前言:目前example 的建議方式
let m = new builder.Message(s)
.text(“hello world”)
.suggestedActions(
builder.SuggestedActions.create(
s, ms
));
s.send(s)
不過有一個尷尬點,就是 Message 只有 text ,但 line 的card 有分 標題 跟 說明,試做時,我直接將name拿來用,但ChatConnector 似乎name有字數限制,導致報錯,所以fb的message傳不出去。傻眼。
晚點自幹line builder 2版 時,得先考慮進去。
舊版都是 Card 這個物件為主,
前述問題也只能用Card來做,
合理懷疑 SuggestedActions 是為了簡化產生Card時的流程,但又發現很難做的完美,就變這樣了..
let c = new builder.HeroCard().title(“Title").subtitle(“reaction").text(“Text");
let m = new builder.Message(s)
.text(“hello world”).
addAttachment(c)
這樣就合乎舊版以前的教學了
session.send("Good morning.");
var userMessage = session.message.text;
var customMessage = new builder.Message(session)
.text("Hello!")
.textFormat("plain")
.textLocale("en-us");
session.send(customMessage);
// 就是這裡,如果想要表現出Card的部份。
// Create your bot with a function to receive messages from the user
var bot = new builder.UniversalBot(connector, function (session) {
var msg = session.message;
if (msg.attachments && msg.attachments.length > 0) {
// Echo back attachment
var attachment = msg.attachments[0];
session.send({
text: "You sent:",
attachments: [
{
contentType: attachment.contentType,
contentUrl: attachment.contentUrl,
name: attachment.name
}
]
});
} else {
// Echo back users text
session.send("You said: %s", session.message.text);
}
});