【问题标题】:Change the Css of the QnA Bot embedded as webchat更改嵌入为网络聊天的 QnA Bot 的 Css
【发布时间】:2018-11-03 17:25:13
【问题描述】:

您好,我使用网络聊天嵌入了一个 QnA 机器人。我需要更改聊天窗口标题的 CSS。

我将机器人作为网络聊天嵌入到 ASP.net MVC 应用程序中。

我正在使用 iframe 方法将机器人嵌入到 webchhat 窗口中。使用 iframe 方法如何更改 css。

还有从“聊天”到“点击提问”的默认文本

我下载了 botchat.css 和 botchat.js。我在 _Layout.cshtml 中包含了 css 和 js 文件。我在 botchat.css 中将元素“.wc-header”的背景颜色更改为红色。但仍然没有反映变化。

我想知道为什么 botchat.css 显示 botchat.css 取自 https://webchat.botframework.com/css/webchat-stable/botchat.css

有人可以帮助我如何制作网络聊天窗口以获取我已修改并包含在 _Layout.cshtml 中的 botchat.css。

提前谢谢你

【问题讨论】:

标签: css botframework


【解决方案1】:

您好,这是我为了更改 QnABot 的 Css 和聊天标题所做的。

首先我将 iframe 放在 _Layout.cshtml 文件中。 iframe 的 src 是一个名为 MyFAQChat.html 的 HTML 文件

要生成 MyFAQChat.html 的内容,您可以执行以下操作。

像这样在 _Layout.cshtml 中只放置 iframe

<div id='botDiv' style='height: 30px; position: fixed; bottom: 0;right: 0; z-index: 1000; background-color: #fff'><div id='botTitleBar' style='height: 30px; width: 300px; position:fixed; cursor: pointer;'></div><iframe width='300px' height='300px' src='https://webchat.botframework.com/embed/YOURBOTHANDLE?s= secretforWebchat'></iframe>

然后使用 F12 可以看到 iframe 的内容。它看起来像这样

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>MyBot</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <style>
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
    </style>
        <link href="../../Content/botchat.css"   rel="stylesheet" />

        <link href="/css/webchat-stable/botchat-fullwindow.css" rel="stylesheet" />
</head>
<body>
    <div id="BotChatElement"></div>
        <script src="Scripts/jquery-1.12.3.js"></script>
        <script src="Scripts/Custom/botchat.js"></script>

    <script>
        var model = {

  "userId": "someuserid",
  "userName": "You",
  "botId": "botIDhere",

  "botName": "botNamehere",
  "secret": "webchatsecretidhere",

  "directLineUrl": "https://webchat.botframework.com/v3/directline",
  "webSocketEnabled": "false"

};
    </script>
    <script>
        BotChat.App({
            directLine: {
                secret: model.secret,
                token: model.token,
                domain: model.directLineUrl,
                webSocket: false
            },
            user: { id: model.userId, name: model.userName },
            bot: { id: model.botId, name: model.botName },
            resize: 'window',
            locale: 'en'
        }, document.getElementById("BotChatElement"));


    </script>
   <script>
   $(document).ready(function () {
       var id = document.getElementsByClassName("wc-header");         
            id[0].innerHTML="Click for Help";
        });
   </script>
</body>
</html>

您可以复制 iframe 的内容并将其保存为 HTML 文件。然后在_Layout.cshtml中放置的iframe中引用这个html文件。

html 文件包含更改聊天窗口标题的代码。我正在将其更改为单击以获取有关 document.ready 功能的帮助。

要更改机器人窗口的 CSS..我首先从 cdn 下载了 botchat.css 和 botchat.js,然后更改了 css 并将链接添加到 MyFAQChat.html 中的 css。

这是我使用的方法,没有使用 webchat repo。

我在document.ready函数的layout.cshtml中添加了iframe

$(document).ready(function () {
var div = document.createElement("div");
            document.getElementsByTagName('body')[0].appendChild(div);
            div.outerHTML = "<div id='botDiv' style='height: 38px; position: fixed; bottom: 0; z-index: 1000; background-color: #fff'><div id='botTitleBar' style='height: 38px; width: 400px; position:fixed; cursor: pointer;'></div><iframe width='400px' height='600px' src='https://webchat.botframework.com/embed/DSWebBotForFAQs?s=0SRsueCeamk.cwA.JIM.ShMx5BDubHOaIOY3fxrdB_do7iBd1os'></iframe></div>";

            document.querySelector('body').addEventListener('click', function (e) {
                e.target.matches = e.target.matches || e.target.msMatchesSelector;
                if (e.target.matches('#botTitleBar')) {
                    var botDiv = document.querySelector('#botDiv');
                    botDiv.style.height = botDiv.style.height == '600px' ? '38px' : '600px';
                };
            });

        });

【讨论】:

  • 你在哪里将你的 MYFAQHTML 添加为 iframe 标签中的源文件? 我正在关注你的实现。我已经使用 iframe 代码创建了 HTML 文件,并将 css 和 JS 链接替换为我的项目中的一个。我现在需要在 iframe 中引用该文件。
  • 您好,我在 _layout.cshtml 中添加了 iframe。这就像 webforms 应用程序中的母版页。
  • 在 的末尾添加为 div 元素(将 botDiv 添加为 的最后一个元素)
  • 只是为了确认iframe的来源应该是我的带有iframe代码的html页面?
  • @Hkhan:将第一步解释生成的iframe的内容复制到MYFAQHTML中,引用html文件如下
【解决方案2】:

首先,您的问题可能与其他 SO 线程重复。正如 Nicolas R 和 Ashwin Kumar 在 cmets 中分享的那样,您可以克隆 WebChat repo 并根据您的要求修改源代码以自定义 WebChat。

如果您不熟悉WebChat repo,您​​可以尝试以下方法来实现您的要求:将默认文本从“Chat”修改为“Click to Ask a Question”并更改“.wc-header”的背景颜色变成红色。

1).在Strings.ts中,将title: "Chat"更改为title: "Click to Ask a Question"

const localizedStrings: LocalizedStrings = {
    'en-us': {
        title: "Chat",

2).在botchat.scss更改background-color: $c_brandbackground-color:red;

.wc-header {
    background-color: $c_brand;

测试结果:

其次,如果可能,您可以通过botchat.js 在您的网站中添加网络聊天(不要使用提供的&lt;iframe&gt; 代码)。要更改“.wc-header”的背景颜色,可以使用以下CSS代码sn-p覆盖默认样式。

.wc-header{
    background-color:red !important;
}

注意:我们会将您的帖子投票为重复,如果您在自定义 WebChat 时有新问题,请随时回复。

编辑:

为什么 botchat.css 显示 botchat.css 取自 https://webchat.botframework.com/css/webchat-stable/botchat.css

您使用提供的代码,该代码指向 Microsoft 托管的 Web Chat 实例,botchat.css 也由 Microsoft 托管。

【讨论】:

  • 嗨@bharathy,我分享了满足您要求的解决方案,您尝试了吗?
  • 谢谢。我不熟悉网络聊天回购。我正在尝试在 iframe 中使用 webchat 嵌入机器人。我确实更改了从 cdn 网站复制的 botchat.css,并在我的应用程序的 Layout.cshtml 中引用了 css。但对 botchat.css 所做的更改并未反映出来。相反,botchat.css 取自 webchat.botframework.com/css/webchat-stable/botchat.css
  • 如何更改 String.ts 并将修改后的 String.ts 包含在我的应用程序中。现在我可以更改机器人窗口的 CSS。我没有使用网络聊天仓库,我使用了 iframe 方法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多