Search code examples
node.jsrestbotframeworkmicrosoft-teamsadaptive-cards

Adaptive card in teams not workig - REST API


I created a bot (nodejs server) for teams - through bot framework.

I'm trying to send adaptive card that I created through: adaptive cards designer

and I get error :

{"code":"BadArgument","message":"ContentType of an attachment is not set"}

The request body :

{
  "type": "message",
  "from": {
    "id": "xxxxxx"
  },
  "conversation": {
    "id": "xxxxxx"
  },
  "recipient": {
    "id": "xxxxx"
  },
  "replyToId": "xxxxx",
  "text": "some text",
  "attachments": [
    {
      "type": "AdaptiveCard",
      "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
      "version": "1.2",
      "body": [
        {
          "type": "TextBlock",
          "text": "some text"
        },
        {
          "type": "Input.Date",
          "separator": true
        }
      ]
    }
  ]
}

I would appreciate help


Solution

  • When adding attachments you'll want to set the contentType and content properties of the attachment object.

    https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-api-reference?view=azure-bot-service-4.0#attachment-object

    {
        "type": "message",
        "from": {
            "id": "xxxxxx"
        },
        "conversation": {
            "id": "xxxxxx"
        },
        "recipient": {
            "id": "xxxxx"
        },
        "replyToId": "xxxxx",
        "text": "some text",
        "attachments": [
            {
                "contentType": "application/vnd.microsoft.card.adaptive",
                "content": {
                    "type": "AdaptiveCard",
                    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                    "version": "1.2",
                    "body": [
                        {
                            "type": "TextBlock",
                            "text": "some text"
                        },
                        {
                            "type": "Input.Date",
                            "separator": true
                        }
                    ]
                }
            }
        ]
    }