Microsoft-Teams上的Botframework:关于向用户发送回复消息的问题

时间:2017-05-18 10:18:43

标签: rest botframework microsoft-teams

我在Botframework中开发了一个机器人并添加了Microsoft Teams频道。

当用户写下' hi'在MS-Teams中,我的webhook收到以下消息:

{
  "text": "hi",
  "textFormat": "plain",
  "type": "message",
  "timestamp": "2017-05-18T10:05:07.742Z",
  "id": "1495101906391",
  "channelId": "msteams",
  "serviceUrl": "https://smba.trafficmanager.net/emea-client-ss.msg/",
  "from": {
    "id": "29:1hyY0WDlv1ehVaSqIA-anqB9CMHoukm59yNjxcVxjTnb5s2B1_HtUI6GFmS1vC6w2XufYPX7L03xlY1qEEQtT2w",
    "name": "xxx"
  },
  "conversation": {
    "id": "a:1ivnXQ6qsiT1hLo26tk4vL1vgUcanbkRm3mMsDj48HkQSKFwr87HCKUFvFoSqjMdGICUBYzds5MR1_kIBCJRY0GZyZ9fa3Yd3MXmlHUhLVA7XaXezOO5u7CaLTNghSiEM"
  },
  "recipient": {
    "id": "28:4faa7ac7-bb35-4737-b49a-e21bbc3fb65d",
    "name": "xxx"
  },
  "entities": [
    {
      "locale": "it-IT",
      "country": "IT",
      "platform": "Mac",
      "type": "clientInfo"
    }
  ],
  "channelData": {
    "tenant": {
      "id": "5cf8dc9b-6f57-4eff-a404-5518dc1826d6"
    }
  }
}

为了回复用户问题,我使用以下端点: https://smba.trafficmanager.net/emea-client-ss.msg/v3/conversations/29:1hyY0WDlv1ehVaSqIA-anqB9CMHoukm59yNjxcVxjTnb5s2B1_HtUI6GFmS1vC6w2XufYPX7L03xlY1qEEQtT2w/activities/

身体:

{
  "action": "message",
  "channelData": {
    "tenant": {
      "id": "5cf8dc9b-6f57-4eff-a404-5518dc1826d6"
    }
  },
  "channelId": "msteams",
  "conversation": {
    "id": "a:1ivnXQ6qsiT1hLo26tk4vL1vgUcanbkRm3mMsDj48HkQSKFwr87HCKUFvFoSqjMdGICUBYzds5MR1_kIBCJRY0GZyZ9fa3Yd3MXmlHUhLVA7XaXezOO5u7CaLTNghSiEM"
  },
  "entities": [
    {
      "locale": "it-IT",
      "country": "IT",
      "platform": "Mac",
      "type": "clientInfo"
    }
  ],
  "from": {
    "id": "28:4faa7ac7-bb35-4737-b49a-e21bbc3fb65d",
    "name": "XXX"
  },
  "id": "14950405460679",
  "replyToId": "1495040546067",
  "inputHint": "ignoringInput",
  "locale": "it-IT",
  "localTimestamp": "2017-05-17T17:02:25.716Z",
  "recipient": {
    "id": "29:1hyY0WDlv1ehVaSqIA-anqB9CMHoukm59yNjxcVxjTnb5s2B1_HtUI6GFmS1vC6w2XufYPX7L03xlY1qEEQtT2w",
    "name": "XXX"
  },
  "serviceUrl": "https://smba.trafficmanager.net/emea-client-ss.msg/",
  "text": "hi Antonio",
  "textFormat": "markdown",
  "type": "message",
  "timestamp": "2017-05-19T17:02:25.716Z"
}

我收到以下正文的400错误

 {   
     "error": {
     "code": "ServiceError",
     "message": "Unsupported conversation type"   
     } 
 }

回复讯息有什么问题?端点和身体是否正确?

提前致谢

2 个答案:

答案 0 :(得分:1)

