我有开始对话的网络聊天代码。它在Chrome中运行良好,但在IE11中不起作用。在机器人方面,我想用bot.on('conversationUpdate')从客户端读取一些初始数据。我应该将要传递给机器人的userID放在哪里以及如何放置?
当前客户端代码:
<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的情况下,机器人无法读取user.id,而上述代码在Chrome中运行良好。
发布于 2019-05-17 18:36:59
在网络聊天中,将值传递给后台的最好方式是使用backchannel功能。
在Webchat的Github页面上有很多很好的演示:https://github.com/Microsoft/BotFramework-WebChat/tree/master/samples/15.d.backchannel-send-welcome-event
简而言之,您应该抛出一个包含所有所需数据的自定义事件,并且不要使用conversationUpdate事件。
然后在你的机器人端捕捉这个事件,你就在这里了!
https://stackoverflow.com/questions/56182817
复制相似问题