0

我有开始对话的网络聊天代码。它在 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 中运行良好。

4

1 回答 1

0

在 Webchat 中向后端传递值的最佳方式是使用backchannel功能。

Webchat 的 Github 页面上有很棒的演示:https ://github.com/Microsoft/BotFramework-WebChat/tree/master/samples/15.d.backchannel-send-welcome-event

简而言之,您应该使用您需要的所有数据抛出一个自定义事件,并且不要使用该conversationUpdate事件。

然后在你的机器人端捕捉这个事件,你就在这里!

于 2019-05-17T10:36:59.203 回答