【问题标题】:Adaptive card in teams not workig - REST API团队中的自适应卡不起作用 - REST API
【发布时间】:2020-09-12 22:35:08
【问题描述】:

我通过机器人框架为团队创建了一个机器人(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
        }
      ]
    }
  ]
}

非常感谢您的帮助

【问题讨论】:

  • 'Shalom' Hodaya Shalom :-)。您如何准确地附加/发送卡?你看过BotBuilder sample这个吗?
  • 我目前正在使用 REST API ׁׁ(我会检查机器人生成器)。您可以看到我发送的有问题的正文(卡片在附件中)。我很想知道为什么错误会出现在 REST API 中
  • 您使用的是哪个 REST Api? MS Graph,还是 Bot Framework 本身?如果是 Bot Framework,请务必使用提供的库。如果您采用 REST 方法,可能是因为您尝试发送主动消息,而不是对用户的响应 - 对吗?
  • bot 框架本身,是的 - 我发送主动消息,为什么这很重要?短信发送很好,还有英雄卡之类的卡片......
  • 好的,我想,只是想确认一下。如果您只是回复消息,与发送主动消息相比,情况略有不同,但无论哪种方式,Bot Framework 都提供了类来使其更容易,而不是直接调用 REST。网站上的一位编辑不喜欢我原来的答案有问题,所以我会在没有问题的情况下重新发布它(mah la'sot?)

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


【解决方案1】:

添加附件时,您需要设置附件对象的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
                    }
                ]
            }
        }
    ]
}

【讨论】:

    【解决方案2】:

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

    请具体查看this sample,了解如何在 Node 中执行此操作。

    【讨论】:

      猜你喜欢
      • 2020-08-13
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      • 2021-03-25
      • 2022-01-21
      • 2020-05-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多