Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Botframework 将查询字符串传递到Microsoft bot web频道_Botframework - Fatal编程技术网

Botframework 将查询字符串传递到Microsoft bot web频道

Botframework 将查询字符串传递到Microsoft bot web频道,botframework,Botframework,我们已经使用ms bot框架创建了一个bot,并希望向bot传递一些用户不会输入的数据。就像我在想,我们是否可以将查询字符串传递到下面的web频道 从bot-api代码中,我可以以某种方式读取这个querystring参数……理想情况下,我知道我们不能控制上面的webchat链接,我们只允许访问bot-api。但这是可能的,还是通过其他方式将用户未输入的数据传递给bot 我们计划在iframe中显示指向不同站点的web频道url,并希望通过当前浏览的url来识别用户从何处开始对话 谢谢 Sid

我们已经使用ms bot框架创建了一个bot,并希望向bot传递一些用户不会输入的数据。就像我在想,我们是否可以将查询字符串传递到下面的web频道

从bot-api代码中,我可以以某种方式读取这个querystring参数……理想情况下,我知道我们不能控制上面的webchat链接,我们只允许访问bot-api。但这是可能的,还是通过其他方式将用户未输入的数据传递给bot

我们计划在iframe中显示指向不同站点的web频道url,并希望通过当前浏览的url来识别用户从何处开始对话

谢谢
Siddharth

这可以通过使用库轻松完成。只需执行几个步骤即可完成设置

首先,包含一个div,其中包含一个id,供bot的webchat实例锚定。在本例中,id为“webchat”


希望有帮助

谢谢Steven…理解了,解释得很好…我可以让它工作的:)
<!DOCTYPE html>

<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>Bot Chat</title>
    <style>
      #webchat,
      #webchat>* {
        border: 1px solid #333;
        float: left;
        min-height: 600px;
        height: 600px;
        position: relative;
        width: 460px;
      }
    </style>
  </head>

  <body>
    <div class="example">
      <h2>Back Channel Bot</h2>
      <div id="webchat"></div>
    <script src='https://code.jquery.com/jquery-3.3.1.min.js'></script>
    <script src='https://cdn.botframework.com/botframework-webchat/master/webchat.js'></script>
    <script src='https://unpkg.com/simple-update-in/dist/simple-update-in.production.min.js'></script>
    <script>
      (async function () {
        // To talk to your bot, you should use the token exchanged using your Direct Line secret.
        // You should never put the Direct Line secret in the browser or client app.
        const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
          method: 'POST',
          headers: {
            'Authorization': 'Bearer ' + secret
          },
          json: true
        });
        const { token } = await res.json();

let location = window.location.href;

        let store = window.WebChat.createStore(
          {},
          ({ dispatch }) => next => action => {
            if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
              // simple-update-in is used to update the "action"
              action = window.simpleUpdateIn(action, ['payload', 'activity', 'channelData', 'location'], () => location);
            }
            return next(action);
          }
        );

        window.WebChat.renderWebChat({
          directLine: window.WebChat.createDirectLine({ token }),
          store,
          styleOptions: {
            botAvatarInitials: 'BF',
            userAvatarInitials: 'WC'
          }
        }, document.getElementById('webchat'));

        document.querySelector('#webchat > *').focus();
      })().catch(err => console.error(err));;
    </script>
  </body>
</html>
channelData: { clientActivityID: '15469824216440.emdrovn0f5h', location: 'http://localhost:3000/' }