botframework - 部署自定义网络聊天机器人框架

标签 botframework bots web-chat

我克隆了这个仓库 https://github.com/Microsoft/BotFramework-WebChat我设法在本地编辑CSS。 我想知道我需要部署什么才能使用在线网络聊天?

谢谢你的帮助

最佳答案

I clone this repo https://github.com/Microsoft/BotFramework-WebChat and I managed to edit css in local. I would like to know what I need to deploy to use webchat online?

在你之后customize&build your own web chat ,要在您的网站中嵌入网络聊天,您应该在项目中包含构建的 botchat.cssbotchat.js 文件,并引用 botchat.cssbotchat.js 在您的网页中。

I want to add a widget like this to open my chatbot, what I need to do?

您似乎希望在网页中显示聊天图标,以允许用户动态打开/折叠您的网络聊天,要实现此要求,您不需要修改 botchat.js 文件,以下代码示例适合我,您可以引用它。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link href="BotChat/botchat.css" rel="stylesheet" />
    <script src="BotChat/botchat.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="/image/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: '{directline_secret}' },
            user: { id: 'You' },
            bot: { id: '{your_botid}' }
        }, 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>

测试结果:

enter image description here

关于botframework - 部署自定义网络聊天机器人框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51563481/

相关文章:

azure - 是否有使用 Azure CLI 删除 Webchat channel 的命令

javascript - 如何修复空按钮以实现可访问性?

.net - 在一对一聊天中向租户中的用户发送通知

c# - 如何识别我们得到答案的机器人回复

node.js - 无法使用 balebot npm 发送短信

python - 带参数的 Telegram Bot 可点击命令

html - 在Microsoft Bot Framework中,如何从聊天的url中提取参数?

visual-studio-2015 - Microsoft Bot 应用程序模板未出现在 Visual Studio 2015 更新 1/2 中

javascript - 你如何确定他选择了一个?