Skip to content

Post Teams Message Sub Flow Development

We will now develop a Sub Flow to post a Notification to MS Teams when a Computer Inspection submission data is saved to the database.

A Sub Flow is interesting in that its invoked from a parent or main flow and has the ability to accept additional input. This additional input is important as some of the data processed in the main flow might have to be passed to the Sub Flow. Such input is passed in JSON format through a special parameter called Flow Input to Sub Flows. In our example we will pass the message that we want to send to Teams as a Flow Input so that the Teams Notification Sub Flow can be used by any flows. This is a very powerful concept and can later be extended to pass additional parameters like type of message, send as a card, importance or even post to a different channel.

For this tutorial we will first build the Sub Flow and then test it. Finally we will integrate it in the previously developed Save To Database Flow to post a notification about the Inspection to a Teams Channel.

You will need access to an MS Teams environment and PowerApps. If your company is not using Teams, you can still sign up for a free account if you want to test this flow. Alternatively you can use the same process to post a message to Slack or any other messaging tool as they all mostly follow the same process.

  1. Head over to Power Automate
  2. On the left side-bar choose Create and search for webhook.
  3. From the list of entries shown, select Post to a channel when a webhook request is received. and click Continue.
  4. Now select the Team and the Channel you want to send the message to.
  5. Complete the setup and close the pop-up window.
  6. We now need to get the webhook URL. For that click on the Edit button.
  7. From the list of nodes displayed select the first node ie. “When a Teams webhook is received”.
  8. A properties window is displayed and you need to Copy the generated HTTP URL.

Thats it, we are now ready to build the flow.

  1. In the Forms list, click on the Flows icon on the Computer Inspection row
  2. A list of Flows will be displayed. Now click on the Create button and choose the Sub Flow option
    • Title - Enter Post Message To Teams
    • Description - Enter description as Sub flow to post a message to MS Teams channel or similar
    • Click on Save to create the flow
  3. You will now be navigated to the Flow Builder

Before we develop the flow, let us draw a flow chart of the different steps we need to perform to save the data:

