[英]Azure Bot Framework: Bot responds with “undefined” (Node.js)
使用我的機器人的方式是,當用戶鍵入問題時,它將重定向對話框並根據問題返回答案。 目前,我正在嘗試存儲對話歷史記錄。 添加中間件是存儲過程的一部分,我遇到了一個問題,即消息日志中意外出現了“ undefined ”。
我的代碼段
bot.dialog('cards', [
function (session) {
session.send('Test1');
var msg = new builder.Message(session)
.attachmentLayout(builder.AttachmentLayout.carousel)
.textFormat(builder.TextFormat.xml)
.attachments([
new builder.HeroCard(session)
.title('Test1')
.images([
builder.CardImage.create(session, 'imgURL')
])
.buttons([builder.CardAction.dialogAction(session, 'Card1', null, 'Here')
])
]);
msg.addAttachment (
new builder.HeroCard(session)
.title("Test2")
.images([
builder.CardImage.create(session, "imgUrl")
])
.buttons([
builder.CardAction.dialogAction(session, "Card2", null, "Here")
])
);
session.endDialog(msg)
}
]).triggerAction({
matches: 'Greetings'})
//Adding of new card
bot.dialog('Card1', [
function (session) {
var msg1 = new builder.Message(session).sourceEvent({
//specify the channel
facebook: {
text:"Card1"
}
});
session.endDialog(msg1)
session.beginDialog('card1link');
}
]).triggerAction({
matches: 'card1'})
bot.dialog('card1link', [
function (session, args, next) {
builder.Prompts.choice(session, '1. Card2\n2. Card3\n', ['1', '2'], {
retryPrompt: "Please pick your choice.\n1. Card2\n2. Card3\n",
maxRetries: 1
});
},
function (session, args, next) {
if (args.response) {
var choice = args.response.entity;
switch (choice) {
case '1':
session.replaceDialog('Card2');
break;
case '2':
session.replaceDialog('Card3');
break;
}
}
else{
session.send("Sorry");
}
}
]);
輸出量
(用戶到機器人)消息:嗨
(向用戶發送)消息:Test1
(Bot-to-User)訊息:未定義
(用戶到機器人)消息:Card1
(Bot-to-User)訊息:未定義
(針對用戶)消息:請選擇您的選擇。 1.卡2 2.卡3
預期
(用戶到機器人)消息:嗨
(向用戶發送)消息:Test1
(用戶到機器人)消息:Card1
(針對用戶)消息:請選擇您的選擇。 1.卡2 2.卡3
您尚未提供recieve
或send
中間件的代碼段。 假設您使用以下代碼記錄歷史記錄:
bot.use({
receive: (evt, next) => {
//handle evt
//what you save should be `evt.text` as the message
next();
},
send: (evt, next) => {
//handle evt
//what you save should be `evt.text` as the message
next();
}
})
當您的漫游器收到(Bot-to-User) message: undefined
,應觸發endOfConversation
事件。 此事件的結構如下:
{
address:Object {id: "9n1h124ddkb2", channelId: "emulator", user: Object, …}
code:"completedSuccessfully"
textLocale:"en-US"
type:"endOfConversation"
}
其中不包含text
屬性。 這應該是罪犯。
您可以添加條件來避免這種情況:
receive: (evt, next) => {
console.log(evt);
if (evt.type == 'message') {
your logic here
}
next();
}
您可以為此使用同義詞和retryPrompt。
builder.Prompts.choice(
session,
"Selection one option",
[
{
value: "1",
synonyms: ["Card1", "Card 1"]
},
{
value: "2",
synonyms: ["Card2", "Card 2"]
}
],
{
listStyle: builder.ListStyle.button,
retryPrompt: 'Selection one option.'
}
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.