Post Message to Microsoft Teams through PowerApps

Hope you all liked my last blog , today we will learn to Post Message to Microsoft Teams through PowerApps. We will discuss in detail how we can post message to a channel created in the group of MS teams.

We all know that MS Teams is getting popular day by day. And at some point we will need to integrate with PowerApps. May be someone already have this requirement in their hand. So let’s start integration of teams with powerapps.

Create a new data connection

First we will create a new data connection in our app. Follow below steps.

Microsoft Teams through PowerApps

After establishing the data connection, we will create our screen with different controls.

Microsoft Teams through PowerApps
We will bind items to drop downs and galleries by below formaula
Dropdown 1 -> Items -> MicrosoftTeams.GetAllTeams().value
Dropdown 2 -> Items -> MicrosoftTeams.GetChannelsForGroup(Dropdown1.SelectedText.id).value.id
Gallery 1-> MicrosoftTeams.GetAllTeams().value
Now we will add two labels in gallery 1. Text value for first label is ThisItem.displayName and second label is ThisItem.id
Gallery 2 -> Items ->MicrosoftTeams.GetChannelsForGroup(Dropdown1.SelectedText.id).value
Add two labels in gallery 2 too, same as of gallery 1. Text value for first label is ThisItem.displayName and second label is ThisItem.id

We are using galleries to show GUID and display name of Group and channels of MS Teams.

Write below formula on the POST button. 
MicrosoftTeams.PostMessageToChannel(Dropdown1.SelectedText.id,Dropdown1_1.SelectedText.id,{body:{content:TextInput1.Text,contentType:0}});Refresh(MicrosoftTeams.GetAllTeams())
For detailed guide on MicrosoftTeams.PostMessageToChannel method please refer this link.

Explanation of function: PostMessageToChannel(groupId, channelld, rootMessage)

groupld: unique id of the Team (string)
channelld: unique id of the channel (string)
rootMessage: message to be posted (record)

The rootMessage body record is made up of these values:
content: message to be posted
contentType: 0 for text or 1 for html

After doing all the above steps you post message to the desired channel of your MS Teams. If you like this post, please share and subscribe our site for more upcoming posts. You can enroll for PowerApps/Flow training here & for SharePoint Framework training enroll here. In comment section you can provide you suggestions for upcoming posts.