Microsoft BotFramework WebChat收到两条欢迎消息
我使用的代码基于 当我加载网页时,我收到两条欢迎信息。查看我的机器人的控制台输出,我可以看到两个对话更新正在发生 Bot框架模拟器不会出现这种情况,它只显示一条欢迎消息 我的代码与示例的唯一不同之处在于呈现:Microsoft BotFramework WebChat收到两条欢迎消息,botframework,Botframework,我使用的代码基于 当我加载网页时,我收到两条欢迎信息。查看我的机器人的控制台输出,我可以看到两个对话更新正在发生 Bot框架模拟器不会出现这种情况,它只显示一条欢迎消息 我的代码与示例的唯一不同之处在于呈现: window.WebChat.renderWebChat({ directLine: window.WebChat.createDirectLine({ token }), store, styleOptions, userID: guid(), }, docume
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)
}
}
}
}不建议使用
会话更新
事件发送欢迎信息。阅读更多关于
每个连接将有两个ConversationUpdate
事件。一个用于机器人加入对话时,另一个用于(人类)用户加入对话时。在当前代码中,您正在迭代所有新成员,必须过滤掉bot本身
更好的选择是使用使用反向通道发送的自定义事件。在您提到的示例中,您已经具备了此功能。它将向您的bot发送一个新的事件
webchat/join
,默认情况下,它甚至包括浏览器语言。我正在查看哪些使用ConversationUpdate,它们的模式看起来与您发布的博客非常不同。谢谢你的建议,我想我可以在这方面取得一些进展。谢谢,只有用户有“实体”密钥。。。所以检查“如果(typeof turnContext.activity.entities!='undefined'){”足以确定加入的用户是人类。这更符合Microsoft Great find示例中给出的方法,Andy!使用ConversationUpdate或自定义事件都是可能的,但是使用ConversationUpdate不可能发送自定义参数,如浏览器语言或登录用户的名称以供检查而ConversationUpdate有更多的限制,比如无法在第一条消息中使用提示。