Microsoft BotFramework-WebChat收到两条欢迎消息

时间:2019-01-30 15:05:00

标签: botframework

我正在使用基于https://github.com/Microsoft/BotFramework-WebChat/blob/master/samples/15.d.backchannel-send-welcome-event/index.html

的代码

当我加载网页时,我收到两条欢迎消息。查看我的机器人的控制台输出,我可以看到正在发生两个对话更新。

Bot框架仿真器不会发生这种情况,它只会显示一条欢迎消息。

我的代码与示例不同的唯一地方是渲染:

window.WebChat.renderWebChat({
   directLine: window.WebChat.createDirectLine({ token }),
   store,
   styleOptions,
   userID: guid(),
}, document.getElementById('webchat'));

为什么会这样?为什么网络频道会为用户发送两个“加入”事件?

我的代码处理对话更新如下:

} else if (turnContext.activity.type === ActivityTypes.ConversationUpdate) {
if (DEBUG) { console.log("ConversationUpdate"); }

// Do we have any new members added to the conversation?
if (turnContext.activity.membersAdded.length !== 0) {
    // Iterate over all new members added to the conversation
    for (var idx in turnContext.activity.membersAdded) {
        console.log(turnContext.activity.membersAdded);
        // Greet anyone that was not the target (recipient) of this message
        // the 'bot' is the recipient for events from the channel,
        // turnContext.activity.membersAdded == turnContext.activity.recipient.Id indicates the
        // bot was added to the conversation.
        if (turnContext.activity.membersAdded[idx].id != turnContext.activity.recipient.id) {
            if (DEBUG) {console.log("Starting MASTER_DIALOG");}
            const user = await this.userProfile.get(turnContext, {});
            user.id = this.guid();
            await this.userProfile.set(turnContext, user);
            await this.userState.saveChanges(turnContext);
            return await dialogContext.beginDialog(MASTER_DIALOG)
        }
    }
}

}

1 个答案:

答案 0 :(得分:1)

不建议使用mSearchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { MenuItemCompat.collapseActionView(searchMenu); } } }); 事件发送欢迎消息。进一步了解how to properly send a greeting message

每个连接将有两个ConversationUpdate事件。一种用于机器人何时加入对话,另一种用于何时(人类)用户加入对话。在您当前的代码中,您正在遍历所有新成员,在这些成员中,您必须过滤掉漫游器本身。

更好的选择是利用通过反向通道发送的自定义事件。在您提到的example中,您已经具有此功能。它将向您的机器人发送一个新事件ConversationUpdate,默认情况下甚至包括浏览器语言。