SOLVED

Send adaptive card via Powershell to a Teams Channel

Brass Contributor

I created an adaptive card and want to send it via PowerShell to a Teams Channel via a webhook. Everything works so far, but the card is shown as a blank line?! :sad:

 

Annotation.png

5 Replies
Can you paste the card you’re sending?

It should work; but Teams doesn’t fully support all of the latest Adaptive Card stuff, so it might be that. Sometimes it’s a case of starting small and then building it back up to see where it breaks.

@Tom Morgan 

 

$body = @"
{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.0",
    "summary": "Adaptive Card Test",
    "body": [
        {
            "type": "TextBlock",
            "text": "Using Microsoft Teams",
            "size": "Large",
            "weight": "Bolder"
        },
        {
            "type": "Image",
            "altText": "",
            "url": "https://media.giphy.com/media/WOIGpnJ3ye445BUQl4/giphy.gif"
        },
        {
            "type": "TextBlock",
            "text": "Please make sure to read the User Guide first.",
            "horizontalAlignment": "Left",
            "height": "stretch",
            "wrap": true
        }
    ],
    "selectAction": {
        "type": "Action.OpenUrl",
        "title": "Request Office 365 Group",
        "url": "https://teams.microsoft.com/xyz"
    },
    "actions": [
        {
            "type": "Action.OpenUrl",
            "title": "Request Office 365 Group",
            "url": "https://teams.microsoft.com/xyz"
        }
    ]
}
"@

$uri = 'https://outlook.office.com/webhook/xyz'

Invoke-RestMethod -uri $uri -Method Post -body $body -ContentType 'application/json'

 

best response confirmed by Thomas_Steibl (Brass Contributor)
Solution

@Thomas_Steibl  Ah, ok, so I forgot something really important!  You can't use Adaptive Cards, you have to use the older MessageCard format. See https://docs.microsoft.com/en-us/outlook/actionable-messages/send-via-connectors for the detail, but this should work:


$body = ' {
  "@context": "https://schema.org/extensions",
  "@type": "MessageCard",
  "themeColor": "0072C6",
  "title": "Using Microsoft Teams",
  "text": "Please make sure to read the User Guide first.",
  "potentialAction": [
    
    {
      "@type": "OpenUri",
      "name": "Request Office 365 Group",
      "targets": [
        { "os": "default", "uri": "https://teams.microsoft.com/l/entity/81fef3a6-72aa-4648-a763-de824aeafb7d/_djb2_msteams_prefix_316372079?context=%7B%22subEntityId%22%3Anull%2C%22channelId%22%3A%2219%3A96f7bce5c6e2472a8f6e896ef0e4f875%40thread.skype%22%7D&groupId=d622b046-74e2-46a4-a1c6-63411f915464&tenantId=5176709f-3f1f-4e44-a034-277655f7629c" }
      ]
    }
  ]
}'

Should give you:

 

2020-02-10 08_58_13-POC Channel (Development) _ Microsoft Teams.png

@Tom Morgan 

oh wow okay. Thanks!

 

Any ideas if adaptive cards are coming to Teams?

1 best response

Accepted Solutions
best response confirmed by Thomas_Steibl (Brass Contributor)
Solution

@Thomas_Steibl  Ah, ok, so I forgot something really important!  You can't use Adaptive Cards, you have to use the older MessageCard format. See https://docs.microsoft.com/en-us/outlook/actionable-messages/send-via-connectors for the detail, but this should work:


$body = ' {
  "@context": "https://schema.org/extensions",
  "@type": "MessageCard",
  "themeColor": "0072C6",
  "title": "Using Microsoft Teams",
  "text": "Please make sure to read the User Guide first.",
  "potentialAction": [
    
    {
      "@type": "OpenUri",
      "name": "Request Office 365 Group",
      "targets": [
        { "os": "default", "uri": "https://teams.microsoft.com/l/entity/81fef3a6-72aa-4648-a763-de824aeafb7d/_djb2_msteams_prefix_316372079?context=%7B%22subEntityId%22%3Anull%2C%22channelId%22%3A%2219%3A96f7bce5c6e2472a8f6e896ef0e4f875%40thread.skype%22%7D&groupId=d622b046-74e2-46a4-a1c6-63411f915464&tenantId=5176709f-3f1f-4e44-a034-277655f7629c" }
      ]
    }
  ]
}'

Should give you:

 

2020-02-10 08_58_13-POC Channel (Development) _ Microsoft Teams.png

View solution in original post