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...

Thursday, February 28, 2019

Send Actionable Message Card to Microsoft Teams From SharePoint Workflows

Traditionally, SharePoint designer workflows help organizations to adhere to consistent business processes, and they also improve organizational efficiency and productivity by managing the tasks and steps involved in business processes.

As Microsoft is moving the enterprise collaboration ecosystem from on-premises to the cloud, many new cloud services created in the cloud are separated from the existed business processes leveraging the old fashion SharePoint workflows. 

To bridge the gap of business process automation between on-premises and the cloud, Microsoft put Flow as the successor of SharePoint workflow. However, due to the heavy investment made in SharePoint designer workflows, it might take a long time to make the switch. 

In the meantime, it's possible to take advantage of the new services in the cloud from the existing SharePoint workflows. I am going to show a simple example of sending an actionable message card to a Microsoft Teams channel from a SharePoint workflow. 

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 can understand)












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











Step 2 Create a simple workflow




Add "Build Dictionary" action
Name the dictionary "RequestHeader". (Note: value of "Authorization" is empty string)
Fill "RequestHeader" with http header info
 


Add "Set Workflow Variable" Action


Name the variable "TempRequestBody", and set it as String
Open text builder
Paste following JSON snippet into the text editor, and save it
{
  "@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"
        }
      ]
    }
  ]
}
















Add another "Set Workflow Variable" action, name it "RequestBody", and set it as Dictionary, Open workflow lookup window











Set "Data source" as "Workflow Variables and Parameters", "Field from source" as "Variable: TempRequestBody" (the String variable defined above)


Add "Call Http Web Service" action











Update the Url of the service with the webhook Url saved above




Update the properties of the "Call Http Web Service" action





Update the value of "RquestHeaders" with variable "RequestHeader"


Update the value of "RquestContent" with variable "RequestBody", and save the changes


Add workflow end stage, then save and publish the workflow






Step 3 Test it

Trigger a workflow instance






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









Hope it's helpful...