Power Apps: How to interact with teams

The idea is to present you the Microsoft Teams connector, the boundaries of this connector and how to workaround some issues.

  1. Get ids in url
  2. Microsoft Teams connector in PowerApps
  3. Get all teams
  4. Get channels from team
  5. Get messages in channel
  6. Create a channel
  7. Send message into channel
  8. Send reply to a message
  9. Interact with a flow bot

Get ids in url

We will be to able to get id of different element in Powerapps itself, but it is good to know how to get it with the url.

To get the url, try to copy the link to the team or the channel. Of course depending on where you get the link, you don’t have the same level of information. Mostly you need to click on the … then on Get link to channel or team.


Tenant ID
The tenant id is under the tenantId parameter in the url.

https://teams.microsoft.com/l/team/19%3a00000000000000000000000000000000%40thread.skype/conversations?groupId=00000000-0000-0000-0000-000000000000&tenantId=00000000-0000-0000-0000-000000000000

Team ID
The team id is under the groupId parameter in the url.

https://teams.microsoft.com/l/team/19%3a00000000000000000000000000000000%40thread.skype/conversations?groupId=00000000-0000-0000-0000-000000000000&tenantId=00000000-0000-0000-0000-000000000000

Channel ID
The channel ID isn’t in a parameter, you will find it in the url as /channel/ID. It start with 19: and finish with @thread.skype.

https://teams.microsoft.com/l/channel/19%3a00000000000000000000000000000000%40thread.skype/From%2520Powerapps?groupId=00000000-0000-0000-0000-000000000000&tenantId=00000000-0000-0000-0000-000000000000

Message ID
As for the others ID, you need to click on the … right to the right side of the message such as adding a like. Click again on the … then copy link.


On the link, the ID of the message is going to be after the channel ID in url. You will also find a parentMessageId, it is different from the message id if you picked up a reply message.

https://teams.microsoft.com/l/message/19:00000000000000000000000000000000@thread.skype/1576000000000?tenantId=00000000-0000-0000-0000-000000000000&groupId=00000000-0000-0000-0000-000000000000&parentMessageId=1575000000000&teamName=Tests%20Microsoft%20Teams&channelName=From%20Powerapps&createdTime=1576359062924

Microsoft Teams connector in PowerApps

Let’s start with the connector in PowerApps. In the connectors panel, such as connecting SharePoint database, you will find the Microsoft Teams connector. Click on it then on add a connection.

Get all teams

The method is GetAllTeams() from the Microsoft Teams connector. It will return all the team you have the permissions on. Don’t forget, Powerapps is going to use the current user credential, if this one doesn’t have the persmissions on the team, it won’t be able to get it through Powerapps.

MicrosoftTeams.GetAllTeams()


It will return an object as following:

{
     '@odata.context' : "https://graph.microsoft.com/v1.0/$metadata#groups",
     value : [ARRAY OF OBJECTS WITH THE RESULT]
}


So if you want to use it, in a gallery for example, you need to get the value.

MicrosoftTeams.GetAllTeams().value


The object(s) returned are as following:

Key nameTypeDescription
displayNameStringThe display name of the team.
idGuid as StringGUID of the team.
descriptionStringDescription of the team.

Example with the display name:

Get channels from team

Again from the Microsoft Team connector, we will use the method GetChannelsForGroup(). It will return the channel from a specific team id. Don’t forget, Powerapps is going to use the current user credential, if this one doesn’t have the persmissions on the channel, it won’t be able to get it through Powerapps.
The input is going to be the Guid of the team you want to get the channels from. If you wonder how to get the id through the url, follow Get ids in url.

MicrosoftTeams.GetChannelsForGroup("00000000-0000-0000-0000-000000000000")

It will return an object as following:

{
     '@odata.context' : "https://graph.microsoft.com/v1.0/$metadata#teams('00000000-0000-0000-0000-000000000000')/channels",
     value : [ARRAY OF OBJECTS WITH THE RESULT]
}

