opticyclic
opticyclic

Reputation: 8146

How I Query Graph API For Chat Id In Teams?

I am exporting Teams chat history to html and need to work out how to query for the chat name.

When I know the chat id I can get the chat with

graphClient.me().chats("19:xxxxgbl.spaces").messages()

I can then page through the collection and output all the chats.
However, I don't know how to get the chat id from the API in the first place.

I was able to find the first one from the Graph Explorer with /beta/me/chats and then searching the preview for a channel name and finding the name in the topic field.

The same section/value doesn't exist for one on one chats with a colleague though. When I search the output of /beta/me/chats for my colleagues name it doesn't find it.

When I scroll down the output I see it has a webUrl field. Clicking on the 3rd item of the response to /beta/me/chats shows me the 3rd chats in the sidebar of Teams.

How can I find the chat id with the Java API if I know my colleagues name that I am chatting with?

Upvotes: 0

Views: 2232

Answers (1)

Glen Scales
Glen Scales

Reputation: 22032

Have you tried using the Search endpoint https://learn.microsoft.com/en-us/graph/search-concept-chat-messages . You can query on To, From or use Participants which would return anything where the target either sends or received a chat message eg

POST https://graph.microsoft.com/v1.0/search/query
{
    "requests": [
        {
            "entityTypes": [
                "chatMessage"
            ],
            "query": {
                "queryString": "participants:blah@blah.com"
            }
        }
    ]
}

This then returns both the ChatId and the MessageId

There is also an Export API https://learn.microsoft.com/en-us/microsoftteams/export-teams-content (it has a cost involved) if you where doing things a tenant level.

Upvotes: 0

Related Questions