首页 > 解决方案 > 机器人框架 continueDialog 没有弹出堆栈

问题描述

我通过 Bot Framework 创建聊天机器人并在node.js上使用 LINE API Developers

我工作的问题是continueDialog下一步没有继续瀑布对话框。
使用 continueDialog 完成后堆栈没有改变

continueDialog

stack1 [ { id: 'xxxDialog', state: { options: {}, values: [Object], stepIndex: 0 } } ]

continueDialog

stack2 [ { id: 'xxxDialog', state: { options: {}, values: [Object], stepIndex: 0 } } ]



在 index.js 上

server.post('/api/line',jsonParser, async (req, res)=> {
  const conversationReference = { 
          type: "message", 
          text: "Hello world" ,
          channelData: { clientActivityID: "id-xxxx" },
          channelId: 'api/line/id-xxxx',
          recipient:
            { id: lineID`,
              name: 'line',
              role: 'botLine' },
              serviceUrl: 'https://localhost:3978' ,
          from:
            { id: lineId`,
              name: 'User',
              role: 'user' },
          conversation: { id: lineId },
       };
  const context = await adapter.createContext(conversationReference);

  await bot.onTurn(context);
});



在 bot.js 上

class Bot extends ActivityHandler {
     /**
     *
     * @param {ConversationState} conversationState
     * @param {UserState} userState
     * @param {Dialog} dialog
     */
    constructor(conversationState, userState) {    
        super();
        this.conversationState = conversationState;
        this.userState = userState;

        this.dialogStateAccessor = conversationState.createProperty('dialogStateAccessor');
        this.dialogAccessor= conversationState.createProperty('testAccessor');

        this.dialog = new DialogSet(this.dialogStateAccessor);

        this.dialog.add(new WaterfallDialog('testDialog', [
            this.step1.bind(this), 
            this.step2.bind(this)


    ]));
}

 async step1(stepContext){
    linesent("step 1") ;
    return {status : DialogTurnStatus.waiting} ;
}
async step2(stepContext){
    linesent("step 2") ;
        return await stepContext.endDialog(); 
}

 async onTurn(turnContext) {
 const reservation = await this.dialogAccessor.get(turnContext, null);   
        // Generate a dialog context for our dialog set.
        const dc = await this.dialog.createContext(turnContext);
  if (!dc.activeDialog){
      // If there is no active dialog, check whether we have a reservation yet.
      if (!reservation) {
          // If not, start the dialog.
          await dc.beginDialog(`testDialog`);
      }
}
 else {
  //Continue the dialog.
  const dialogTurnResult = await dc.continueDialog();
 }
return await this.conversationState.saveChanges(turnContext, false);
}

但它没有显示任何错误。
任何帮助,将不胜感激。

标签: node.jsbotframework

解决方案


发现 continueDialog 方法是

 async continueDialog(dc) {
        // Don't do anything for non-message activities
        if (dc.context.activity.type !== botbuilder_core_1.ActivityTypes.Message) {
            return dialog_1.Dialog.EndOfTurn;
        }
        // Run next step with the message text as the result.
        return await this.resumeDialog(dc, dialog_1.DialogReason.continueCalled, dc.context.activity.text);
    }

机器人总是做if条件。
更改continueDialogresumeDialog您的 activeDialog id,瀑布将在下一步工作。


推荐阅读