Search code examples
microsoft-teamsbotframework

Microsoft Bot Framework REST API - Cannot retrieve activity ID after sending message containing attachments to conversation


Using Microsoft Bot Framework REST API, for a Teams conversation with a bot, we send an Activity to the user. Note that the expect return value is a ResourceResponse object, containing the id of the created Activity.

POST https://smba.trafficmanager.net/emea/v3/conversations/<conversation_id>/activities
Headers: Bearer <token>
Body:

{
    "type": "message",
    "text": "hello",
    "textFormat": "xml"
}

The response has status 201 and contains the Activity identifier as expected:

{
    "id": "1610124975523"
}

Great! Now let's send a message that contains a button.

{
    "type": "message",
    "text": "hello",
    "textFormat": "xml",
    "attachments": [
        {
        "contentType": "application/vnd.microsoft.card.adaptive",
        "content": {
            "type": "AdaptiveCard",
            "version": "1.0",
            "body": [],
            "actions": [{
                "type": "Action.Submit",
                "title": "SUBMIT",
                "data": {
                    "payload": "derp"
                }
                }]
      }}
    ]
}

This time we receive an empty response 202 and there is no attached Activity ID.

Note that both Activities are received successfully by the end user.

How can we receive the Activity ID when sending an activity containing attachments such as buttons? Why does this not match the REST API's specifications?


Solution

  • I created an Issue on the Github of the Bot framework SDK here

    Apparently, an activity that includes both a text and card attachments is sent as two separate activities (the text, then the attached card), which is why an empty 202 response is received. This is apparently "by design".

    The (not-so-great) solution is thus to create both activities separately and store both activity IDs.