【问题标题】:botframework webchat token post call returns 403botframework 网络聊天令牌发布调用返回 403
【发布时间】:2020-04-30 23:22:17
【问题描述】:

我使用这个example 将机器人集成到网络聊天中。

<!DOCTYPE html>
<html lang="en-US">
  <head>
    <title>Web Chat: Send welcome event</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script crossorigin="anonymous" src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
    <style>
      html,
      body {
        height: 100%;
      }

      body {
        margin: 0;
      }

      #webchat {
        height: 100%;
        width: 100%;
      }
    </style>
  </head>
  <body>
    <div id="webchat"></div>
    <script>
      (async function() {
        const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', 
        { method: 'POST',
        headers: { Authorization: 'my webchat secret' }
        });
        const { token } = await res.json();
        const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
          if (action.type === 'DIRECT_LINE/CONNECT_FULFILLED') {
            dispatch({
              type: 'WEB_CHAT/SEND_EVENT',
              payload: {
                name: 'webchat/join',
                value: { language: window.navigator.language }
              }
            });
          }

          return next(action);
        });

        window.WebChat.renderWebChat(
          {
            directLine: window.WebChat.createDirectLine({ token }),
            store
          },
          document.getElementById('webchat')
        );

        document.querySelector('#webchat > *').focus();
      })().catch(err => console.error(err));
    </script>
  </body>
</html>

请在控制台中查找错误信息

但是,当我尝试使用与我的机器人密码相同的 api url 作为邮递员中的授权时,我得到 200 OK 响应,其中包含“conversationId”、“token”和“expires_in”值。

我在通话后遗漏了什么?

【问题讨论】:

    标签: javascript botframework


    【解决方案1】:

    我认为您可能缺少 Authorization 标头中的 Bearer 部分。

    所以,它应该是这样的:

    headers: { Authorization: 'Bearer my webchat secret' }
    

    【讨论】:

    • 谢谢!这行得通。你知道哪个是生成语音服务令牌的 url,因为我也在尝试这个例子link
    • 您是否尝试过使用订阅密钥生成授权令牌,如here 所述?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    相关资源
    最近更新 更多