Mastering the Art of Converting Teams Webhook with Payload Type MessageCard for Power Automate
Image by Diwata - hkhazo.biz.id

Mastering the Art of Converting Teams Webhook with Payload Type MessageCard for Power Automate

Posted on

Are you tired of tediously sending messages to your Microsoft Teams channel every time a specific event occurs? Do you wish there was a more efficient way to automate this process? Look no further! In this article, we’ll guide you through the process of converting a Teams Webhook with a payload type of MessageCard to be used in Power Automate’s “Post to channel when a webhook request is received” workflow.

What is a Teams Webhook and MessageCard?

Before we dive into the conversion process, let’s take a step back and understand what a Teams Webhook and MessageCard are.

A Teams Webhook is a way to send notifications to a Microsoft Teams channel programmatically. It allows developers to send messages, cards, or even files to a specific channel. Webhooks are commonly used to integrate with external services, such as APIs, to notify teams of certain events or updates.

A MessageCard, on the other hand, is a payload type that can be sent via a Teams Webhook. It’s a JSON object that contains a rich set of data, including text, images, and buttons, which are displayed as a card in the Teams channel.

Why Convert a Teams Webhook to MessageCard?

Converting a Teams Webhook to a MessageCard payload type offers several benefits, including:

  • Customizable layout and design: MessageCards allow you to create visually appealing cards with images, icons, and text, making it easy to convey complex information in a concise manner.
  • Interactive elements: MessageCards can include interactive elements like buttons, which enable users to take actions directly from the card.
  • Better readability: MessageCards are easier to read and understand compared to plain text messages, making it ideal for sending critical information or updates.

Converting a Teams Webhook to MessageCard Payload Type

Now that we’ve covered the basics, let’s dive into the conversion process.

Step 1: Create a New Power Automate Flow

Log in to your Power Automate account and create a new flow. Click on the “Create from blank” button and search for “Webhook” in the trigger section.

Select the “When a HTTP request is received” trigger and click on “Create.”

Step 2: Set Up the Webhook Trigger

In the trigger settings, select “JSON” as the content type and add the following schema:

{
    "type": "object",
    "properties": {
        "title": {"type": "string"},
        "text": {"type": "string"}
    }
}

This schema defines the properties for the title and text of the MessageCard.

Step 3: Convert the Webhook Payload to MessageCard

In the next step, we’ll add an action to convert the webhook payload to a MessageCard. Search for “Compose” in the actions section and add a new compose action.

In the compose action, add the following code:

{
    "type": "https://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3",
    "body": [
        {
            "type": "TextBlock",
            "text": "@{triggerBody()?['text']}",
            "size": "Large"
        }
    ],
    "actions": [
        {
            "type": "Action.Submit",
            "title": "View details",
            "data": {
                "id": "view_details"
            }
        }
    ]
}

This code creates a basic MessageCard with a large text block displaying the text from the webhook payload and a “View details” button.

Step 4: Post the MessageCard to the Teams Channel

Finally, add a new action to post the MessageCard to the Teams channel. Search for “Post a message” in the actions section and add a new action.

Select the Teams channel you want to post to and add the following code in the message field:

@{outputs('Compose')?['body']}

This code posts the MessageCard to the selected Teams channel.

Example Use Case

Let’s say you want to send a notification to a Teams channel whenever a new issue is created in your project management tool. You can use a webhook to send the issue details to Power Automate, which then converts the payload to a MessageCard and posts it to the Teams channel.

Here’s an example MessageCard payload:

{
    "title": "New issue created",
    "text": "Issue #123: 'Error in login feature' has been created by John Doe."
}

The resulting MessageCard would look like this:

Issue card
New issue created
Issue #123: ‘Error in login feature’ has been created by John Doe.

Conclusion

Converting a Teams Webhook with a payload type of MessageCard to be used in Power Automate’s “Post to channel when a webhook request is received” workflow is a powerful way to automate notifications and create visually appealing cards in your Teams channel. By following the steps outlined in this article, you can unlock the full potential of MessageCards and take your automation game to the next level.

Remember to experiment with different MessageCard templates and layouts to create a unique experience for your team. With Power Automate and Teams Webhooks, the possibilities are endless!

Further Reading

If you want to learn more about Teams Webhooks and MessageCards, check out the following resources:

Happy automating!

Frequently Asked Questions

Get the scoop on converting Teams Webhooks with payload type MessageCard to be used in Power Automate’s “Post to channel when a webhook request is received” workflow!

What is the primary reason I need to convert Teams Webhook with payload type MessageCard to use it in Power Automate?

The primary reason is that Power Automate’s “Post to channel when a webhook request is received” workflow requires the webhook payload to be in a specific format, which is not the default MessageCard format used by Teams Webhooks. Converting the payload ensures that the webhook request is processed correctly and the message is posted to the channel successfully.

What changes do I need to make to the MessageCard payload to make it compatible with Power Automate?

You’ll need to modify the MessageCard payload to remove unnecessary fields and reformat the remaining fields to match the expected payload structure for Power Automate. This typically involves removing the “type” field, changing the “text” field to “body”, and reformatting the “attachments” field.

Can I use the same Webhook URL for both Teams and Power Automate?

No, you’ll need to create a separate Webhook URL for Power Automate. This is because the payload format required by Power Automate is different from the default MessageCard format used by Teams Webhooks.

Do I need to configure anything in Power Automate to receive the converted webhook request?

Yes, you’ll need to configure the “Post to channel when a webhook request is received” workflow in Power Automate to receive the converted webhook request. This involves setting up the webhook trigger, specifying the channel to post to, and configuring any additional actions or conditions as needed.

Can I use this approach for other types of webhooks and workflow scenarios?

Yes, the approach of converting the webhook payload to match the expected format can be applied to other types of webhooks and workflow scenarios. This allows you to integrate various systems and services with Power Automate, expanding its capabilities and enabling more sophisticated automation workflows.

Leave a Reply

Your email address will not be published. Required fields are marked *