Post to Microsoft Team from Flow

I was preparing a demo for the Arizona SharePoint Pros group on Microsoft Teams, PowerApps, and Flow, and I thought it would be cool if I could have my PowerApp post a message to a channel conversation for teams. After a bit of digging I got it to work. It is fairly simple to setup so I figured I would write this post to make it easier for others to setup.

Team Site Setup

For the demo I was doing, I went with a Wizard of Oz theme with the Emerald City Department of Transportation. More particularly the team responsible for maintaining the Yellow Brick Road. I created a list in the team site and on that list I created a PowerApp to gather road reports. The list is called RoadReport and has a title, description, and geolocation through latitude and longitude.

Microsoft Team Setup

Since messages can’t be posted directly to a team and need to go through a channel we need to enable a connector to allow us to add messages. So from teams click the … on the channel where you would like the messages to show up.

After clicking on the Connectos option you will get a modal that shows all the currently available connectors. If you search the connectors for Flow you will not find any at the moment. The approach we are going to use can be used from Flow or any other web enabled system. In the search box type webhook and you should see Incoming Webhook as an option.

On the right click add to configure our connector. To setup our connector we need two things, a name and an image. We could stick with the default incoming webhook image, but where’s the fun in that. I’m going to change the image out to an image of the Emerald City from the Yellow Brick Road perspective.

Once this is configured we can click create to get the information we need to be able to post our messages. After the modal reloads you will see the same information so if you wanted to change the image or get the URL later you can. If you scroll down underneath our image is a textbox that contains a URL. This URL is how we will be posting our messages to the channel. **You need to make sure that you keep this URL secure because anyone that has this URL can post messages to your channel as your connector.**

You can manually copy the URL from the textbox or you can click the copy button to the right of the box. We are now ready to setup our Flow. Click on the Flow tile from the app launcher and we are ready for the next step.

Flow Creation

Once in Flow make sure you are on your “My Flows” tab and click “Create from Blank”

On the next screen, we can start setting up our Flow. On the top where it says Untitled, we can set the name for our Flow. For our purposes, we are going to select SharePoint as the trigger. If you have not worked with Flow before, a flow has to have a trigger, which is what lets Flow know that it needs to start the process, and actions, these are the steps to perform.

We now need to decide which SharePoint event will trigger our Flow. We want our message to be posted when a new item is created so we are going to select “When a new item is created”.

We now need to specify a URL to our SharePoint site that has our list. The next box will then process all the lists in the site we entered and give us the list. We will then select the RoadReport list.

Now we are ready to start defining the steps in our process. We just need one step to accomplish our goal and that is, we need to add an HTTP action. Click on New Step and then click the Action button. Search for HTTP and you should get a list back of HTTP actions. We just need the basic HTTP action. The HTTP + Swagger option could work for us as well if we had a complicated JSON format that we needed to send data with but we are using a simple JSON object, so we will the basic HTTP action. Click on HTTP.

To setup our action we need to give it three pieces of information, the Method, Uri, and Body. We will be posting our data to the service so we will select post from the Method. This means that the parameters will be sent as the body of the message and not as part of the URL as we would with a get. Next, we paste in the URL that we got from setting up our connector. In order to do what we need with the web hook we have to provide the body in a specific format. Microsoft has provided documentation about what the parameters we can use are, https://go.microsoft.com/fwlink/?linkid=837668. Any formatting that we want to use needs to be in Markdown and not HTML. To post the message we need just the text value. We want our message to look like this “New Report: [Report Title]”. To accomplish this, we need to set our body to

{
    "text":"New Report: "
}

After you type this in put the cursor just inside the last quote and then select the title field underneath our box so your action looks like the following image.

Once we have completed this setup we are ready to Create the Flow, click “Create flow” near the top of the page. Next, we can click “Done” to close the designer. You should get a message that your flow is running. If you click manage you will be brought back to your “My Flows” page where we started in teams earlier. If you want to track the runs to make sure things are processing, click on the information button.

In the beginning, there should be nothing there. If we add a new item to the list, then in a few minutes when flow picks this up it will show up. We can check the status or just watch our team channel for it to show up.

We could easily modify our text value that we are sending to include more information like the detailed description, link to the item, etc.

That’s all there is to it. We could use the same endpoint created for our connector to post from other systems as well. Have fun and enjoy.

6 thoughts on “Post to Microsoft Team from Flow”

    1. Thanks, for some reason the image urls reverted to the path to the old host for my blog. This should be fixed now.

Leave a Reply

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