Adaptive card in teams not workig - REST API

久未见 提交于 2020-06-17 09:42:39

问题


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


回答1:


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

https://docs.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
                    }
                ]
            }
        }
    ]
}



回答2:


As per the comments above, this is a pro-active message, but using the Bot Framework libraries are a much better approach than trying to call the bot endpoints directly (I wondered if, by "REST", you meant the Bot Framework endpoint or the Graph Api, but in either case the Bot Framework is easier to work with for proactive messages).

Please see specifically this sample for how to do this in Node.



来源:https://stackoverflow.com/questions/62016804/adaptive-card-in-teams-not-workig-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!