当前位置: 首页 > 知识库问答 >
问题:

Microsoft BotFramework WebChat收到两条欢迎消息

艾阳羽
2023-03-14

我使用的代码基于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'));

为什么会这样?为什么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)
        }
    }
}

}

共有1个答案

濮阳和泰
2023-03-14

不建议使用ConversationUpdate事件发送欢迎信息。阅读更多有关如何正确发送问候语的信息。

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

更好的选择是使用使用反向通道发送的自定义事件。在您提到的示例中,您已经具有此功能。它会向你的机器人发送一个新的事件webchat/加入,默认情况下甚至包括浏览器语言。

 类似资料:
  • Jinja2 是一个现代的,设计者友好的,仿照 Django 模板的 Python 模板语言。 它速度快,被广泛使用,并且提供了可选的沙箱模板执行环境保证安全: <title>{% block title %}{% endblock %}</title> <ul> {% for user in users %} <li><a href="{{ user.url }}">{{ user.user

  • Jinja2 是一个现代的,设计者友好的,仿照 Django 模板的 Python 模板语言。 它速度快,被广泛使用,并且提供了可选的沙箱模板执行环境保证安全: <title>{% block title %}{% endblock %}</title> <ul> {% for user in users %} <li><a href="{{ user.url }}">{{ user.user

  • 该站点的目标是成为 Jekyll 的全面指南。包括一些内容如:搭建和运行你的站点、创建以及管理内容、定制站点的展现和外观、在不同的环境中发布、以及参与到 Jekyll 将来的开发的一些建议。 Jekyll 究竟是什么? Jekyll 是一个简单的博客形态的静态站点生产机器。它有一个模版目录,其中包含原始文本格式的文档,通过一个转换器(如 Markdown)和我们的 Liquid 渲染器转化成一个完

  • 欢迎来到 Libra 开发者站点! Libra 的使命是建立一套简单的全球货币和金融基础设施,为数十亿人服务。 The world truly needs a reliable digital currency and infrastructure that together can deliver on the promise of “the internet of money.” Securi

  • 我正在开发一个基于微软bot框架的多渠道bot(专注于web和电报)(https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0) 我被用户收到的最初消息所困扰。我的机器人基于Microsoft发布的复杂机器人:https://github.com/Microsoft/BotFramework-Sam

  • Ceph 独一无二地在一个统一的系统中同时提供了对象、块、和文件存储功能。div.body h3{margin:5px 0px 0px 0px;} CEPH 对象存储 REST 风格的接口 与 S3 和 Swift 兼容的 API S3 风格的子域 统一的 S3/Swift 命名空间 用户管理 利用率跟踪 条带化对象 云解决方案集成 多站点部署 灾难恢复 Ceph 块设备 瘦接口支持 映像尺寸最大