代码之家  ›  专栏  ›  技术社区  ›  sid8491

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

  •  0
  • sid8491  · 技术社区  · 6 年前

    我无法从bot获取响应并将其附加到MS-Botframework提供的网络聊天中。

    以下是我迄今为止所做的工作:

    1. 已在上创建机器人程序 https://dev.botframework.com/ (没有移民)

    2. 集成网络聊天和直拨电话

    3. 创建了 烧瓶侦听器服务器 并使用生成HTTPS ngrok公司

    4. 将创建的服务器地址作为bot的消息传递终结点

    enter image description here

    1. 使用以下代码生成HTML页面(在本地运行,无需任何服务器)
    <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发送消息,并能够在flask listener服务器中捕获它。
    但是我如何从服务器回复消息,以便消息来自bot并附加到UI?

    我错过什么了吗?

    我试过了 https://directline.botframework.com/v3/directline/conversations/ {convalid}/activities来发布请求,但这只会再次返回到服务器,不会附加到web聊天。

    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:

    从网络聊天界面发送

    http://bcebb07a.ngrok.io/webhook“[发布]> **************************************************************************{'type':'message','id':'5DvIa5ImiPF4G6WnGlPYyY | 000000 2', “时间戳”:“2018-06-05T06:51:45.3174659Z”,“服务URL”: ' https://directline.botframework.com/ “,”channelId“:”directline“, '来自':{'id':'sid'},'对话':{'id': “5DVIA5IMIPF4G6WNGLPYY”“,”收件人“:{'id': '一个_assist@CrbpWod1mw8“,”name“:”OneAssist“},“”textFormat“:”plain“, “locale”:“en US”, “文本”:“你好” ,“channelData”: {'clientActivityId':'1528180308547.7414264322396316.5'} 5DVIA5IMIPF4G6WNGLPYY

    ####################################################################{'messages':[{'id':

    “5DvIa5ImiPF4G6WnGlPYyY | 0000000”,“会话ID”: “5DVIA5IMIPF4G6WNGLPYY”,“已创建”:“2018-06-05T06:32:50.9651813Z”, '发件人':'sid','文本':'你好','通道数据':{'clientActivityId': '1528180308547.7414264322396316.0'},'图像':[],'附件':[]}, {'id':'5DVIA5IMIPF4G6Wnglpyy | 000000 1','conversationId': “5DVIA5IMIPF4G6WNGLPYY”,“创建时间:”“2018-06-05T06:47:14.1602925Z”“, '发件人':'sid','文本':'你好','通道数据': {'clientActivityId':'1528180308547.7414264322396316.3','images': [],'附件':[]},{'id':'5DVIA5IMIPF4G6Wnglpyy | 000000 2', '会话ID':'5DVIA5IMIPF4G6WNGLPYY','已创建': '2018-06-05T06:51:45.3174659Z','发件人':'sid','文本':'你好 you“,”channelData“:{'clientActivityId”: '1528180308547.7414264322396316.5','图像':[],'附件': []}],“水印”:“2”}

    {“错误”:{ “code”:“BotError”, “message”:“未能发送活动:bot超时”},“httpStatusCode”:504} 127.0.0.1--【2018年6月5日12:22:12】“POST/webhook HTTP/1.1”200- ************************************************************************** http://bcebb07a.ngrok.io/webhook“[发布]> **************************************************************************{'type':'conversationUpdate','id':'D3XJ6CAaVsc','timestamp': '2018-06-05T06:51:56.7508828Z','服务URL': ' https://directline.botframework.com/ “,”channelId“:”directline“, '来自':{'id':'5DVIA5IMIPF4G6Wnglpyy','对话':{'id': “5DVIA5IMIPF4G6WNGLPYY”“,”收件人“:{'id': '一个_assist@CrbpWod1mw8“,”name“:”OneAssist“},“membersAdded”: [{'id':'botid}]}5DVIA5IMIPF4G6Wnglpyy

    ####################################################################{'messages':[{'id':

    “5DvIa5ImiPF4G6WnGlPYyY | 0000000”,“会话ID”: “5DVIA5IMIPF4G6WNGLPYY”,“已创建”:“2018-06-05T06:32:50.9651813Z”, '发件人':'sid','文本':'你好','通道数据':{'clientActivityId': '1528180308547.7414264322396316.0'},'图像':[],'附件':[]}, {'id':'5DVIA5IMIPF4G6Wnglpyy | 000000 1','conversationId': “5DVIA5IMIPF4G6WNGLPYY”,“创建时间:”“2018-06-05T06:47:14.1602925Z”“, '发件人':'sid','文本':'你好','通道数据': {'clientActivityId':'1528180308547.7414264322396316.3','images': [],'附件':[]},{'id':'5DVIA5IMIPF4G6Wnglpyy | 000000 2', '会话ID':'5DVIA5IMIPF4G6WNGLPYY','已创建': '2018-06-05T06:51:45.3174659Z','发件人':'sid','文本':'你好 you“,”channelData“:{'clientActivityId”: '1528180308547.7414264322396316.5','图像':[],'附件': []}],“水印”:“2”}

    {“错误”:{ “code”:“BotError”, “message”:“未能发送活动:bot超时”},“httpStatusCode”:504} 127.0.0.1--【2018年6月5日12:22:32】“POST/webhook HTTP/1.1”200-

    #从服务器代码发送此 ************************************************************************** http://bcebb07a.ngrok.io/webhook“[发布]> **************************************************************************{'type':'message','id':'5DvIa5ImiPF4G6WnGlPYyY | 000000 3', “时间戳”:“2018-06-05T06:52:16.6925987Z”,“服务URL”: ' https://directline.botframework.com/ “,”channelId“:”directline“, '来自':{'id':'botid'},'对话':{'id': “5DVIA5IMIPF4G6WNGLPYY”“,”收件人“:{'id': '一个_assist@CrbpWod1mw8“,”name“:”OneAssist“}, “文本”:“Hii!” } 5DVIA5IMIPF4G6WNGLPYY

    ####################################################################{'messages':[{'id':

    “5DvIa5ImiPF4G6WnGlPYyY | 0000000”,“会话ID”: “5DVIA5IMIPF4G6WNGLPYY”,“已创建”:“2018-06-05T06:32:50.9651813Z”, '发件人':'sid','文本':'你好','通道数据':{'clientActivityId': '1528180308547.7414264322396316.0'},'图像':[],'附件':[]}, {'id':'5DVIA5IMIPF4G6Wnglpyy | 000000 1','conversationId': “5DVIA5IMIPF4G6WNGLPYY”,“创建时间:”“2018-06-05T06:47:14.1602925Z”“, '发件人':'sid','文本':'你好','通道数据': {'clientActivityId':'1528180308547.7414264322396316.3','images': [],'附件':[]},{'id':'5DVIA5IMIPF4G6Wnglpyy | 000000 2', '会话ID':'5DVIA5IMIPF4G6WNGLPYY','已创建': '2018-06-05T06:51:45.3174659Z','发件人':'sid','文本':'你好 you“,”channelData“:{'clientActivityId”: '1528180308547.7414264322396316.5'},'图像':[],'附件':[]}, {'id':'5DVIA5IMIPF4G6Wnglpyy | 000000 3','conversationId': “5DvIa5ImiPF4G6WnGlPYyY”,“已创建”:“2018-06-05T06:52:16.6925987Z”, '来自':'botid','文本':'Hii!','图像“:[],”附件“:[]}], “水印”:“3”} https://directline.botframework.com/v3/directline/conversations/5DvIa5ImiPF4G6WnGlPYyY/activities/

    https://directline.botframework.com/v3/conversations/5DvIa5ImiPF4G6WnGlPYyY/activities {“错误”:{ “code”:“BotError”, “message”:“未能发送活动:bot超时”},“httpStatusCode”:504}

    1 回复  |  直到 6 年前
        1
  •  0
  •   Morph    6 年前

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

    例如,我使用

    ngrok http -host-header=localhost:55486 55486
    

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