So let say I select the team from the gallery of the get teams screen, then I display the channel associated into another gallery through another screen. It would be as following:

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

The object(s) returned are as following:

Key nameTypeDescription
displayNameStringThe display name of the channel.
idGuid as StringGUID of the channel, starting with 19: and finishing with @thread.skype.
descriptionStringDescription of the channel.

Get messages in channel

Again from the Microsoft Team connector, we will use the method GetMessagesFromChannel(). It will return the message from a specific channel and team id. Don’t forget, Powerapps is going to use the current user credential, if this one doesn’t have the persmissions on the channel, it won’t be able to get the messages in it through Powerapps.
The inputs are going to be the Guid of the team and Id if the channel you want to get the messages from. If you wonder how to get the id through the url, follow Get ids in url

MicrosoftTeams.GetMessagesFromChannel([GUID OF TEAM],[ID OF CHANNEL])
MicrosoftTeams.GetMessagesFromChannel("00000000-0000-0000-0000-000000000000","19:00000000000000000000000000000000@thread.skype")

It will return an object as following:

{
     '@odata.context' : "https://graph.microsoft.com/beta/$metadata#teams('00000000-0000-0000-0000-000000000000')/channels('19%3A00000000000000000000000000000000%40thread.skype')/messages",
     '@odata.count' : [NUMBER OF MESSAGES]
     value : [ARRAY OF OBJECTS WITH THE RESULT]
}

So let say I select the channel from the gallery of the get channels screen, then I display the messages associated into another gallery through another screen. It would be as following:

MicrosoftTeams.GetMessagesFromChannel(galTeams.Selected.id,galChannel.Selected.id).value

The object(s) returned are as following:

Key nameTypeDescription
idStringId of the message.
importanceStringImportance of the message, will return normal or high.
subjectStringSubject of the message
bodyObjectObject which represent the body of our message.
body.contentTypeStringWill return text or html. It means which kind of content type have the body, plain text or html.
body.contentStringThe content of your message.
createdDateTimeDateDate and time of when the message has been created.
lastModifiedDateTimeDateDate and time of when the message has been edited for the last time. If never edited, value is blank.

Example with the id:

Create a channel

Again from the Microsoft Team connector, we will use the method CreateChannel(). It will create a channel in a specific team. Don’t forget, Powerapps is going to use the current user credential.
We are going to need id of team, if you wonder how to get the id through the url, follow Get ids in url

MicrosoftTeams.CreateChannel(  
    [ID OF TEAM],
    [CHANNEL NAME],
    {description: [CHANNEL DESCRIPTION]}
)

So for example:

MicrosoftTeams.CreateChannel(  
    [ID OF TEAM],
    [CHANNEL NAME],
    {description: [CHANNEL DESCRIPTION]}
)

So basically on my screenshot, I select a team from my gallery of teams (see above) and I will create a Channel from in this team:


Demo:

Send message into channel

Again from the Microsoft Team connector, we will use the method PostMessageToChannelV3(). It will post a message to a specific channel and team id. Don’t forget, Powerapps is going to use the current user credential, if this one doesn’t have the persmissions on the channel, it won’t be able to post messages in it through Powerapps.
Also please note that it will post the message under the current user loged on Powerapps.
We are going to need id of team and channel, if you wonder how to get the id through the url, follow Get ids in url
To call this method, it is going to be as following:

MicrosoftTeams.PostMessageToChannelV3(  
    [ID OF TEAM],
    [ID OF CHANNEL],
    {
        content : [TEXT OF THE MESSAGE],
        contentType : [CONTENT TYPYE IS "Text" OR "Html"]
    },
    {
        subject: [TEXT OF THE SUBJECT]
    }
)

Input definition:

Key nameTypeMandatoryDescription
ID OF TEAMGUID as StringYesID of the team where the channel is.
ID OF CHANNELStringYesID of the channel you want to post your message to
TEXT OF THE MESSAGEStringYesText of your message to post on the channel. It has to be into an object, which contains the content and the contentType (see example).
CONTENT TYPEEnum of StringYesCan be “Text” or Html”. If you put Text, it will post your message as plain text. If you put Html, it will post your message as html. It has to be into an object, which contains the content and the contentType (see example).
TEXT OF THE SUBJECTTextNoText of the subject. It has to be into an object, which contains the subject key. If not used remove the whole subject object.

Example message with html and subject:

MicrosoftTeams.PostMessageToChannelV3(  
    "00000000-0000-0000-0000-000000000000",
    "19:00000000000000000000000000000000@thread.skype",
    {
        content: "<p>This is a <a href='https://docs.microsoft.com/en-us/connectors/teams/'>link </a>to the <strong>documentation</strong>.</p>",
        contentType: "Html"
    },
    {subject: "Documentation"}
)

Example message with plain text and without subject:

MicrosoftTeams.PostMessageToChannelV3(  
    "00000000-0000-0000-0000-000000000000",
    "19:00000000000000000000000000000000@thread.skype",
    {
        content: "This is plain text message.",
        contentType: "Text"
    }
)

A little screen shot of a screen that I have made which post message into teams. Example with subject and HTML:

Demo of how to post a message:

Send reply to a message

Again from the Microsoft Team connector, we will use the method PostReplyToMessageV2(). It will post a reply to a specific message in accordance of a channel and team id. Don’t forget, Powerapps is going to use the current user credential, if this one doesn’t have the persmissions on the channel, it won’t be able to post messages in it through Powerapps.
Also please note that it will post the message under the current user loged on Powerapps.
We are going to need id ofmessage, team and channel, if you wonder how to get the id through the url, follow Get ids in url
To call this method, it is going to be as following:

MicrosoftTeams.PostReplyToMessageV2(  
    [ID OF TEAM],
    [ID OF CHANNEL],
    [ID OF MESSAGE],
    {
        content: [TEXT OF MESSAGE],
        contentType: [CONTENT TYPE, "Text" or "Html"]
    }
)

Input definition:

Key nameTypeMandatoryDescription
ID OF TEAMGUID as StringYesID of the team where the channel is.
ID OF CHANNELStringYesID of the channel where the message is.
ID OF MESSAGEStringYesID of the message you want to send a reply.
TEXT OF THE MESSAGEStringYesText of your message to post on the channel. It has to be into an object, which contains the content and the contentType (see example).
CONTENT TYPEEnum of StringYesCan be “Text” or Html”. If you put Text, it will post your message as plain text. If you put Html, it will post your message as html. It has to be into an object, which contains the content and the contentType (see example).

Example:

MicrosoftTeams.PostReplyToMessageV2(  
    "00000000-0000-0000-0000-000000000000",
    "19:00000000000000000000000000000000@thread.skype",
    "1570000000000",
    {
        content: "<p>This is my <strong>reply</strong>.</p>",
        contentType: "Html"
    }
)

On the following screenshot, I have made a screen, which select team, channel and message from the different gallery in the previous part and send a reply.

Demo:

Interact with a flow bot

Playing with the Teams connector is fun but you might want to go further. You can use a Flow bot in teams:

  • Instead of using the credentials of the current user in Powerapps, it will use the flow bot for publication.
  • Some functionalities in the PowerApps connector seems to be still under construction, such as notify user.

So basically the idea is to integrate PowerAutomate into your teams and create flows and use the Microsoft Teams connector to perform action.


So let’s say I am creating a flow, which will be triggered manually in PowerApps and will publish a message to an user through the flow bot, which will be as following:


And in PowerApps I am calling the flow:


Demo:


Of course, here in PowerApps we only call a flow, but feel free to have a look at the teams connector in PowerAutomate to see what you can do.