You can get some details of One on One chats in Microsoft Teams using the Microsoft Teams connector in Power Automate, but getting the actual details is slightly harder.
Using the List chats action you can choose to get chats of the different types available. This way you can get the chats that are within Groups, Meetings or the One on One chats.
When we run this flow however, we will only see very little details of the flow. So how do we get to the message details?
We will need to use the Graph API here.
I’ve checked the various connectors that support Graph API calls, but none of them support the Chat/Messages endpoints. It is time to go back to the HTTP/Custom connector option.
For more details on how to setup the Graph API in an HTTP request action please have a read through my blog post series on the Graph API and the Power Platform.
To set up the app registration, please make sure that you have included one of the following API permissions, if you are creating a custom connector.:
And if you are using the HTTP request action then you will need the application permission instead of the delegated ones.
Now we can build an HTTP request returning all the chats.
Notice that the above request will collect all the chats and not just the one to one chats.
First thing to add is a filter. This filter will make sure that we only get the chats of the Chat type One On One..
So far I’ve just replicated the List Chat action. Potentially I could just have used the List Chats action. Although, in the above example we will have a bit more flexibility on collecting chats for a specific user Account. Also the data returned has some additional properties in it.
The data returned should look like this:
{
"id": "19:092e5a70------------------------f94097890@unq.gbl.spaces",
"topic": null,
"createdDateTime": "2022-11-30T17:33:12.424Z",
"lastUpdatedDateTime": "2022-11-30T17:33:16.25Z",
"chatType": "oneOnOne",
"webUrl": "https://teams.microsoft.com/l/chat/19%3A092e5a70-3549-40ff-8fb0-e3d84ac-ae0f94097890%40unq.gbl.spaces/0?tenantId=3985---------------------e47",
"tenantId": "3985--------------------------e47",
"viewpoint": null,
"onlineMeetingInfo": null
}
Now the next part of this solution is to get the message details.
So the next step in the process is to get the messages of a chat. I can now build up my flow and collect the messages for my user account with the following HTTP request action.
But …
When we run this flow we will get the following message:
Invoked API requires Protected API access in application-only context when not using Resource Specific Consent. Visit https://docs.microsoft.com/en-us/graph/teams-protected-apis for more details.
So, this API is protected and we can’t get to it without specifically requesting access from Microsoft to use the requested API.
If we ran the flow and used the https://graph.microsoft.com/v1.0/me/chats endpoint rather than the user equivalent, then we would run into issues resulting in /me request is only valid with delegated authentication flow.
So the only option is to create a custom connector.
For more details on how to create a custom connector, please have a look at my Custom Connector with Microsoft Graph post.
When we import the endpoint that we want to use, we will see the following dialog. This is where all the magic will happen.
Now you could decide to make the Content Type and Accept header hidden and required as thee values will always be set to the same.
And then when we get to building our flow, we can collect the text of all the messages in a chat.
If you want to collect all the messages together into one array you could of course use Pieter’s method to do so. But this all depends on what you want to do with the messages found.
Continue Reading Pieter Veenstra’s Article on their blog
Get your Microsoft Teams 1on1 chats with Power Automate using the Graph API
You can get some details of 1on1 chats in Microsoft Teams using the Microsoft Teams connector in Power Automate, but getting the actual details is slightly
Blog Syndicated with Pieter Veenstra’s Permission