serviceUrl端点并不意味着直接发布。 Bot Framework SDK(以及底层的REST API)为您做到了这一点。您应该发布的唯一端点是在Bot Framework门户中为您的机器人指定的“消息传递端点” - 通常采用https://<your-bot-endpoint>/api/messages形式。

在没有看到更多代码的情况下,我无法更具体,而且我从未尝试直接发布到serviceUrl以查看会发生什么,但您所观察到的与我所发现的并不矛盾期望的。

以下是一个示例消息一个机器人:

{
    "text": "hello",
    "textFormat": "plain",
    "type": "message",
    "timestamp": "2017-05-19T19:34:57.1Z",
    "id": "1495222496101",
    "channelId": "msteams",
    "serviceUrl": "https://smba.trafficmanager.net/amer-client-ss.msg/",
    "from": {
        "id": "29:1b-XXgcDBMdLhH_MyEbE8u4C6re5IXsyM4diL4_6RBnOG-TCUm-YPsBGMq_cltQkc_paI8g5gsIVT6AgWFZigs5E49-i0F0OxpODhGY-IX08",
        "name": "Bill Bliss"
    },
    "conversation": {
        "id": "a:1X7RpEdoNRlujstg0zjaq_ouNBRrfN_brwVTHRzIdSEhAwS0XPa8uMlGl1Vrw4tOqIVLwN6WzWK1WyooWrPyVpsEcciyOJRI1snA_RMvUkejB39HCAZPtoJLUpgogTm_d"
    },
    "recipient": {
        "id": "28:71d82610-942e-4115-b6a7-2ac1992ecb23",
        "name": "Build Bot  DEV "
    },
    "entities": [
        {
            "locale": "en-US",
            "country": "US",
            "platform": "Windows",
            "type": "clientInfo"
        }
    ],
    "channelData": {
        "tenant": {
            "id": "72f988bf-86f1-41af-91ab-2d7cd011db47"
        }
    }
}

以下是来自机器人的回复

{
    text: 'hello',
    textFormat: 'plain',
    type: 'message',
    timestamp: '2017-05-19T20: 00: 33.764Z',
    entities: [{
        locale: 'en-US',
        country: 'US',
        platform: 'Windows',
        type: 'clientInfo'
    }],
    sourceEvent: {
        tenant: {
            id: '72f988bf-86f1-41af-91ab-2d7cd011db47'
        }
    },
    attachments: [],
    address: {
        id: '1495224034790',
        channelId: 'msteams',
        user: {
            id: '29: 1b-XXgcDBMdLhH_MyEbE8u4C6re5IXsyM4diL4_6RBnOG-TCUm-YPsBGMq_cltQkc_paI8g5gsIVT6AgWFZigs5E49-i0F0OxpODhGY-IX08',
            name: 'BillBliss'
        },
        conversation: {
            id: 'a: 1X7RpEdoNRlujstg0zjaq_ouNBRrfN_brwVTHRzIdSEhAwS0XPa8uMlGl1Vrw4tOqIVLwN6WzWK1WyooWrPyVpsEcciyOJRI1snA_RMvUkejB39HCAZPtoJLUpgogTm_d'
        },
        bot: {
            id: '28: 71d82610-942e-4115-b6a7-2ac1992ecb23',
            name: 'BuildBotDEV'
        },
        serviceUrl: 'https: //smba.trafficmanager.net/amer-client-ss.msg/'
    },
    source: 'msteams',
    agent: 'botbuilder',
    user: {
        id: '29: 1b-XXgcDBMdLhH_MyEbE8u4C6re5IXsyM4diL4_6RBnOG-TCUm-YPsBGMq_cltQkc_paI8g5gsIVT6AgWFZigs5E49-i0F0OxpODhGY-IX08',
        name: 'BillBliss'
    }
}

答案 1 :(得分:0)

您的端点网址应具有会话ID,而不是用户ID。 function printer( callback ) { callback(); } function print() { var name = "testing and all is well"; function callbackHandler() { console.log( name ); } printer( callbackHandler ); } print();是用户ID。 尝试使用会话ID发送相同的有效内容,该ID位于:29:..

所以在你的情况下,URL应该是: "conversation": {"id": ".."}