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.
Prerequisite - MS Teams
Section titled “Prerequisite - MS Teams”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.
- Head over to Power Automate
- On the left side-bar choose
Createand search forwebhook. - From the list of entries shown, select
Post to a channel when a webhook request is received.and clickContinue. - Now select the
Teamand theChannelyou want to send the message to. - Complete the setup and close the pop-up window.
- We now need to get the webhook URL. For that click on the
Editbutton. - From the list of nodes displayed select the first node ie. “When a Teams webhook is received”.
- A properties window is displayed and you need to Copy the generated HTTP URL.
Thats it, we are now ready to build the flow.
Flow Development
Section titled “Flow Development”- In the Forms list, click on the
Flowsicon on the Computer Inspection row - A list of Flows will be displayed. Now click on the
Createbutton and choose theSub Flowoption- Title - Enter Post Message To Teams
- Description - Enter description as Sub flow to post a message to MS Teams channel or similar
- Click on
Saveto create the flow
- You will now be navigated to the Flow Builder
Understanding the steps
Section titled “Understanding the steps”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
Developing the Flow
Section titled “Developing the Flow”- In the Flow Builder, the
Add Nodedialog should already be open. If not, click on theSub Flowstart node and then click on the :fontawesome-solid-circle-plus: icon that is displayed below the node - Search for the
JSON Parsernode by typing in json and clicking on it - The
JSON Parsernode is now opened and you can configure it.- Change the title to
Extract Messageand remember to connect theSub Flowstart nodeSuccessconnector to this node (else the expression builder will not display all the possible fields and nodes) - Since we want to work with the Flow Input, click on the
Otherssection - For
Map Field NameselectFlow Input - Under
Expressionclick on the :fontawesome-solid-wrench: icon to open the Expression Builder - Let us define the Flow Input JSON looks like this:
{"message":"Hi from my TurboApps Sub flow"}
- To extract the message, copy and paste the Flow Input JSON into the
JSONwindow on the left - The expression builder we use for JSON parsing is a tool called Jsonata
- The Teams webhook expects the message in JSON format:
{"text":"message content"} - We now need to extract the message field and prepare the JSON as Teams expects:
$.{"text":message}
- Paste the expression from the step above into the
Mapping Expressionwindow on the right. The extracted message is now displayed at the bottom. Confirm that what is displayed is correct. - Now Click on
Saveand close the builder, - Now Click on the :fontawesome-solid-floppy-disk: icon and save the node
- Change the title to
- Search for the
HTTPnode to send REST requests by typing in http and clicking on it - The
HTTPnode is now opened and you can configure it.- Change the title to
Send Teams Messageand remember to connect theSub FlownodeSuccessconnector to this node (else the expression builder will not display all the possible fields and nodes) - 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.
- The
Add Systemdialog 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 Typeto None as the webhook does not require additional authentication - Set the
OAuth Providerto None - Save the system
- Now choose the newly added
ms-teamssystem (or the name that you entered above) - Change the
HTTP Actionto Post Content-TypeandAcceptneeds to be applicaiton/json- For
URL Path, from the MS Teams URL that was copied earlier, starting with the first / carefully until the end of the string. - Now we need to configure the message. The Teams webhook expects the message in JSON format in the
Bodyparameter which we have already preapared in the step above. - Scroll down to the
Body Dataconfiguration and click on the :fontawesome-solid-wrench: icon to display the expression builder. - From
extractmessageselect Success. This is now displayed in the edit box below as: ${extractmessage_result} - Now click on the :fontawesome-solid-floppy-disk: icon and save the node
- Change the title to
- Connect the
Send Teams Messagenode to Success - 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.
Testing the Flow
Section titled “Testing the Flow”- 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.
- 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 Databutton and saving it. - 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.
- Run the flow by clicking on the
Runbutton. The flow should run successfully. - 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.
- Now login to your MS Teams App (Web, Desktop or Mobile) and check the newly created channel.
- You should now see the new message “Hi from my TurboApps sub flow” posted to the channel.
- Now click on Run Flow again. This opens the Run dialog and you can now change the
Flow Inputto:{"message":"Hi again, here is another message for you"} - Run the flow by clicking on the
Runbutton. The flow should run successfully.
Integrating the flow in the Database Flow
Section titled “Integrating the flow in the Database Flow”- Navigate back to the
Flowsdialog by clicking onFlowsin the breadcrumb in the title bar - From the list of flows click on the Save To Database flow
- Click on the
Save For Datanode and then click on the :fontawesome-solid-circle-plus: icon that is displayed below the node - Search for the
Sub Flownode by typing in sub flow and clicking on it - The
Sub Flownode is now opened and you can configure it.- Change the title to
Notify On Teamand remember to connect theSave Form DatanodeSuccessconnector to this node (else the expression builder will not display all the possible fields and nodes) - Click on the
Workflowdropdown and choose the Post Message To Teams flow - Leave the Execution Mode to the default “Execute as part of Parent flow”
- Scroll down to the
Flow Inputfield and set it to:{"message":"Submission saved to Supabase"} - Connect the
Notify On Teamsnode to Success
- Change the title to
- 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.
- 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.
Login to Turbo Forms App
Section titled “Login to Turbo Forms App”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.
Assignment
Section titled “Assignment”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:
- Copy the
Post Message To Teamsflow toPost Message To Teams v2using theCopy Flowoption - 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
Topics Covered
Section titled “Topics Covered”- Configuring an HTTP Server and the other parameters to POST a REST message call to MS Teams
- Working with
Flow Input - Running the flow and testing it