Microsoft Teams

Download 34
Last updated Nov 20, 2026

User Guide

Overview

Target users: operators in organizations using Microsoft 365 who want to receive security alerts in Teams, and security officers who need to review Teams chat history for audits or investigations

Use the Microsoft Teams app to perform the following tasks.

  • Send detection results or check alerts to a Teams channel
  • Query the user list of a Microsoft Entra tenant
  • Query the one-on-one and group chat messages a user took part in

Each query command requests the results from Microsoft when it runs.

Concepts and Terms

TermMeaningRelated resource
Workflow webhookA URL issued to post messages to a Teams channel. The target channel is already fixed in the URLInstall Guide
Microsoft Teams Graph API connect profileA query-only connect profile that stores the tenant ID, client ID, and client secret. Separate from the profile for sending messagesInstall Guide
User principal name (UPN)The account name used to sign in. Used to specify the target user of the query commands. e.g. hong@example.comms-teams-users
User object IDA 36-character identifier that Microsoft Entra assigns to a user. Can be used instead of the UPNms-teams-users
ChatOne-on-one and group conversations. Messages posted to team channels are not queriedms-teams-chat-messages
System event messageA message not typed by a person, such as adding or removing a member. Excluded from query results by defaultms-teams-chat-messages
Connect profileA Sonar object that stores the credentials required to connect to Microsoft Teams (the workflow webhook URL, or the tenant ID, client ID, and client secret)Install Guide

Screens and Menu Paths

FeaturePath
App managementApps
Connect profilesSystem > Connect Profile
Run query commandsAnalysis > Queries
Register periodic runsAnalysis > Scheduled Queries

Task Scenarios

Scenario 1: Review the chat messages of a specific user

Purpose: Review the chats that a user exchanged during a specific period, when a security inquiry or an audit request is raised for that user.

Prerequisites:

Procedure:

  1. Go to Analysis > Queries.
  2. Check the account of the target user.
ms-teams-users profile=ms_teams_graph
| search is_enabled == true
| fields user, user_name, email
  1. Query the chat messages with the account you checked. Specify the period with the duration option, or use the from and to options to view a specific range.
ms-teams-chat-messages profile=ms_teams_graph user="hong@example.com" duration=1d
| sort -_time
| fields _time, from_user_name, msg, chat_id

Check the results:

The query should return records like the following.

_timefrom_user_namemsgchat_id
2026-09-10 14:02:11Gildong HongSharing the meeting notes19:abc123@thread.v2
2026-09-10 13:58:40Gildong HongGot it19:abc123@thread.v2
  • Records with the same chat_id belong to the same conversation. Filter by this value to follow a specific conversation.
  • The msg field contains the body with HTML markup removed. Check the original format in the content_type field.
  • Line breaks are joined with spaces, and emoji and link addresses are kept. Attachments that are not part of the body, such as link preview cards, are not included.

Troubleshooting:

SymptomCauseSolution
No resultsThere was no conversation during the period, or the period is too shortIncrease the duration value or widen the range with from and to, then run again
user option should be a user principal name or an object IDA value in the wrong format, such as a display name or mail alias, was specifiedCheck the account (UPN) first with step 2 of Scenario 1
No available Microsoft Teams Graph API connect profile found.The profile option contains the name of the connect profile, or a wrong identifierEnter the identifier of the connect profile, not its name
An error starting with cannot issue Microsoft Graph access token: invalid_client, AADSTS7000215The client secret value is wrong, including when the secret ID was enteredEnter the value of the client secret again from Certificates & secrets of the Microsoft Entra app, or issue a new one
Microsoft Graph API returned 403 Forbidden - 애플리케이션 권한과 관리자 동의를 확인해주세요.The Chat.Read.All permission is missing, or admin consent has not been grantedPerform step 3 of 2. Register a Microsoft Entra App in the install guide again
An error starting with Microsoft Graph API error 404: NotFound, Failed to find user with idThe user specified in the user option does not exist in the tenantCheck the account (UPN) first with step 2 of Scenario 1

Scenario 2: Periodically collect the chat messages of all users

Purpose: Query the chat messages of all active users in the tenant at a fixed interval, to track the conversation volume or keep reference material for investigations.

Prerequisites:

  • The prerequisites of Scenario 1 must be met.
  • The number of calls grows with the number of users, so decide the run interval and period first.

Procedure:

  1. Run the following query in Analysis > Queries and check the results and the elapsed time. The batch command reads the user field of the incoming records and queries each user.
ms-teams-users profile=ms_teams_graph
| search is_enabled == true
| ms-teams-chat-messages-batch profile=ms_teams_graph duration=1h
| stats count by user
  1. If the results match the intended range, register the same query in Analysis > Scheduled Queries.
  2. Match the duration value to the run interval. If the query runs every hour, specify duration=1h so that the ranges neither overlap nor leave gaps.

Check the results:

usercount
hong@example.com128
user@example.com74
  • The number of messages per user is returned.
  • If a count equals the value of the limit option, the results may have been cut off at the limit. Raise the limit or split the period and run again.

Troubleshooting:

SymptomCauseSolution
Some records have an _error fieldThe user value of the incoming record is empty or in the wrong format, or the query for that user failed (a user not in the tenant, a wrong client secret, and so on)Check the cause shown in the _error value, and clean up the user field or filter out empty values in the preceding query
Specify only one connect profileSeveral identifiers separated by commas were specified in the profile optionSpecify only one connect profile
The run takes too longThe number of target users or the query period is too largeReduce the duration, or narrow down the target users in the preceding query

Notes

  • Querying and sending use different connect profiles: sending to a channel uses the Microsoft Teams Workflows type, and querying users and chats uses the Microsoft Teams Graph API type. Specify the right profile identifier for each command.
  • Only the last day is queried if no period is given: Microsoft requires both ends of the query range, so the command fills in the end you leave out. The end defaults to the current time, and the start to one day before the end.
  • Chats are queried: one-on-one and group conversations are queried, and messages posted to team channels are not.
  • The same message can appear more than once: when you query each user who took part in the same conversation, the same message is returned for each user. Deduplicate by msg_id before aggregating.
  • Client secrets expire: once a secret expires, all query commands fail. Issue a new one before it expires and update the connect profile.
  • Mind the permissions: querying chat messages means reading the conversations of members of the organization. Manage the query permission and the purpose of use according to internal policy, and keep the sharing scope of the connect profile to a minimum.
Caution
Chat message queries handle conversations that can contain personal information. Check the privacy policy of your organization before loading the results into a separate table or sending them outside.

Related Documents