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
| Term | Meaning | Related resource |
|---|---|---|
| Workflow webhook | A URL issued to post messages to a Teams channel. The target channel is already fixed in the URL | Install Guide |
| Microsoft Teams Graph API connect profile | A query-only connect profile that stores the tenant ID, client ID, and client secret. Separate from the profile for sending messages | Install 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.com | ms-teams-users |
| User object ID | A 36-character identifier that Microsoft Entra assigns to a user. Can be used instead of the UPN | ms-teams-users |
| Chat | One-on-one and group conversations. Messages posted to team channels are not queried | ms-teams-chat-messages |
| System event message | A message not typed by a person, such as adding or removing a member. Excluded from query results by default | ms-teams-chat-messages |
| Connect profile | A 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
| Feature | Path |
|---|---|
| App management | Apps |
| Connect profiles | System > Connect Profile |
| Run query commands | Analysis > Queries |
| Register periodic runs | Analysis > 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:
- A connect profile of the Microsoft Teams Graph API type must be registered. 2. Register a Microsoft Entra App and 3. Configure Connect Profiles of the install guide must be completed.
- Admin consent must be granted for the application permissions Chat.Read.All and User.Read.All.
Procedure:
- Go to Analysis > Queries.
- Check the account of the target user.
- 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.
| _time | from_user_name | msg | chat_id |
|---|---|---|---|
| 2026-09-10 14:02:11 | Gildong Hong | Sharing the meeting notes | 19:abc123@thread.v2 |
| 2026-09-10 13:58:40 | Gildong Hong | Got it | 19: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:
| Symptom | Cause | Solution |
|---|---|---|
| No results | There was no conversation during the period, or the period is too short | Increase 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 ID | A value in the wrong format, such as a display name or mail alias, was specified | Check 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 identifier | Enter the identifier of the connect profile, not its name |
| An error starting with cannot issue Microsoft Graph access token: invalid_client, AADSTS7000215 | The client secret value is wrong, including when the secret ID was entered | Enter 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 granted | Perform 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 id | The user specified in the user option does not exist in the tenant | Check 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:
- 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
- If the results match the intended range, register the same query in Analysis > Scheduled Queries.
- 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:
| user | count |
|---|---|
| hong@example.com | 128 |
| user@example.com | 74 |
- 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:
| Symptom | Cause | Solution |
|---|---|---|
| Some records have an _error field | The 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 profile | Several identifiers separated by commas were specified in the profile option | Specify only one connect profile |
| The run takes too long | The number of target users or the query period is too large | Reduce 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.
Related Documents
- Install Guide — issuing a workflow webhook, registering a Microsoft Entra app, and configuring connect profiles
- ms-teams-users — query the tenant user list
- ms-teams-chat-messages — query chat messages
- ms-teams-chat-messages-batch — query chat messages in batch
- ms-teams-send — send messages to a channel
- ms-teams-send-batch — send messages to a channel in batch