February 11, 2021

Exploring Microsoft Teams connector in Power Apps – Get Channel Messages

Introduction:

We recently implemented Power Apps - Canvas App that was having the integration with Microsoft Teams for Construction & Engineering company based out of Washington, United States. One of the requirements was to get the MS Teams - Channel Messages and display the same in Power Apps.

In this article, we will explore the Microsoft Teams connector available in Power Apps. The Teams connector with Power Apps opened lots of possibilities to leverage Teams capability within the Power Apps. Let's check how to get messages of a specific channel in MS Teams in PowerApps and what other actions are available using the Teams connector.

Business Scenario:

Here, first we will show all available Teams for the current logged in user. When user clicks on Teams name, this will open all channels for the current Team. Once we click on the channel name, we will be able to see all the messages from that channel on the right side section. That’s the end goal we will achieve at the end of the blog. So, now let’s get started!



Step 1: Add "MicrosoftTeams" connector in Power Apps from DataSource.

Step 2: Insert a Blank Gallery and add the below code in the Items of the Gallery.

 MicrosoftTeams.GetAllTeams().value  

Step 3: Add a label in the Gallery and show the DisplayName of the Items.

 ThisItem.displayName  

 Hence, you can see it will list all the teams that you are part of.


Step 4: Now we require all the channels of the selected Team. For that, insert another gallery and add this code into the Items of that Gallery.

MicrosoftTeams.GetChannelsForGroup(Gallery1.Selected.id).value 

Step 5: Now as we have both the Items (i.e. Team and Channel), we can get the messages of that specific selected channel. Insert a new Gallery and add this code in the Items property of that Gallery.

 SortByColumns(MicrosoftTeams.GetMessagesFromChannel(TeamsGallery.Selected.id,  
 ChannelGallery.Selected.id).value,"createdDateTime",Ascending)  

Step 6: Add a HtmlText in this Gallery and place the below code in the HtmlText

 ThisItem.body.content  

As the message which is returned is in the form of HTML, we need to use the HtmlText element for displaying messages. The final output may look something like shown in the below image:


Here are some of the properties which we can show along with the channel messages:

         From

         User

         ThisItem.from.user.displayName

         ThisItem.from.user.id

         Device

         ThisItem.from.device

         Attachments

         ThisItem.attachments

         Mentions

         ThisItem.mentions

         Reactions

         ThisItem.reactions

         Dates

         ThisItem.createdDateTime

         ThisItem.lastModifiedDateTime

         Importance

         ThisItem.importance

As a final outcome, we are able to generate the screen like below.

References:

Please check the following link to get more information about different available methods for Microsoft Teams connector for Power Apps.

https://docs.microsoft.com/en-us/connectors/teams/#actions

Conclusion:

This is how we can use the Microsoft Teams connector for fetching Channel messages in Power Apps. Happy Power Apping!

If you have any questions you can reach out our SharePoint Consulting team here.

No comments:

Post a Comment