微软/BotFramework-DirectLineJS

问题描述

我正在尝试与 Health bot 建立 DirectLine 连接,并选择了预设场景之一。我计划使用 HealthBot 设置多个场景,并希望能够按需触发它们。

我能找到的触发场景的唯一示例是我没有使用的网络聊天,您可以在这里找到它:

https://www.linkedin.com/pulse/microsoft-healthcare-bot-covid-19-triage-scenario-up-ravichander/

我还发现了 {{3}} 建议这样做:

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);

我试过这样做:

Default reply for utterances that are not understood 

在 DirectLineJS 的文档中没有提到它可以像那样使用,但是它触发了正确的场景并将参数正确地传递给机器人。

我遇到的问题似乎与 HealthBot 本身更相关,因为它无法识别任何用户输入并返回 postActivity 中定义的通用消息。 有没有人对这种级别的定制有任何经验,并且可以建议如何使用 {{1}} 通过 DirectLineJS 按需触发场景。

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

解决方法

示例代码 https://github.com/microsoft/HealthBotContainerSample/blob/master/public/index.js 具有正确的示例,如果您使用的是 WebChat V4。只需取消对 triggeredScenario 对象的注释并将 trigger 属性替换为您的场景 ID。

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}"
                    }
                }
                */
            }
        }
    }
});
,

我似乎解开了这个谜团。这些场景是用我的代码正确触发的。问题归结为 Health Bot 无法正确识别用户输入。我已经通过在场景本身中添加一些守卫来解决它。