node.js - 机器人框架 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);
}
但它没有显示任何错误。
任何帮助,将不胜感激。
解决方案
发现 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
条件。
更改continueDialog
为resumeDialog
您的 activeDialog id,瀑布将在下一步工作。
推荐阅读
- stream - 如何理解 Modelica 模型中的 Instream 算子?
- api - 如何对偏离标准且需要在 URL 中使用特定版本号的 API 进行版本控制?
- angular - FormGroup 验证模型绑定相互覆盖 angular 8
- android - 如何从 HEX 中获得正确的葡萄糖测量值
- powershell - Powershell如何从json转换为哈希表
- selenium - 测试用例的分组在 testng.xml 中没有按预期工作
- php - Etsy API - 更新库存
- javascript - 单独设置字符串的每个字母的样式
- azure-devops - Azure-DevOps:Azure Pipeline 中的自动递增 docker 标签
- recaptcha - Recaptcha v3 徽章未显示(framework7)