【发布时间】:2021-11-30 04:20:39
【问题描述】:
我正在使用带有 nodejs 的 Bot Framework SDK 来实现分流。
我希望如果 Luis 预测的两个意图彼此接近,请询问用户他们想要的是哪一个。我已经完成了验证程序,但是流程有问题。
这是一个包含 3 个步骤的瀑布对话框:
- FirstStep:调用 Orchestrator 和 Luis 以获取意图和实体。它使用
return await step.next({...})传递数据 - 消歧步骤:检查是否需要消歧,在这种情况下,提示选项。如果没有,它会像第一步一样传递数据。
- 回答步骤:如果在
step.result收到的数据中有消歧标志,则根据用户响应提示回答。在其他地方,它使用来自第一步的step.result中的数据。
问题是,当它提示用户说出意图时,我丢失了FirstStep的数据,因为我无法使用step.next({...})
¿如何同时维护第一步的数据和提示中的用户回答?
下面是基本代码:
async firstStep(step) {
logger.info(`FinalAnswer Dialog: firstStep`);
let model_dispatch = await this.bot.get_intent_dispatch(step.context);
let result = await this.bot.dispatchToTopIntentAsync(step.context, model_dispatch.model)
// model_dispatch = orchestrator_model
// result = {topIntent: String, entities: Array, disamibiguation: Array}
return await step.next({ model_dispatch: model_dispatch, result: result})
}
async disambiguationStep(step) {
logger.info(`FinalAnswer Dialog: disambiguationStep`);
if (step.result.result.disambiguation) {
logger.info("We need to disambiguate")
let disambiguation_options = step.result.result.disambiguation
const message_text = "What do you need";
const data = [
{
"title": "TEXT",
"value": disambiguation_option[0]
},
{
"title": "TEXT",
"value": disambiguation_option[1]
},
]
let buttons = data.map(function (d) {
return {
type: ActionTypes.PostBack,
title: d.title,
value: d.value
}
});
const msg = MessageFactory.suggestedActions(buttons, message_text);
return await step.prompt(TEXT_PROMPT, { prompt: msg });
return step.next(step.result) //not working
}
else {
logger.info("We dont desambiguate")
return step.next(step.result)
}
}
async answerStep(step) {
logger.info(`FinalAnswer Dialog: answerStep`);
let model_dispatch = step.result.model_dispatch
let result = step.result.result
//Show answer
return await step.endDialog();
}
【问题讨论】:
标签: node.js botframework bot-framework-composer