flowchart TD
    A([Start]) -->|Sub Flow Trigger| B[Extract Message]
    B --> C{Error}
    C --> |No| D[(Send Text To Teams)]
    C --> |Yes| E([ReturnError])
    D --> F{Error}
    F --> |No| G([Return Success])
    F --> |Yes| E
  1. In the Flow Builder, the Add Node dialog should already be open. If not, click on the Sub Flow start node and then click on the :fontawesome-solid-circle-plus: icon that is displayed below the node
  2. Search for the JSON Parser node by typing in json and clicking on it
  3. The JSON Parser node is now opened and you can configure it.
    1. Change the title to Extract Message and remember to connect the Sub Flow start node Success connector to this node (else the expression builder will not display all the possible fields and nodes)
    2. Since we want to work with the Flow Input, click on the Others section
    3. For Map Field Name select Flow Input
    4. Under Expression click on the :fontawesome-solid-wrench: icon to open the Expression Builder
    5. Let us define the Flow Input JSON looks like this:
      {
      "message":"Hi from my TurboApps Sub flow"
      }
    6. To extract the message, copy and paste the Flow Input JSON into the JSON window on the left
    7. The expression builder we use for JSON parsing is a tool called Jsonata
    8. The Teams webhook expects the message in JSON format: {"text":"message content"}
    9. We now need to extract the message field and prepare the JSON as Teams expects:
      $.{"text":message}
    10. Paste the expression from the step above into the Mapping Expression window on the right. The extracted message is now displayed at the bottom. Confirm that what is displayed is correct.
    11. Now Click on Save and close the builder,
    12. Now Click on the :fontawesome-solid-floppy-disk: icon and save the node
  4. Search for the HTTP node to send REST requests by typing in http and clicking on it
  5. The HTTP node is now opened and you can configure it.
    1. Change the title to Send Teams Message and remember to connect the Sub Flow node Success connector to this node (else the expression builder will not display all the possible fields and nodes)
    2. We will be adding a new system to communicate with the MS Teams Server. Later if we need to work with a different API provided by the Teams server we can reuse the server and modify the URL path we are communicating to. Click on :fontawesome-solid-plus: icon next to the Server dropdown.
    3. The Add System dialog is displayed. Enter the following data:
      • Description: Teams (or anything else you desire)
      • Identifier: This is a unique identifier for the system, enter ms-teams
      • URL: From the URL you copied while configuring teams, copy the host portion of the URL ie. from https until before the first /. You can leave out the :443 if present as that is the default https port and is not required.
      • Set the Authentication Type to None as the webhook does not require additional authentication
      • Set the OAuth Provider to None
      • Save the system
    4. Now choose the newly added ms-teams system (or the name that you entered above)
    5. Change the HTTP Action to Post
    6. Content-Type and Accept needs to be applicaiton/json
    7. For URL Path, from the MS Teams URL that was copied earlier, starting with the first / carefully until the end of the string.
    8. Now we need to configure the message. The Teams webhook expects the message in JSON format in the Body parameter which we have already preapared in the step above.
    9. Scroll down to the Body Data configuration and click on the :fontawesome-solid-wrench: icon to display the expression builder.
    10. From extractmessage select Success. This is now displayed in the edit box below as: ${extractmessage_result}
    11. Now click on the :fontawesome-solid-floppy-disk: icon and save the node
  6. Connect the Send Teams Message node to Success
  7. Now click on Publish button to save and compile the Sub flow. If the compilation is successful it will also be published and we can run it to test.
  1. Now that we have published the flow we are ready to test it. The Flow Builder has an integrated Run and Debug tool to help us troubleshoot the flow in case of errors.
  2. Now click on the Run Flow button. The Run dialog is now displayed. Since this is the first time we are running the flow we need to enter Form (test) data now by clicking on the Form Data button and saving it.
  3. Still in the Run Flow screen, copy the Flow Input JSON from above and paste it into the Flow Input field. The Flow Input now has the message that we want to send to the Teams channel.
  4. Run the flow by clicking on the Run button. The flow should run successfully.
  5. If there are errors it could be due to some mistakes while configuring the system or copy/pasting the expression or similar. Check each step carefully with the documentation above.
  6. Now login to your MS Teams App (Web, Desktop or Mobile) and check the newly created channel.
  7. You should now see the new message “Hi from my TurboApps sub flow” posted to the channel.
  8. Now click on Run Flow again. This opens the Run dialog and you can now change the Flow Input to:
    {
    "message":"Hi again, here is another message for you"
    }
  9. Run the flow by clicking on the Run button. The flow should run successfully.
  1. Navigate back to the Flows dialog by clicking on Flows in the breadcrumb in the title bar
  2. From the list of flows click on the Save To Database flow
  3. Click on the Save For Data node and then click on the :fontawesome-solid-circle-plus: icon that is displayed below the node
  4. Search for the Sub Flow node by typing in sub flow and clicking on it
  5. The Sub Flow node is now opened and you can configure it.
    1. Change the title to Notify On Team and remember to connect the Save Form Data node Success connector to this node (else the expression builder will not display all the possible fields and nodes)
    2. Click on the Workflow dropdown and choose the Post Message To Teams flow
    3. Leave the Execution Mode to the default “Execute as part of Parent flow”
    4. Scroll down to the Flow Input field and set it to:
      {"message":"Submission saved to Supabase"}
    5. Connect the Notify On Teams node to Success
  6. Now click on Publish button to save and compile the flow. If the compilation is successful it will also be published and we can run it to test.
  7. Now run the flow and once the Form (test) data is saved to the PostfgreSQL database on Supabase, a notification is also received on the Teams channel.

Now login to the Turbo Forms App on web or mobile as the same user and click on the + button to create a new form to fill and choose the Computer Inspection form. Fill in data, choose the user, take a picture and after filling all fields click on Complete. This will ensure that the form is finalized and the On Complete flow we developed above will be executed. You will now also see the notification in the Teams channel.

The flow above uses a Json Parser step to extract the message from the Flow Input field and post it to Teams as a JSON with the attribute text. We used the parser node to introduce data transformation as a part of the tutorial. As you probably realized by now, this is a redundant step as the Flow Input could have been defined as :"text":"message content"}. In this case there is no need of the transformation node itself and the Flow Input can directly be passed in as the Body parameter.

This is your assignment:

  1. Copy the Post Message To Teams flow to Post Message To Teams v2 using the Copy Flow option
  2. Change the Flow Input message format and post directly to Teams without the need for additional parsing

Check the solution for this assignment: Assignment Solution

  1. Configuring an HTTP Server and the other parameters to POST a REST message call to MS Teams
  2. Working with Flow Input
  3. Running the flow and testing it