ChannelMessages
Returns messages and replies exchanged within a Microsoft Teams channel.
View-Specific Information
SELECT
The connector uses the Microsoft Teams API to process WHERE clause conditions built with the columns and operator shown below. The rest of the filter is executed client-side within the connector.
- TeamId supports the = operator.
- ChannelId supports the = operator.
- Id supports the = operator.
Note: For best performance, specify both TeamId and ChannelId in the WHERE clause.
Example Queries
To retrieve all channel messages:
SELECT * FROM ChannelMessages
To retrieve all messages from a specific team:
SELECT * FROM ChannelMessages WHERE TeamId = '4729c5e5-f923-4435-8a41-44423d42ea79'
To retrieve messages from a specific channel within a team:
SELECT * FROM ChannelMessages WHERE TeamId = '4729c5e5-f923-4435-8a41-44423d42ea79' AND ChannelId = '19:[email protected]'
To retrieve a specific message:
SELECT * FROM ChannelMessages WHERE TeamId = '4729c5e5-f923-4435-8a41-44423d42ea79' AND ChannelId = '19:[email protected]' AND Id = '1688061957561'
Keyword Search
The Microsoft Teams API does not support filtering channel messages by body content in a WHERE clause. To search for messages containing a keyword, use the SearchMessages stored procedure, which routes the request through the Microsoft Teams Search API and returns results across both ChannelMessages and ChatMessages.
The following example searches for all messages containing the keyword "Asteria":
EXEC SearchMessages Keyword = 'Asteria'
Each result includes a TableName column indicating whether the full message record can be retrieved from ChannelMessages or ChatMessages, along with the Id, TeamId, and ChannelId values needed to perform that lookup.
Columns
| Name | Type | Description |
| Id [KEY] | String | Unique identifier for the channel message in Microsoft Teams. |
| BodyContent | String | Plaintext or rich text content of the message body. |
| BodyContentType | String | Specifies the format of the message body content, such as text or HTML. |
| ChannelId | String | Identifier of the Microsoft Teams channel where the message was posted. |
| TeamId | String | Identifier of the team associated with the channel. |
| Mentions | String | List of entities mentioned in the message. Supported entities include user, bot, team, and channel. |
| Reactions | String | List of reactions applied to the channel message, such as like or heart. |
| Attachments | String | References to objects attached to the message, such as files, tabs, or meetings. |
| Importance | String | Priority level of the message, such as normal, high, or urgent. |
| CreatedDateTime | Datetime | Timestamp indicating when the message was created. |
| LastEditedDateTime | Datetime | Timestamp indicating when the message was last edited. |
| LastModifiedDateTime | Datetime | Timestamp indicating when the message was last updated. |
| DeletedDateTime | Datetime | Timestamp indicating when the message was deleted, or null if it has not been deleted. |
| MessageType | String | Type of message, such as standard or system notification. |
| ChatId | String | Identifier of the chat thread when the message is part of a threaded conversation. |
| Etag | String | Version identifier for the message used for concurrency control. |
| FromUserDisplayName | String | Display name of the user who sent the message. |
| FromUserId | String | Unique identifier of the user who sent the message. |
| FromUserUserIdentityType | String | Specifies the identity type of the user who sent the message. |
| FromApplication | String | Name of the application that sent the message, if applicable. |
| FromDevice | String | Name of the device used to send the message, if available. |
| Locale | String | Locale setting of the message as defined by the client application, typically en-us. |
| PolicyViolation | String | Details about any policy violations associated with the message. |
| ReplyToId | String | Identifier of the parent message when the current message is part of a reply thread. |
| Subject | String | Subject line of the message in plaintext, if provided. |
| Summary | String | Summary text of the message for use in notifications, previews, or fallback views. Applies only to channel messages. |
| WebUrl | String | Direct link to view the message in Microsoft Teams. |
| EventDetail | String | Details about the event associated with the message, if applicable. |