当我加载网页时,我收到了两条欢迎消息。查看我的机器人的控制台输出,我可以看到两个会话更新正在发生。
这不会发生在Bot框架仿真器中,它只显示一条欢迎消息。
我的代码与示例的唯一不同之处在于渲染:
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token }),
store,
styleOptions,
userID: guid(),
}, document.getElementById('webchat'));为什么会出现这种情况呢?为什么web通道要为用户发送两个“加入”事件?
我处理会话更新的代码如下所示:
} 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)
}
}
}}
发布于 2019-01-31 02:04:10
不建议使用ConversationUpdate事件发送欢迎消息。阅读有关how to properly send a greeting message的更多信息。
每个连接将有两个ConversationUpdate事件。一个用于机器人加入对话,另一个用于(人类)用户加入对话。在您当前的代码中,您正在迭代所有新成员,其中您必须过滤掉机器人本身。
更好的选择是使用使用反向通道发送的自定义事件。在您提到的example中,您已经拥有了此功能。它会向你的机器人发送一个新的事件webchat/join,默认情况下甚至包括浏览器语言。
https://stackoverflow.com/questions/54443597
复制相似问题