botframework - MS Bot,Direct line API,无法发送事件,如何解决?

标签 botframework direct-line-botframework

我一直在尝试在应用程序中设置 MS Bot。到目前为止,我做了以下。

  • 为 Bot 设置一个 REST 端点,该连接器会监听它。
     app.post("/botapi/messages", connector);
    
  • 获取APP_ID和APP_PASSWORD,模拟器成功连接如下,
     http://localhost:4000/botapi/messages
     APP_ID
     APP_PASSWORD
    

    这是成功的,机器人按预期回复。
  • 尝试使用 Direct Line API 与 Bot 对话。已成功开始对话。回应之一如下。
     {
       "conversationId": "3JYZyAn5VYB3HNcO3tcgtn",
       token: ....
        .....
      }
    

    正如文档所说,我使用“node-fetch”包来发出 POST 请求。

  • 但是,我无法使用 Direct Line API 发送事件,已收到
        internal server error 500
    

    文档说 POST 请求应该如下所示。
        POST 
        https://directline.botframework.com/v3/directline/conversations
        Authorization: Bearer my_secret
    

    这非常适合开始对话,但不适用于发送事件。

    我发送的事件是:
          {
           "type": "message",
           "from": {
                  "id": "user1"
                   },
                "text": "hello Bot, say something"
           }
    

    我不认为“id”很重要,所以这就是我发布的内容
              https://directline.botframework.com/v3/directline/conversations/{conversationId}/activities
    

    我使用了从开始对话时收到的对话 ID。
    我用谷歌搜索,但没有找到我的问题的答案。
    此外,我的问题很少,也许他们的回答会对我有所帮助。

    Q1:使用 Direct Line API 的每个人的 url "https://directline.botframework.com/v3/directline/ "都一样吗?当我用机器人的端点“http://localhost:3000/botapi/messages/conversations”替换它时,我什至无法开始对话,没有任何效果。

    Q2:Direct Line API 是如何工作的?我向 API 发出了带有我的 secret 的 POST,然后 API 如何找到我的机器人? Bot 和 API 如何通信?我在这里错过了什么吗?

    Q3:当我发出 POST 以发送事件时,我遵循了文档。
    在授权中,我尝试了我的 secret 和从开始对话中获得的 token ,两者都不起作用。我相信两者都应该有效。我错了吗?

    Q4:我需要对Bot Connector Service做些什么吗? ?我读了这篇文章,但我不知道它是为了什么。我错了吗?

    那么,我在这里缺少什么?如何发送事件?

    备注 :我的机器人没有部署到 azuri 或 aws,它只在我的 Mac 上。
    但是,如文档所述,我获得了 DirectLine 的 APP_ID、APP_PASSWORD 和 SECRET。

    最佳答案

    documentation指定这是通过 Direct Line 向机器人发送事件(消息)的端点:

    https://directline.botframework.com/v3/directline/conversations/{conversationId}/activities
    

    在此 URI 中,{conversationId}是您在 started the conversation 时在响应正文中收到的对话 ID(conversationId 值) .并且请求的正文应指定有关您发送的事件的信息,例如:
    {
        "type": "message",
        "from": {
            "id": "user1"
        },
        "text": "hello"
    }
    

    最后,回答你的问题:
  • Q1:基本 URI is the same适用于所有 Direct Line API 请求。
  • Q2:您在 Authorization 中指定的 Direct Line secret 或 token 请求的 header 用于标识应将请求定向到
  • 的机器人
  • Q3:是的,您应该能够指定 secret 或 token您在 中收到的值开始对话 Authorization 中的响应 的标题发送事件 要求。但是请注意,您在 中收到的 token 开始对话 response 只能用于与该特定对话进行交互。
  • Q4:您链接到的文章与使用 Direct Line API 没有直接关系。 (但正如@EzequielJadib 在他的评论中提到的,您确实需要为您的机器人启用 Direct Line channel 。)
  • 关于botframework - MS Bot,Direct line API,无法发送事件,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46684849/

    相关文章:

    botframework - webhook 的引用文档

    node.js - 在 Azure Bot Framework (Nodejs) 中使用 session.send 向对话发送 Webhook 响应

    node.js - Directline语音 Node js连接

    node.js - 向机器人执行 POST 时出现 502(错误网关)

    node.js - 直线 API : Define a new ChannelId

    node.js - Microsoft bot builder V4 Nodejs 获取用户电子邮件

    c# - 如何在 C# 中使用 LUIS None Intent 而无需 LUIS 的火车话语

    c# - Conversation.SendToConversation 抛出错误未知 botId

    botframework - 在 Teams 中使用 azure 机器人服务 : how to send files to bot

    azure - 无法将机器人连接到 Skype For Business Online