如何将机器人的回复附加到网络聊天中?

时间:2018-06-04 10:22:03

标签: botframework chatbot direct-line-botframework web-chat

我无法从机器人那里获得响应,并将其附加到MS Botframework提供的网络聊天中。

这是我到目前为止所做的事情:

  1. https://dev.botframework.com/(没有迁移)

  2. 上创建了一个机器人
  3. 集成网络聊天和直线

  4. 创建烧录监听器服务器并使用 ngrok 生成HTTPS

  5. 将服务器的地址创建为机器人的消息传递端点

  6. enter image description here

    1. 使用以下代码生成HTML页面(在没有任何服务器的情况下在本地运行)
    2. <html>
        <head>
          <link href="https://cdn.botframework.com/botframework-webchat/latest/botchat.css" rel="stylesheet" />
        </head>
        <body>
          <div id="bot"/>
          <script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
          <script>
            BotChat.App({
              directLine: { secret: 'direct_line_secret_key' },
              user: { id: 'userid' },
              bot: { id: 'botid' },
              resize: 'detect'
            }, document.getElementById("bot"));
          </script>
        </body>
      </html>
      

      现在我能够以用户身份从UI发送消息,并能够在烧录侦听器服务器中捕获它 但是如何从服务器回复以便消息来自bot并附加到用户界面?

      我错过了什么吗?

      我已经尝试https://directline.botframework.com/v3/directline/conversations/ {convoId} / activities来发布请求,但这又一次只回到服务器而不会附加到网络聊天中。

      data = json.dumps({"type": "message","from":{"id":"botid"},"text": "Hii!"})

      requests.post('https://directline.botframework.com/v3/directline/conversations/' + r['conversation']['id'] + '/activities', 
      headers={"Authorization": "Bearer " + "secret_key", "Content-Type": "application/json", "Content-Length": "512"},data=data
      

      注意:我只在网络聊天用户界面中使用botframework,而不是其他任何内容。

      编辑1:

        

      从网络聊天ui

      发送了这个      

      http://bcebb07a.ngrok.io/webhook' [POST] GT;   ************************************************** ************************ {&#39;输入&#39;:&#39; message&#39;,&#39; id&#39 ;:&#39; 5DvIa5ImiPF4G6WnGlPYyY | 0000002&#39;,   &#39; timestamp&#39;:&#39; 2018-06-05T06:51:45.3174659Z&#39;,&#39; serviceUrl&#39;:   &#39; https://directline.botframework.com/&#39;,&#39; channelId&#39;:&#39; directline&#39;,   &#39;来自&#39;:{&#39; id&#39;:&#39; sid&#39;},&#39;对话&#39;:{&#39; id&#39;:   &#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;},&#39;收件人&#39;:{&#39; id&#39;:   &#39; one_assist @ CrbpWod1mw8&#39;,&#39;名称&#39;:&#39; OneAssist&#39;},&#39; textFormat&#39;:&#39; plain&#39;,   &#39;区域设置&#39;:&#39; en-US&#39;,&#39;文字&#39;:&#39;你好,你好&#39; ,&# 39; channelData&#39 ;:   {&#39; clientActivityId&#39;:&#39; 1528180308547.7414264322396316.5&#39;}}   5DvIa5ImiPF4G6WnGlPYyY

           ################################################## ################## {&#39;消息&#39;:[{&#39; id&#39;:      

      &#39; 5DvIa5ImiPF4G6WnGlPYyY | 0000000&#39;,&#39; conversationId&#39;:   &#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;,&#39;&#39;:&#39; 2018-06-05T06:32:50.9651813Z&#39;,   &#39;来自&#39; sid&#39;,&#39; text&#39;:&#39; hello&#39;,&#39; channelData&#39;:{&#39; clientActivityId&#39 ;:   &#39; 1528180308547.7414264322396316.0&#39;},&#39;图片&#39;:[],&#39;附件&#39;:[]},   {&#39; id&#39;:&#39; 5DvIa5ImiPF4G6WnGlPYyY | 0000001&#39;,&#39; conversationId&#39;:   &#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;,&#39;&#39;:&#39; 2018-06-05T06:47:14.1602925Z&#39;,   &#39;来自&#39; sid&#39;,&#39; text&#39;:&#39;你是怎样的&#39;,&#39; channelData&#39;:   {&#39; clientActivityId&#39;:&#39; 1528180308547.7414264322396316.3&#39;},&#39; images&#39;:   [],&#39;附件&#39;:[]},{&#39; id&#39;:&#39; 5DvIa5ImiPF4G6WnGlPYyY | 0000002&#39;,   &#39; conversationId&#39;:&#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;,&#39;创建&#39;:   &#39; 2018-06-05T06:51:45.3174659Z&#39;,&#39;来自&#39;&#39; sid&#39;,&#39; text&#39;:&#39;你好如何   你&#39;,&#39; channelData&#39;:{&#39; clientActivityId&#39;:   &#39; 1528180308547.7414264322396316.5&#39;},&#39;图片&#39;:[],&#39;附件&#39;:   []}],&#39;水印&#39;:&#39; 2&#39;}

           

      {&#34;错误&#34;:{       &#34;代码&#34;:&#34; BotError&#34;,       &#34;消息&#34;:&#34;发送活动失败:机器人超时&#34; },&#34; httpStatusCode&#34;:504}   127.0.0.1 - - [05 / Jun / 2018 12:22:12]&#34; POST / webhook HTTP / 1.1&#34; 200 -   ************************************************** ************************ http://bcebb07a.ngrok.io/webhook' [POST] GT;   ************************************************** ************************ {&#39; type&#39;:&#39; conversationUpdate&#39;,&#39; id&#39 ;:&#39; D3XJ6CAaVsc&#39;,&#39;时间戳&#39;:   &#39; 2018-06-05T06:51:56.7508828Z&#39;,&#39; serviceUrl&#39;:   &#39; https://directline.botframework.com/&#39;,&#39; channelId&#39;:&#39; directline&#39;,   &#39;来自&#39;:{&#39; id&#39;:&#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;},&#39;对话&#39;:{&#39; id&#39;:   &#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;},&#39;收件人&#39;:{&#39; id&#39;:   &#39; one_assist @ CrbpWod1mw8&#39;,&#39;名称&#39;:&#39; OneAssist&#39;},&#39; membersAdded&#39;:   [{&#39; id&#39;:&#39; botid&#39;}]} 5DvIa5ImiPF4G6WnGlPYyY

           ################################################## ################## {&#39;消息&#39;:[{&#39; id&#39;:      

      &#39; 5DvIa5ImiPF4G6WnGlPYyY | 0000000&#39;,&#39; conversationId&#39;:   &#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;,&#39;&#39;:&#39; 2018-06-05T06:32:50.9651813Z&#39;,   &#39;来自&#39; sid&#39;,&#39; text&#39;:&#39; hello&#39;,&#39; channelData&#39;:{&#39; clientActivityId&#39 ;:   &#39; 1528180308547.7414264322396316.0&#39;},&#39;图片&#39;:[],&#39;附件&#39;:[]},   {&#39; id&#39;:&#39; 5DvIa5ImiPF4G6WnGlPYyY | 0000001&#39;,&#39; conversationId&#39;:   &#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;,&#39;&#39;:&#39; 2018-06-05T06:47:14.1602925Z&#39;,   &#39;来自&#39; sid&#39;,&#39; text&#39;:&#39;你是怎样的&#39;,&#39; channelData&#39;:   {&#39; clientActivityId&#39;:&#39; 1528180308547.7414264322396316.3&#39;},&#39; images&#39;:   [],&#39;附件&#39;:[]},{&#39; id&#39;:&#39; 5DvIa5ImiPF4G6WnGlPYyY | 0000002&#39;,   &#39; conversationId&#39;:&#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;,&#39;创建&#39;:   &#39; 2018-06-05T06:51:45.3174659Z&#39;,&#39;来自&#39;&#39; sid&#39;,&#39; text&#39;:&#39;你好如何   你&#39;,&#39; channelData&#39;:{&#39; clientActivityId&#39;:   &#39; 1528180308547.7414264322396316.5&#39;},&#39;图片&#39;:[],&#39;附件&#39;:   []}],&#39;水印&#39;:&#39; 2&#39;}

           

      {&#34;错误&#34;:{       &#34;代码&#34;:&#34; BotError&#34;,       &#34;消息&#34;:&#34;发送活动失败:机器人超时&#34; },&#34; httpStatusCode&#34;:504}   127.0.0.1 - - [05 / Jun / 2018 12:22:32]&#34; POST / webhook HTTP / 1.1&#34; 200 -

           

      #从服务器代码发送此内容   ************************************************** ************************ http://bcebb07a.ngrok.io/webhook' [POST] GT;   ************************************************** ************************ {&#39;输入&#39;:&#39; message&#39;,&#39; id&#39 ;:&#39; 5DvIa5ImiPF4G6WnGlPYyY | 0000003&#39;,   &#39; timestamp&#39;:&#39; 2018-06-05T06:52:16.6925987Z&#39;,&#39; serviceUrl&#39;:   &#39; https://directline.botframework.com/&#39;,&#39; channelId&#39;:&#39; directline&#39;,   &#39;来自&#39;:{&#39; id&#39;:&#39; botid&#39;},&#39;对话&#39;:{&#39; id&#39;:   &#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;},&#39;收件人&#39;:{&#39; id&#39;:   &#39; one_assist @ CrbpWod1mw8&#39;,&#39;姓名&#39;:&#39; OneAssist&#39;},&#39;文字&#39;:&#39; Hii!&# 39; }   5DvIa5ImiPF4G6WnGlPYyY

           ################################################## ################## {&#39;消息&#39;:[{&#39; id&#39;:      

      &#39; 5DvIa5ImiPF4G6WnGlPYyY | 0000000&#39;,&#39; conversationId&#39;:   &#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;,&#39;&#39;:&#39; 2018-06-05T06:32:50.9651813Z&#39;,   &#39;来自&#39; sid&#39;,&#39; text&#39;:&#39; hello&#39;,&#39; channelData&#39;:{&#39; clientActivityId&#39 ;:   &#39; 1528180308547.7414264322396316.0&#39;},&#39;图片&#39;:[],&#39;附件&#39;:[]},   {&#39; id&#39;:&#39; 5DvIa5ImiPF4G6WnGlPYyY | 0000001&#39;,&#39; conversationId&#39;:   &#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;,&#39;&#39;:&#39; 2018-06-05T06:47:14.1602925Z&#39;,   &#39;来自&#39; sid&#39;,&#39; text&#39;:&#39;你是怎样的&#39;,&#39; channelData&#39;:   {&#39; clientActivityId&#39;:&#39; 1528180308547.7414264322396316.3&#39;},&#39; images&#39;:   [],&#39;附件&#39;:[]},{&#39; id&#39;:&#39; 5DvIa5ImiPF4G6WnGlPYyY | 0000002&#39;,   &#39; conversationId&#39;:&#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;,&#39;创建&#39;:   &#39; 2018-06-05T06:51:45.3174659Z&#39;,&#39;来自&#39;&#39; sid&#39;,&#39; text&#39;:&#39;你好如何   你&#39;,&#39; channelData&#39;:{&#39; clientActivityId&#39;:   &#39; 1528180308547.7414264322396316.5&#39;},&#39;图片&#39;:[],&#39;附件&#39;:[]},   {&#39; id&#39;:&#39; 5DvIa5ImiPF4G6WnGlPYyY | 0000003&#39;,&#39; conversationId&#39;:   &#39; 5DvIa5ImiPF4G6WnGlPYyY&#39;,&#39;&#39;:&#39; 2018-06-05T06:52:16.6925987Z&#39;,   &#39;来自&#39; botid&#39;,&#39; text&#39;:&#39; Hii!&#39;,&#39; images&#39;:[], &#39;附件&#39;:[]}],   &#39;水印&#39;:&#39; 3&#39;}   https://directline.botframework.com/v3/directline/conversations/5DvIa5ImiPF4G6WnGlPYyY/activities/

           

      https://directline.botframework.com/v3/conversations/5DvIa5ImiPF4G6WnGlPYyY/activities    {&#34;错误&#34;:{       &#34;代码&#34;:&#34; BotError&#34;,       &#34;消息&#34;:&#34;发送活动失败:机器人超时&#34; },&#34; httpStatusCode&#34;:504}

1 个答案:

答案 0 :(得分:0)

我在使用ngrok时遇到了类似的问题,我在日志中注意到有对127.0.0.1的引用。尝试将-host-header参数添加到ngrok命令行。

例如我使用

ngrok http -host-header=localhost:55486 55486

其中55486是我的终端所在的端口号。