Bot框架网络聊天抛出502 Bad Gateway

时间:2018-07-05 14:52:08

标签: botframework direct-line-botframework

我正试图通过Microsoft提供的Web聊天html模板将其他频道数据传递到C#后端,但我没有运气。

关于这一点,我读了很多博客文章,但是我不知道这些人是如何工作的,因为每篇文章我总是得到502 Bad Gateway。

我的bot应用程序HTML初始化如下:

    // removed my token for brevity

    var connection = new BotChat.DirectLine({
        token: "{secret}",
        webSocket: true
    });

    function getBotConnectionDetail(botconnection) {
        var botConnectionDetail = {};
        var keys = Object.keys(botconnection);
        for (var i = 0; i < keys.length; i++) {
            botConnectionDetail[keys[i]] = botconnection[keys[i]];
        };
        botConnectionDetail['postActivity'] = function (activity) {
            activity.channelData = {
                Username: 'John Doe'
            };
            return botconnection.postActivity(activity);
        };
        return botConnectionDetail;
    }

    BotChat.App({
        botConnection: getBotConnectionDetail(connection),
        user: { id: "Yo" },
        bot: { id: "Yo" },
        resize: "window"
    },
    document.getElementById("bot"));

此示例大致基于以下我尝试过的以下博客和github票证。

这是DirectlineJS组件上引入的新错误,还是从未奏效。任何帮助将不胜感激。

Sending channelData to webchat with each message

https://github.com/Microsoft/BotBuilder/issues/15

https://github.com/Microsoft/BotBuilder/issues/201

https://github.com/Microsoft/BotFramework-WebChat/issues/142

更新

HTML:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>Bot Chat</title>
    <title>Siza</title>
    <link href="webview/webview.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />
    <style>
        html, body {
            height: 100%;
            margin: 0;
            overflow: hidden;
            padding: 0;
        }
    </style>
</head>
<body>
<div id="bot"></div>
<script src="webview/botchat.js"></script>
<script>
    var connection = new BotChat.DirectLine({
        secret: "{secret}",
        webSocket: true
    });

    function getBotConnectionDetail(botconnection) {
        var botConnectionDetail = {};
        var keys = Object.keys(botconnection);
        for (var i = 0; i < keys.length; i++) {
            botConnectionDetail[keys[i]] = botconnection[keys[i]];
        };
        botConnectionDetail['postActivity'] = function (activity) {
            activity.channelData = {
                Username: 'John Doe'
            };
            return botconnection.postActivity(activity);
        };
        return botConnectionDetail;
    }

    BotChat.App({
        botConnection: getBotConnectionDetail(connection),
            user: { id: "Yo" },
            bot: { id: "Yo" },
            resize: "window"
        },
        document.getElementById("bot"));
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

我想我明白了。尝试进行测试时遇到了相同的问题,然后当我在导航器开发人员工具中进入网络视图时。

投掷502的请求包含以下内容,这有助于我理解:

Unauthorized

实际上,这是在某处未经授权的问题...因此,通过快速谷歌搜索,我发现了这篇文章:Unauthorized Bot Service from Web Chat

就在那里:我没有在Azure的App Service中设置MicrosoftAppIdMicrosoftAppPassword。我编辑了它们(请参阅其他答案),没关系。