Friday, March 1, 2019

Send Actionable Message Card to Microsoft Teams From Microsoft Flow

Microsoft Teams is an unified communications platform that combines persistent workplace chat, video meetings, file storage (including collaboration on files), and application integration.

Microsoft Flow is cloud-based service that allows business users to create and automate workflows and tasks across multiple applications and services. Currently Flow has a built-in Teams connector, and it does a decent job which allows Flow instances to post messages into Teams channels. However, the connector currently only supports plain text messages, and they look like coming from the authors of Flow instances. 

There is a way to post richer information to Teams through incoming webhook.

Teams Incoming webhook is a URL provided by Teams for any service to post content with the goal of sharing that content in your team's channel. When you configure it, you get a URL which represent an endpoint accepting JSON message. 

In the following example, I am going to show a simple Flow definition which contains one trigger and one action. On manual triggering, an actionable rich message card will be posed to a Teams channel. 

Step 1 Create an Incoming webhook in a Teams channel
















Name the webhook "SPWorkflowRichMsgCard" (the name can usually be an application or service which all members in the team understand)














Copy the Url of the webhook, and save it for later use












Step 2 Create the Flow definition with a manual trigger and a Http action


In Http action, switch "Method" to "POST", update Url to the Webhook Url saved above, add one header with key as "Content-Type" and value as "application/json", and also paste following JSON snippet into the text editor (Be aware of escaping "@" with "@@")

{
  "@@context": "https://schema.org/extensions",
  "@@type": "MessageCard",
  "themeColor": "0072C6",
  "title": "Sample Feedback Card",
  "text": "Tell us how you like Actionable Messages. Click **Learn More** to learn more about Actionable Messages!",
  "potentialAction": [
    {
      "@@type": "ActionCard",
      "name": "Send Feedback",
      "inputs": [
        {
          "@@type": "TextInput",
          "id": "feedback",
          "isMultiline": true,
          "title": "Let us know what you think about Actionable Messages"
        }
      ],
      "actions": [
        {
          "@@type": "HttpPOST",
          "name": "Send Feedback",
          "isPrimary": true,
          "target": "http://..."
        }
      ]
    },
    {
      "@@type": "OpenUri",
      "name": "Learn More",
      "targets": [
        {
          "os": "default",
          "uri": "https://docs.microsoft.com/outlook/actionable-messages"
        }
      ]
    }
  ]
}


Test the Flow







Open the Teams channel, there should be a rich message card posed by "SPWorkflowRichMsgCard", and it's ACTIONABLE!









Hopefully it's helpful...