团队中的自适应卡不起作用-REST API

时间:2020-05-26 07:31:31

标签: node.js rest botframework microsoft-teams adaptive-cards

我通过机器人框架为团队创建了一个机器人(nodejs服务器)。

我正在尝试发送通过以下方式创建的自适应卡:adaptive cards designer

我收到错误消息:

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

请求正文:

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

希望获得帮助

2 个答案:

答案 0 :(得分:2)

添加附件时,您需要设置附件对象的contentTypecontent属性。

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
                    }
                ]
            }
        }
    ]
}

答案 1 :(得分:0)

根据上面的评论,这是一条主动消息,但是使用Bot Framework库比尝试直接调用bot端点要好得多(我想知道,“ REST”是否意味着Bot框架端点或Graph Api,但无论哪种情况,Bot框架都更易于处理主动消息。

有关如何在Node中执行此操作,请具体参见this sample