Antonino Gentile
Antonino Gentile

Reputation: 11

Botframework on Microsoft-Teams: Issue about sending reply message to user

I have developed a bot within Botframework and add the channel Microsoft Teams.

When user writes 'hi' in MS-Teams to the chatbot, my webhook receives the following message:

{
  "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"
    }
  }
}

In order to reply to user question, i'm using the following endpoint: https://smba.trafficmanager.net/emea-client-ss.msg/v3/conversations/29:1hyY0WDlv1ehVaSqIA-anqB9CMHoukm59yNjxcVxjTnb5s2B1_HtUI6GFmS1vC6w2XufYPX7L03xlY1qEEQtT2w/activities/

with body:

{
  "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"
}

I receive a 400 error with the following body

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

What is wrong about reply message? Are the endpoint and body correct?

Thanks in advance

Upvotes: 1

Views: 907

Answers (2)

bio512
bio512

Reputation: 23

Your endpoint URL should have the conversation ID, not the user ID. The 29:.. is the user ID. Try sending the same payload with the conversation ID, which is located under: "conversation": {"id": ".."}

So in your case the URL should be: https://smba.trafficmanager.net/emea-client-ss.msg/v3/conversations/a:1ivnXQ6qsiT1hLo26tk4vL1vgUcanbkRm3mMsDj48HkQSKFwr87HCKUFvFoSqjMdGICUBYzds5MR1_kIBCJRY0GZyZ9fa3Yd3MXmlHUhLVA7XaXezOO5u7CaLTNghSiEM/activities/

Upvotes: 0

Bill Bliss - MSFT
Bill Bliss - MSFT

Reputation: 3591

The serviceUrl endpoint is not meant to be POSTed to directly. The Bot Framework SDKs (and the underlying REST APIs) do that for you. The only endpoint you should be posting to is the "Messaging endpoint" specified for your bot in the Bot Framework portal - usually in the form https://<your-bot-endpoint>/api/messages.

Without seeing more of your code I can't be more specific, and I've never tried posting to the serviceUrl directly to see what happens, but what you observed isn't inconsistent with what I'd expect.

Here's a sample message to a bot:

{
    "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"
        }
    }
}

Here's the reply from the bot:

{
    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'
    }
}

Upvotes: 1

Related Questions