You may have the need to archive chat messages or capture chat sessions for further processing. Activities like summarizing the conversation, extract action items, or suggesting meeting times can be done by analyzing the chat conversation. This starts with extracting the conversation using the Microsoft Graph APIs. In Microsoft Teams, a chat conversation is made up of messages and replies. A 'message' is the initiating text. Responses to the initial prompt by recipients of the message and the message initiator are 'replies'. For example:
In this case the 'message' is 'Where did you want to meet for lunch?'. The remainder of the conversation are 'replies'. The Microsoft Teams Connector, provides methods we need to extract the messages. However, no method is provided for collecting the message replies. For this, we will call the Microsoft Graph using a custom connector.
An exported solution with the following implemented can be downloaded here.
The Postman Graph API collection is very useful for experimenting with the Graph APIs. See here: Use Postman with the Microsoft Graph API - Microsoft Graph | Microsoft Learn This useful for getting the Team, Channel and Message ids you'll need for testing the custom connector.
In this step we'll create a custom connector that will call the MS Graph API:
GET /teams/{team-id}/channels/{channel-id}/messages/{message-id}/replies
Connector Name: GetMessageReplies Key Fields: General:
Host: graph.microsoft.com
Security:
Authentication Type: OAuth 2.0
Identity Provider: Azure Active Directory
Client ID: <client id from AAD section above>
Authorization URL: https://login.microsoftonline.com
Tenant ID: common
Resource URL: https://graph.microsoft.com
Redirect URL: https://global.consent.azure-apim.net/redirect
Definition:
General:
Summary: Get message replies
Description: Get message replies
Operation ID: Get-message-replies
Visibility: Important
Request:
Import from sample:
GET
URL: https://graph.microsoft.com/beta/teams/{TeamId}/channels/{ChannelId}/messages/{MessageId}/replies
// Response:
// Import from sample:
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#teams('eb825a11-3b12-4c5f-8258-fd405b1395c8')/channels('19%3Aq0-BRQ6TDgcZczl9O7V2Ye078k1eOIzgghUkpRzTlW41%40thread.tacv2')/messages('1677699468267')/replies",
"@odata.count": 0,
"value": []
}
Test:
In the following steps, we'll create a flow that will collect chat messages and replies for every Team the service account is a member. The idea here is that an admin would add this user account to each Team where they want to extract the chat messages.
In this step we'll create a scheduled flow that calls a child flow that will capture the messages and replies and pass them back to the calling flow. This is required to have the flow run in the context of the 'run-only' user, which will be the Service Account created in the AAD section above.
Save the Flow
On the Flow's detail page, edit the 'Run only users' and set the 'Connections Used' for Microsoft Teams and GetAllTeams (Custom Connector) to be the Service Account.
Here is an example of the output of the chat in the first screenshot:
{
"Team": "Demo Team",
"Channel": "Project Silver",
"MessageId": "1677098428650",
"MessageText": "Where did you want to meet for lunch?",
"ReplyId": "1677098885814",
"ReplyText": "I'd don't want to go all the way out to Dunmore."
},
{
"Team": "Demo Team",
"Channel": "Project Silver",
"MessageId": "1677098428650",
"MessageText": "Where did you want to meet for lunch?",
"ReplyId": "1677098838074",
"ReplyText": "No seafood. How about Cugino's?"
},
{
"Team": "Demo Team",
"Channel": "Project Silver",
"MessageId": "1677098428650",
"MessageText": "Where did you want to meet for lunch?",
"ReplyId": "1677098447360",
"ReplyText": "How about Cooper's?"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.