我想在chatbot初始化时显示消息并调用对话框。以下代码显示了该消息。但是,无法调用对话框。
bot.on('conversationUpdate', function (activity) {
// when user joins conversation, send welcome message
if (activity.membersAdded) {
activity.membersAdded.forEach(function (identity) {
if (identity.id === activity.address.bot.id) {
var reply = new builder.Message()
.address(activity.address)
.text("Hi, Welcome ");
bot.send(reply);
// bot.beginDialog("initialize", '/');
// session.beginDialog("initialize");
}
});
}});bot.dialog('/', intents);
下面是对话框的代码。当chatbot开始时,我需要在下面的对话框中调用
bot.dialog('initialize', [
function (session, args, next) {
builder.Prompts.choice(session, "Do you have account?", "Yes|No", { listStyle: builder.ListStyle.button });
}, function (session, args, next) {
if (args.response.entity.toLowerCase() === 'yes') {
//session.beginDialog("lousyspeed");
session.send("No pressed");
} else if (args.response.entity.toLowerCase() === 'no') {
session.send("Yes pressed");
session.endConversation();
}
}]).endConversationAction("stop",
"",
{
matches: /^cancel$|^goodbye$|^exit|^stop|^close/i
// confirmPrompt: "This will cancel your order. Are you sure?"
});
我试过以下方法。但它没有用
1. bot.beginDialog("initialize", '/');
2. session.beginDialog("initialize");
您正在遇到此错误,因为尽管它们具有相同的方法名称,但session.beginDialog()
和<UniversalBot>bot.beginDialog()
之间的方法签名不同。
这可能有点令人困惑,因为session.beginDialog()
的第一个参数是dialogId
,但是当使用bot.beginDialog()
时,第一个参数是address
,第二个参数是dialogId
。
要解决此问题,请使用SDK参考文档中描述的正确输入参数调用bot.beginDialog()
- 例如。 bot.beginDialog(activity.address, dialogId);
你还可以在这里看到botbuilder.d TypeScript definition file中的完整方法签名:
/**
* Proactively starts a new dialog with the user. Any current conversation between the bot and user will be replaced with a new dialog stack.
* @param address Address of the user to start a new conversation with. This should be saved during a previous conversation with the user. Any existing conversation or dialog will be immediately terminated.
* @param dialogId ID of the dialog to begin.
* @param dialogArgs (Optional) arguments to pass to dialog.
* @param done (Optional) function to invoke once the operation is completed.
*/
beginDialog(address: IAddress, dialogId: string, dialogArgs?: any, done?: (err: Error) => void): void;
我通过使用单行代码修复了我的问题
bot.beginDialog(activity.address, 'initialize');