Forum Discussion

Thomas_Steibl's avatar
Thomas_Steibl
Brass Contributor
Feb 06, 2020
Solved

Send adaptive card via Powershell to a Teams Channel

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:

 

  • tomorgan's avatar
    tomorgan
    Feb 10, 2020

    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:

     

  • 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.
    • Thomas_Steibl's avatar
      Thomas_Steibl
      Brass Contributor

      tomorgan 

       

      $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'

       

      • tomorgan's avatar
        tomorgan
        MVP

        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:

         

Resources