Как решить BotChat.App Uncaught ReferenceError? - PullRequest
0 голосов
/ 15 мая 2019

Я пытаюсь использовать какой-то код, который я нахожу в Встраивание бота на сайт .Я знаю, что это были некоторые обновления, мой вопрос, если BotChat.App доступен для использования.Поскольку я использую BotChat.App и дал мне эту ошибку Uncaught ReferenceError: BotChat не определен.

Я пытаюсь изменить его на window.WebChat.renderWebChat, и он работает, но дал мне ошибку в этом документе строки.getElementsByClassName ("wc-header") [0] .setAttribute ("id", "chatbotheader");


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
   <link href="https://cdn.botframework.com/botframework-webchat/latest/botchat.css" rel="stylesheet" />
  <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
    <style>
        #mychat {
            margin: 10px;
            position: fixed;
            bottom: 30px;
            right: 10px;
            z-index: 1000000;
        }
    </style>
</head>
<body>
    <div id="container">
        <h1>Hello World</h1>
        <!--other page contents-->
        <img id="mychat" src="https://i.stack.imgur.com/RD7i4.png" style="float:right" />
    </div>
</body>
</html>
<script>
    (function () {
        var div = document.createElement("div");
        document.getElementsByTagName('body')[0].appendChild(div);
        div.outerHTML = "<div id='botDiv' style='width: 400px; height: 0px; margin:10px; position: fixed; bottom: 0; right:0; z-index: 1000;><div  id='botTitleBar' style='height: 40px; width: 400px; position:fixed; cursor: pointer;'></div></div>";
        BotChat.App({
            directLine: { secret: 'myAppSecret' },
        }, document.getElementById("botDiv"));

        document.getElementsByClassName("wc-header")[0].setAttribute("id", "chatbotheader");
        document.querySelector('body').addEventListener('click', function (e) {
            e.target.matches = e.target.matches || e.target.msMatchesSelector;
            if (e.target.matches('#chatbotheader')) {
                var botDiv = document.querySelector('#botDiv');

                botDiv.style.height = "0px";

                document.getElementById("mychat").style.display = "block";
            };
        });

        document.getElementById("mychat").addEventListener("click", function (e) {

            document.getElementById("botDiv").style.height = '500px';

            e.target.style.display = "none";
        })
    }());
</script>

Uncaught ReferenceError: BotChat не определен html: 31

1 Ответ

1 голос
/ 15 мая 2019

Как свидетельствует ошибка, это связано с тем, что, хотя вы используете BotChat.App, у вас нет ссылки на BotChat.

Попробуйте импортировать <script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script> в разделе заголовка.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...