microsoft / BotFramework-DirectLineJS



我正在尝试与健康机器人建立DirectLine连接,并选择了预设场景之一。我计划用HealthBot设置几个场景,并希望能够根据需要触发它们。

我能找到的触发场景的唯一例子是我不使用的WebChat,你可以在这里找到它:

https://github.com/microsoft/HealthBotContainerSample/blob/master/public/index.js。

我也找到了https://www.linkedin.com/pulse/microsoft-healthcare-bot-covid-19-triage-scenario-up-ravichander/建议:

dl.postActivity({
type: "invoke",
value: {
trigger: "covid19"
},
locale: 'en-US',
from: user,
name: "TriggerScenario"
})

我试过这样做:

this.directLine.postActivity(
{   
type: "event",
locale: "en-us",
textFormat: "plain",
from: { id: "server", name: "server", role: "user" },
name: "TriggerScenario",
value: {
trigger: "MyScenario",
args: {
myVar1: "{custom_arg_1}",
myVar2: "{custom_arg_2}"
}
}
}).subscribe(console.log,console.error);

在DirectLineJS的文档中没有提到它可以这样使用,但是它会触发正确的场景并正确地将参数传递给bot。

我遇到的问题似乎与HealthBot本身更相关,因为它不识别任何用户输入并返回Default reply for utterances that are not understood中定义的通用消息。有没有人有这种级别的定制经验,并可以建议如何使用postActivity通过DirectLineJS按需触发场景。

我触发场景的方式有什么问题吗?

我似乎已经解开了这个谜。场景被我的代码正确触发。问题在于健康机器人不能正确识别用户输入。我已经解决了这个问题,在场景本身添加了一些警卫。

示例代码https://github.com/microsoft/HealthBotContainerSample/blob/master/public/index.js,如果您正在使用WebChat V4,则具有正确的示例。只需取消triggeredScenario的注释对象并替换触发器属性。

store.dispatch({
type: 'DIRECT_LINE/POST_ACTIVITY',
meta: {method: 'keyboard'},
payload: {
activity: {
type: "invoke",
name: "InitConversation",
locale: user.locale,
value: {
// must use for authenticated conversation.
jsonWebToken: jsonWebToken,
// Use the following activity to proactively invoke a bot scenario
/*
triggeredScenario: {
trigger: "{scenario_id}",
args: {
myVar1: "{custom_arg_1}",
myVar2: "{custom_arg_2}"
}
}
*/
}
}
}
});

最新更新