我使用Bot和nodejs来实现一个分散流。
我想要的是,如果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();
}发布于 2021-10-11 16:34:55
您可以使用步骤字典来存储值。GitHub上的复杂对话框示例很好地演示了这一点。https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/javascript_nodejs/43.complex-dialog/dialogs/topLevelDialog.js
发布于 2022-08-21 22:30:17
您可以使用您想要的任何名称在上下文中保存数据:
step.values['nameProperty'] = {}这将在瀑布对话框的整个执行上下文中访问:
const data = step.values['nameProperty'] // {}https://stackoverflow.com/questions/69525810
复制相似问题