botframework - 无法从 IE 11 中的网络聊天将参数传递给机器人
问题描述
我有开始对话的网络聊天代码。它在 Chrome 中运行良好,但在 IE 11 中不起作用。在机器人端,我想在 bot.on('conversationUpdate') 中从客户端读取一些初始数据。我应该在哪里以及如何将我的用户 ID 传递给机器人?
当前客户的代码:
<script>
window.fetch("https://xxxurladdress", { method: "POST" })
.then(function (res) { return res.json(); })
.then(function (json) {
const secret = json.secret;
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine(
{secret:secret }),
userID: "1588b0f6-50c3-416e-8970-1d86bad6c68b
}, document.getElementById("webchat"));
document.querySelector("#webchat > *").focus();
});
</script>
bot.on('conversationUpdate') 中的机器人代码:
bot.on('conversationUpdate', async function (message) {
if ((message.membersAdded && message.membersAdded.length > 0
&& message.address.user.role !== undefined)) {
let conversationId = message.address.conversation.id;
let userId = message.address.user.id;
在 IE 11 的情况下,bot 无法读取 user.id,而上述代码在 Chrome 中运行良好。
解决方案
在 Webchat 中向后端传递值的最佳方式是使用backchannel
功能。
Webchat 的 Github 页面上有很棒的演示:https ://github.com/Microsoft/BotFramework-WebChat/tree/master/samples/15.d.backchannel-send-welcome-event
简而言之,您应该使用您需要的所有数据抛出一个自定义事件,并且不要使用该conversationUpdate
事件。
然后在你的机器人端捕捉这个事件,你就在这里!
推荐阅读
- ios - 如何将 wowza 视频从一台 iPad 广播到多台 iPad 设备 - swift
- django - PythonAnywhere 无法在没有 www 的情况下使站点重定向
- r - R - plotly - 无法按值对图进行排序
- c# - PostSharp explorer 当前解决方案中没有任何方面
- android - 有没有办法在安装期间限制应用程序?
- python - 用beautifulsoup在python中用colspan解析表
- python - 使用熊猫在具有重复日期的csv文件中添加缺少的日期
- ios - 如何在 iOS 中从呼叫方的呼叫中获取视频窗口?
- nativescript - NativeScript-Angular:nsRouterLink 在 Android 上打开组件,但在 iOS 上不打开
- mongodb - MongoCollection.find() 搜索两次?