如何解决 BotChat.App Uncaught ReferenceError?
How to solve BotChat.App Uncaught ReferenceError?
我正在尝试使用我在 Embedding a bot on a website 中找到的一些代码。
我知道有一些更新,我的问题是 BotChat.App 是否可以使用。
因为我使用 BotChat.App 并给了我这个错误 Uncaught ReferenceError: BotChat is not defined.
我尝试将其更改为 window.WebChat.renderWebChat 并且它有效但在这一行中给了我错误 document.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>
未捕获的引用错误:BotChat 未定义html:31
正如错误提示的那样,这是由于尽管您使用了 BotChat.App,但您没有得到对 BotChat
.
的引用
尝试在页眉部分导入 <script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
。
我正在尝试使用我在 Embedding a bot on a website 中找到的一些代码。 我知道有一些更新,我的问题是 BotChat.App 是否可以使用。 因为我使用 BotChat.App 并给了我这个错误 Uncaught ReferenceError: BotChat is not defined.
我尝试将其更改为 window.WebChat.renderWebChat 并且它有效但在这一行中给了我错误 document.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>
未捕获的引用错误:BotChat 未定义html:31
正如错误提示的那样,这是由于尽管您使用了 BotChat.App,但您没有得到对 BotChat
.
尝试在页眉部分导入 <script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
。