New Power Automate Trigger: Launch a Flow from a Teams Message

If until now one of the flows that I have helped to configure the most are those that are launched manually from a SharePoint element , Microsoft has surprised me again and without a doubt the new trigger for Teams will give a lot to talk about and will be the protagonist in many business solutions .

Teams Message

Just a month ago Microsoft announced a couple of new triggers for Teams : one manual and one automatic. Although the automatic trigger is quite simple, it has a very interesting business use: it consists of capturing the event of a new user added to the team (perfect for automating welcome messages).

I think the new manual trigger is something that many of us have been waiting for for a long time: to be able to launch a flow from a message posted on a channel. Imagine the use cases that arise:

To show you all the potential, I have prepared a video with two use cases:

➡  In the simplest I show you how the trigger works , how to configure a very basic case to report inappropriate messages on a channel.

➡  The second, we increase the complexity by introducing an  Adaptive card  as a pop-up screen to give the user a choice between several options, even requesting additional information, before continuing with the flow.

As I always try, I share with you all the interesting code modules used for my demos. This is the code of the Adaptive card used to inform the administration / management user of the report of the message (it includes the two additional fields of the second use case):

{
  "type": "AdaptiveCard",
  "body": [
    {
      "type": "ColumnSet",
      "columns": [
        {
          "type": "Column",
          "width": "auto",
          "items": [
            {
              "type": "Image",
              "url": "https://static.thenounproject.com/png/540038-200.png",
              "size": "Small"
            }
          ]
        },
        {
          "type": "Column",
          "width": "stretch",
          "items": [
            {
              "type": "TextBlock",
              "text": "New request: Teams message reported",
              "color": "Attention",
              "weight": "Bolder"
            }
          ]
        }
      ]
    },
    {
      "type": "RichTextBlock",
      "inlines": [
        {
          "type": "TextRun",
          "text": "El usuario @{triggerBody()?['entity']?['teamsFlowRunContext']?['from']?['name']} ha reportado el siguiente mensaje en Teams por ser inapropiado. Por favor revise el contenido y tome las medidas necesarias de ser oportuno:"
        }
      ]
    },
    {
      "type": "FactSet",
      "facts": [
        {
          "title": "Enviado por:",
          "value": "@{triggerBody()?['entity']?['teamsFlowRunContext']?['messagePayload']?['from']?['user']?['displayName']}"
        },
        {
          "title": "Contenido del mensaje:",
          "value": "@{triggerBody()?['entity']?['teamsFlowRunContext']?['messagePayload']?['body']?['plainText']}"
        },
        {
          "title": "Motivo de la denuncia",
          "value": "@{triggerBody()?['entity']?['cardOutputs']?['selection']}"
        },
        {
          "title": "Comentarios sobre la denuncia",
          "value": "@{triggerBody()?['entity']?['cardOutputs']?['comments']}"
        },
        {
          "title": "Canal/Teams:",
          "value": "@{triggerBody()?['entity']?['teamsFlowRunContext']?['channelData']?['channel']} / @{triggerBody()?['entity']?['teamsFlowRunContext']?['channelData']?['team']}"
        }
      ]
    }
  ],
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.2",
  "actions": [
    {
      "type": "Action.OpenUrl",
      "title": "Ir al mensaje",
      "style": "positive",
      "url": "@{triggerBody()?['entity']?['teamsFlowRunContext']?['messagePayload']?['linkToMessage']}"
    }
  ]
}

view rawJSON AdaptiveCard ReportedMessage.json hosted with ❤ by GitHub

This is the code of the Adaptive card shown in pop up to interact with the user when launching the flow manually, and where the user chooses the reason for the report and adds a message:

{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.2",
    "body": [
        {
            "type": "TextBlock",
            "text": "Report a message",
            "weight": "Bolder",
            "size": "Medium",
            "color": "Attention",
            "fontType": "Default"
        },
        {
            "type": "TextBlock",
            "text": "Help us understand the problem. What's wrong with this message?",
            "isSubtle": true,
            "wrap": true
        },
        {
            "choices": [
                {
                    "title": "Seems to be spam",
                    "value": "spam"
                },
                {
                    "title": "intentions contrary to the organization",
                    "value": "against"
                },
                {
                    "title": "It's inappropriate or discriminatory ",
                    "value": "discriminatory"
                }
            ],
            "placeholder": "Select an option",
            "type": "Input.ChoiceSet",
            "id": "selection"
        },
        {
            "type": "TextBlock",
            "text": "Tell us more"
        },
        {
            "type": "Input.Text",
            "id": "comments",
            "style": "Tel",
            "spacing": "None",
            "placeholder": "Comments",
            "isMultiline": true
        }
    ],
    "actions": [
        {
            "type": "Action.Submit",
            "title": "Submit"
        }
    ]
}

view rawJSON AdaptiveCard PopUp message.json hosted with ❤ by GitHub

Some important things to note about this use case that I don’t mention in the video:
➡  flows with this trigger must be created in the default environment, as with the trigger of SharePoint.
➡  The flow will be available for all channels / teams, so it is advisable to give a simple and clear name to the flow.
➡  For the flow to be usable by members of an entire team or organization, we must share the flow (how to do it will be the key according to each scenario).
Tell me what you think of the new trigger or if you have any questions or obstacles in the configuration of the flow!

For more great content, check out the Resource Centre

About the Author:

My name is Mar and I present you my logbook: a blog where I write the experiences and knowledge that I want to share with you as I continue to learn.

Reference:

Llambí, M. (2020). NEW POWER AUTOMATE TRIGGER: LAUNCH A FLOW FROM A TEAMS MESSAGE. Available at: https://www.softwaringme.es/2020/08/nuevo-trigger-de-power-automate-lanzar.html [Accessed: 3rd March 2021].

Find more great Power Platform content here.

Share this on...

Rate this Post:

Share: