【发布时间】:2019-06-29 22:37:16
【问题描述】:
我正在尝试弄清楚如何使用 BotFramework v4 和 Node.js 让 Facebook Messenger 显示来自 QnA Maker 的后续提示。
在听从了 Matt Stannett 在这个帖子中的好建议之后,我做到了这一点: How to implement cards in a QnA question which has follow up prompts and uses them in the cards
但是,要让它们出现在 Facebook Messenger 中,我真的很吃力。
我希望它像在我的 onMessage 代码中为 Facebook 快速回复定义一些 channelData 一样简单,因为我只需要 Facebook 传回一个简单的文本有效负载。我想我可以用类似的方式来做,我得到了 Webchat 的提示,代码如下:
this.onMessage(async (context, next) => {
this.logger.log('Processing a Message Activity');
const qnaResults = await this.qnaMaker.getAnswers(context);
// Show choices if the Facebook Payload from ChannelData is not handled
if (!await this.processFacebookPayload(context, context.activity.channelData)) {
if (context.activity.channelId == 'facebook') {
if (qnaResults[0]) {
const { answer, context: { prompts }} = qnaResults[0];
let reply;
if (prompts.length) {
const quickReply = {
channelData: {
"messaging_type":"RESPONSE",
"message":{
"text":"test1", //answer,
"quick_replies":[
{
"content_type":"text",
"title":"test2",//prompts.map({ displayText }),
"payload":"test3",//prompts.map({ displayText })
}
]
}
}
}
reply = quickReply;
} else {
reply = answer;
}
await context.sendActivity(reply);
// If no answers were returned from QnA Maker, reply with help.
} else {
await context.sendActivity('I\'m sorry, I don\'t have an answer for that. Please ask me something else, such as: \n\n "What Is Mental Health?" \n\n "What Is NeuroDiversity" \n\n "Help"');
}
} else {
// If an answer was received from QnA Maker, send the answer back to the user.
if (qnaResults[0]) {
const { answer, context: { prompts }} = qnaResults[0];
let reply;
if (prompts.length) {
const card = {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": answer,
wrap: true
}
],
"actions": prompts.map(({ displayText }) => ({ type: "Action.Submit", title: displayText, data: displayText })),
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.1"
}
reply = { attachments: [CardFactory.adaptiveCard(card)] };
} else {
reply = answer;
}
await context.sendActivity(reply);
// If no answers were returned from QnA Maker, reply with help.
} else {
await context.sendActivity('I\'m sorry, I don\'t have an answer for that. Please ask me something else, such as: \n\n "What Is Mental Health?" \n\n "What Is NeuroDiversity" \n\n "Help"');
}
}
}
// By calling next() you ensure that the next BotHandler is run.
await next();
});
但这不起作用。我得到的是 QnA 对我提出的在 QnA Maker 中没有设置后续提示的任何问题的回复,因此我知道 IF 语句正确地将 Facebook 标识为渠道,并且答案具有后续提示与之相关联。我想我只是没有找到适合 Facebook 快速回复的代码。
谁能帮忙?
提前致谢!
【问题讨论】:
标签: node.js botframework facebook-messenger qnamaker