我想显示消息并在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);

以下是对话框的代码。当聊天机器人启动时,我需要在对话框下方调用
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);
https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.universalbot.html#begindialog

您还可以在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;

10-06 11:54