首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过直行将Microsoft嵌入到可折叠窗口中

通过直行将Microsoft嵌入到可折叠窗口中
EN

Stack Overflow用户
提问于 2018-07-02 08:57:17
回答 1查看 1.2K关注 0票数 1

使用WebChat,有一种方法可以将bot嵌入到可折叠窗口中。

代码语言:javascript
复制
var xhr = new XMLHttpRequest();

xhr.open('GET', "https://webchat.botframework.com/api/tokens", true);
xhr.setRequestHeader('Authorization', 'BotConnector ' + 'webchat-secret');
xhr.send();
xhr.onreadystatechange = processRequest;

function processRequest(e) {
  if (xhr.readyState == 4 && xhr.status == 200) {
    var response = JSON.parse(xhr.responseText);
    document.getElementById("chat").src = "https://webchat.botframework.com/embed/nodejsbot98?t=" + response
  }
}
(function() {
  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';
    };
  });
}());

但是,如果我使用直接行(下面)连接bot,并保留事件侦听器函数,我将得到一个可折叠的窗口,但里面没有bot。

代码语言:javascript
复制
var botConnection = new BotChat.DirectLine({
  secret: 'direct-line secret',
});

var user = {
  id: 'userid',
  name: 'username'
};

var bot = {
  id: 'botid',
  name: 'botname'
};

BotChat.App({
  botConnection: botConnection,
  user: user,
  bot: bot,
}, document.getElementById('chat'));

botConnection
  .postActivity({
    type: "event",
    value: "",
    from: {
      id: "me"
    },
    name: "greeting",
    data: {
      firstname: 'Alain',
      gender: 'male'
    }
  })
  .subscribe(id => console.log("success"));

这是html

代码语言:javascript
复制
<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>
    <div id = 'chat' width='400px' height='600px' ></div>
</div>              
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-03 02:30:02

在http请求的响应中,将嵌入url设置为div DOM:

代码语言:javascript
复制
document.getElementById("chat").src = "https://webchat.botframework.com/embed/nodejsbot98?t=" + response

而且DIV没有src属性,您可以简单地修改:

代码语言:javascript
复制
<div id = 'chat' width='400px' height='600px' ></div>

代码语言:javascript
复制
<iframe id='chat' width='400px' height='600px'></iframe>

来解决你的问题。此外,没有必要使用僵尸框架webchat库,正如您在第二个代码片段中提到的那样。

更新

这似乎是一个CSS问题,您可以尝试添加并修改下面的CSS样式

代码语言:javascript
复制
//add
.wc-chatview-panel {
        width: 400px;
        height: 600px;
        position: relative;
    }

将css样式z-index:2添加到botTitleBar div。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51132395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档