Microsoft Graph 提供了一组全面的Microsoft Teams API,使你能够对 Teams 消息执行作。 本文介绍主要 Teams API 架构元素,并概述基于高级方案要使用的 API。 有关 Microsoft Graph 中的 Teams API 的详细信息,请参阅使用Microsoft图形 API使用 Teams。
chatMessage 架构
chatMessage 资源类型表示 Teams 聊天和频道中的消息。 本部分介绍 chatMessage 架构的 元素。
注意: 本部分中的示例仅显示相关的架构元素,而不是整个消息有效负载。
attachments
chatMessageAttachment 资源类型表示可从 chatMessage 引用的实体。 这些实体包括文件、选项卡、卡片、会议或其他消息。 项目本身可能位于其他位置。 例如,文件可能存储在 SharePoint 中。 以下部分介绍 chatMessage 对象上附件的可能类型。
卡附件
卡片表示预定义架构支持的视觉元素。 除了以下卡类型外,Teams 还支持 Bot Framework 定义的卡片:
- 代码片段或位置持有者 - 将 contentType 设置为
application/vnd.microsoft.card.codesnippet
- 公告卡 - 将 contentType 设置为
application/vnd.microsoft.card.announcement
- Microsoft Loop组件卡 - 将 contentType 设置为
application/vnd.microsoft.card.fluidEmbedCard
对于卡片,contentType 属性设置为卡的类型,内容属性包含卡的序列化 json。
注意: 卡片的各个方面(例如图像)可能将 Teams 托管的外部资源或资源称为 chatMessageHostedContent。
以下示例显示了自适应卡附件的架构。 此卡包含由 Teams 托管的映像。
"attachments": [
{
"id": "74d20c7f34aa4a7fb74e2b30004247c5",
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": null,
"content": "{ \"type\": \"AdaptiveCard\", \"body\": [ { \"items\": [ { \"columns\": [ { \"width\": \"auto\", \"items\": [ { \"size\": \"medium\", \"url\": \"https://graph.microsoft.com/beta/teams/68a3e365-f7d9-4a56-b499-24332a9cc572/channels/19:0b50940236084d258c97b21bd01917b0@thread.skype/messages/1596694346004/hostedContents/aWQ9LHR5cGU9MSx1cmw9aHR0cHM6Ly91cy1hcGkuYXNtLnNreXBlLmNvbS92MS9vYmplY3RzLzAtd3VzLWQyLTUxZDYxNGE5MDQ5ZTU4MjFlMTRmMGI2NmExNmVlNzhlL3ZpZXdzL2ltZ28=/$value\", \"height\": \"auto\", \"type\": \"Image\" }, { \"horizontalAlignment\": \"center\", \"text\": \"SHADES\", \"weight\": \"bolder\", \"type\": \"TextBlock\" } ], \"type\": \"Column\" }, { \"width\": \"stretch\", \"items\": [ { \"horizontalAlignment\": \"center\", \"text\": \"08/31/2019 19:30:00\", \"type\": \"TextBlock\" }, { \"horizontalAlignment\": \"center\", \"text\": \"Final\", \"spacing\": \"None\", \"type\": \"TextBlock\" }, { \"horizontalAlignment\": \"center\", \"size\": \"extraLarge\", \"text\": \"40 - 7\", \"type\": \"TextBlock\" } ], \"spacing\": \"Medium\", \"separator\": true, \"type\": \"Column\" }, { \"width\": \"auto\", \"items\": [ { \"horizontalAlignment\": \"center\", \"size\": \"medium\", \"url\": \"https://graph.microsoft.com/beta/teams/68a3e365-f7d9-4a56-b499-24332a9cc572/channels/19:0b50940236084d258c97b21bd01917b0@thread.skype/messages/1596694346004/hostedContents/aWQ9LHR5cGU9MSx1cmw9aHR0cHM6Ly91cy1hcGkuYXNtLnNreXBlLmNvbS92MS9vYmplY3RzLzAtd3VzLWQyLWM4NjgwMjMzMzcyMzc2MmQ0MWEyY2QxMGVhMWI4ZGRhL3ZpZXdzL2ltZ28=/$value\", \"height\": \"auto\", \"type\": \"Image\" }, { \"horizontalAlignment\": \"center\", \"text\": \"SKINS\", \"weight\": \"bolder\", \"type\": \"TextBlock\" } ], \"spacing\": \"Medium\", \"separator\": true, \"type\": \"Column\" } ], \"type\": \"ColumnSet\" } ], \"type\": \"Container\" } ], \"speak\": \"The Seattle Seahawks beat the Carolina Panthers 40-7\", \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\", \"version\": \"1.2\"}",
"name": null,
"thumbnailUrl": null,
"teamsAppId": null
}
]
对于由 Teams 应用创建的消息(例如通过 消息传递扩展), teamsAppId 属性包含发送消息的应用的 ID。
以下示例演示 Teams 应用发送消息时自适应卡附件的架构。
"attachments": [
{
"id": "f60e7358497741f5bdb5fa7f101fe425",
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": null,
"content": "{ \"type\": \"AdaptiveCard\", \"body\": [ { \"items\": [ { \"items\": [], \"type\": \"Container\" }, { \"altText\": \"Awesome\", \"horizontalAlignment\": \"center\", \"url\": \"https://dev.praise.myanalytics.cdn.office.net/2024.1.31.2/assets/emojis/Trophy_Icon.png\", \"width\": \"82px\", \"height\": \"auto\", \"spacing\": \"small\", \"type\": \"Image\" }, { \"size\": \"large\", \"text\": \"Awesome\", \"weight\": \"lighter\", \"wrap\": true, \"spacing\": \"large\", \"type\": \"TextBlock\" }, { \"size\": \"large\", \"text\": \"Test User 1\", \"weight\": \"bolder\", \"wrap\": true, \"spacing\": \"none\", \"type\": \"TextBlock\" }, { \"size\": \"small\", \"text\": \"From Test User 2\", \"wrap\": true, \"spacing\": \"extraLarge\", \"type\": \"TextBlock\" }, { \"items\": [], \"spacing\": \"small\", \"type\": \"Container\" } ], \"backgroundImage\": { \"url\": \"https://dev.praise.myanalytics.cdn.office.net/2024.1.31.2/assets/themes/CornflowerGradient.png\" }, \"type\": \"Container\" }, { \"columns\": [ { \"width\": \"stretch\", \"items\": [ { \"text\": \"**[Review your praise history](https://teams.microsoft.com/l/entity/57e078b5-6c0e-44a1-a83f-45f75b030d4a)**\", \"wrap\": true, \"spacing\": \"small\", \"type\": \"TextBlock\" } ], \"type\": \"Column\" }, { \"width\": \"auto\", \"items\": [ { \"horizontalAlignment\": \"right\", \"text\": \"**[Send praise](https://teams.microsoft.com/l/task/d832a33f-28c2-4969-8ad0-4fee681dc5b4)**\", \"spacing\": \"small\", \"type\": \"TextBlock\" } ], \"type\": \"Column\" } ], \"spacing\": \"small\", \"type\": \"ColumnSet\" } ], \"speak\": \"Praise card sent from Test User 2 to Test User 1. Awesome, with message \", \"version\": \"1.2\"}",
"name": null,
"thumbnailUrl": null,
"teamsAppId": "d832a33f-28c2-4969-8ad0-4fee681dc5b4"
}
]
注意: Microsoft Graph 仅支持设置了 OpenUrl 作的卡片。 不支持 ShowCard 等其他作。 Microsoft Graph 允许读取机器人发布的具有其他作的消息。
以下示例将 Loop 组件的架构显示为两个附件。
"attachments": [
{
"id": "b21e256a-8581-45cf-ae05-8bb998360bcc",
"contentType": "application/vnd.microsoft.card.fluidEmbedCard",
"contentUrl": null,
"content": "{\r\n \"componentUrl\": \"https://teamsgraph-my.sharepoint.com/:fl:/g/personal/sumanac_teamsgraph_onmicrosoft_com/EQnofOQM0MpOoDaRIvw-pS8Bfsj_WDFuanBBXnjDAD-w3g?nav=cz0lMkZwZXJzb25hbCUyRnN1bWFuYWNfdGVhbXNncmFwaF9vbm1pY3Jvc29mdF9jb20mZD1iIWVUcmxYX19jN2t5eW9GSFhJdG8yTDI4bmtnV2EtOXhEa244SVBOdGZFYnlxandPblkwdE9TcFVldkh6dWtBV1ImZj0wMUU2TzQ0WFlKNUI2T0lER1FaSkhLQU5VUkVMNkQ1SkpQJmM9JTJGJmZsdWlkPTEmYT1UZWFtcyZwPSU0MGZsdWlkeCUyRmxvb3AtcGFnZS1jb250YWluZXI%3D\",\r\n \"sourceType\": \"Compose\"\r\n}",
"name": null,
"thumbnailUrl": null,
"teamsAppId": "FluidEmbedCard"
},
{
"id": "placeholderCard",
"contentType": "application/vnd.microsoft.card.codesnippet",
"contentUrl": null,
"content": "{}",
"name": null,
"thumbnailUrl": null,
"teamsAppId": "FLUID_PLACEHOLDER_CARD"
}
],
文件附件
当 附件 对象引用文件时,它包含有关该文件的信息,包括用于打开该文件的链接。 文件本身位于 SharePoint 等可访问的存储区中。 当 chatMessage 具有文件类型的附件时,附件资源上的 contentType 属性的值设置为 reference
,contentUrl 属性包含文件 URL。
注意: SharePoint URL 是打开文件的链接;它不是Microsoft图形 URL。 但是,调用方可以使用 访问共享项 API 获取有关文件内容的信息。
以下示例显示了文件附件的架构。
"attachments": [
{
"id": "924D1F74-E0D2-4927-8A67-15ECEF455527",
"contentType": "reference",
"contentUrl": "https://testing.sharepoint.com/sites/Samples/Shared Documents/General/color.png",
"content": null,
"name": "color.png",
"thumbnailUrl": null,
"teamsAppId": null
}
],
转发的邮件附件
附件对象包含转发到聊天的转发邮件。 对于邮件附件, id 属性包含转发的邮件的 ID。
content 属性包含有关消息的更多详细信息;例如,原始邮件上下文和原始发件人详细信息。 对于邮件附件, contentType 属性设置为 forwardedMessageReference
。
以下示例显示了转发的邮件附件的架构。
"attachments": [
{
"id": "1727881360458",
"contentType": "forwardedMessageReference",
"contentUrl": null,
"content": "{\"originalMessageId\":\"1727881360458\",\"originalMessageContent\":\"\\n<p>hello</p>\\n\",\"originalConversationId\":\"19:97641583cf154265a237da28ebbde27a@thread.v2\",\"originalSentDateTime\":\"2024-10-02T15:02:40.458+00:00\",\"originalMessageSender\":{\"application\":null,\"device\":null,\"user\":{\"userIdentityType\":\"aadUser\",\"tenantId\":\"2432b57b-0abd-43db-aa7b-16eadd115d34\",\"id\":\"28c10244-4bad-4fda-993c-f332faef94f0\",\"displayName\":null}}}",
"name": null,
"thumbnailUrl": null,
"teamsAppId": null
}
],
会议附件
在频道中安排会议时,频道中会发布包含会议详细信息的消息。 会议附件表示此对象,并包含会议详细信息。
id 属性包含会议的 ID,content 属性包含有关会议组织者和会议的 Exchange ID 的详细信息。 可以使用 Exchange ID 通过日历 API 查找会议。 对于会议附件, contentType 属性设置为 meetingReference
。
以下示例显示了自适应卡附件的架构。
"attachments": [
{
"id": "1628156567881",
"contentType": "meetingReference",
"contentUrl": null,
"content": "{\"exchangeId\":\"AAMkAGU2NzgzNDQ3LWFkMTctNGY2MC05ZjM1LWFkOTYxZWZhYTY2MgBGAAAAAADFwPNVvpzXRqmCO5F6qAKtBwB89fWKTP8MSaPLNsJWtozvAAAAAAENAAB89fWKTP8MSaPLNsJWtozvAAFg-8IoAAA=\",\"organizerId\":\"8ea0e38b-efb3-4757-924a-5f94061cf8c2\"}",
"name": "Testing channel meeting",
"thumbnailUrl": null
}
],
邮件附件
当聊天包含对特定邮件的回复时,附件对象包含一条消息。 对于邮件附件, id 属性包含邮件的 ID。
content 属性包含有关消息的更多详细信息;例如,邮件预览文本和发件人。 对于邮件附件, contentType 属性设置为 messageReference
。
以下示例显示了邮件附件的架构。
"attachments": [
{
"id": "1622853091207",
"contentType": "messageReference",
"contentUrl": null,
"content": "{\"messageId\":\"1622853091207\",\"messagePreview\":\"Testing unread read status\",\"messageSender\":{\"application\":null,\"device\":null,\"user\":{\"userIdentityType\":\"aadUser\",\"id\":\"8ea0e38b-efb3-4757-924a-5f94061cf8c2\",\"displayName\":\"Alex\"}}}",
"name": null,
"thumbnailUrl": null
}
],
选项卡附件
当 附件 对象引用当前上下文中托管的 选项卡 时, contentType 属性设置为 tabReference
, id 属性设置为选项卡的 ID,而 name 属性设置为选项卡名称。 新添加选项卡时,此方案通常适用。
以下示例显示了选项卡附件的架构。
"attachments": [
{
"id": "tab::d64ea8d0-8b63-4f53-9bf6-806648176968",
"contentType": "tabReference",
"contentUrl": null,
"content": null,
"name": "Bing",
"thumbnailUrl": null,
"teamsAppId": null
}
],
body
chatMessage 对象的 body 属性表示消息的正文。
body 属性可以引用架构中的其他元素,例如提及或附件。 内容可以是 text
或 html
,由 itemBody 资源类型的 contentType 属性指定。
chatMessage 架构支持 Teams 还支持的以下非 HTML 元素:
- at - 对 chatMessageMention 的引用,该引用代表用户、应用程序、 频道、 团队或 标记 的详细信息,即 @mentioned。
- attachment - 表示附件引用的位置。
- systemEventMessage - 当 itemBody 资源的内容属性设置为
<systemEventMessage/>
时,消息表示特殊事件。 有关详细信息,请参阅 获取系统消息。 - 表情符号 - 当邮件正文包含表情符号时,
$"<emoji id="IdOfTheEmoji" alt="AlternateRepresentationOfEmoji" title="TitleOfEmoji"></emoji>"
元素表示 表情符号的属性:- id - 表情符号的 ID。
- alt - 表情符号的备用表示形式;例如 Unicode。
- title - 表情符号的标题。
- customemoji - 当邮件正文包含自定义表情符号时
$"<customemoji id="IdOfTheCustomEmoji" alt="AlternateRepresentationOfCustomEmoji" source="HostedContentOfCustomEmoji"></customemoji>"
,元素表示 customemoji 的属性:- id - 自定义表情符号的 ID。
- alt - 自定义表情符号的备用表示形式;例如,自定义表情符号的名称。
- source - 与邮件关联的自定义表情符号的托管内容。
- codeblock - 当消息正文包含代码块时,
"<codeblock class=\"Json\"><code>Hello world</code></codeblock>"
元素表示代码块的属性。
示例:团队的消息@mentions
"body": {
"contentType": "html",
"content": "<div><div><at id=\"0\">WebhookTesting</at> Hello team</div></div>"
},
"mentions": [
{
"id": 0,
"mentionText": "WebhookTesting",
"mentioned": {
"application": null,
"device": null,
"user": null,
"tag": null,
"conversation": {
"id": "68a3e365-f7d9-4a56-b499-24332a9cc572",
"displayName": "WebhookTesting",
"conversationIdentityType": "team"
}
}
}
],
示例:带有附件的邮件
"body": {
"contentType": "html",
"content": "Scheduled a meeting<attachment id=\"1628156567881\"></attachment>"
},
"attachments": [
{
"id": "1628156567881",
"contentType": "meetingReference",
"contentUrl": null,
"content": "{\"exchangeId\":\"AAMkAGU2NzgzNDQ3LWFkMTctNGY2MC05ZjM1LWFkOTYxZWZhYTY2MgBGAAAAAADFwPNVvpzXRqmCO5F6qAKtBwB89fWKTP8MSaPLNsJWtozvAAAAAAENAAB89fWKTP8MSaPLNsJWtozvAAFg-8IoAAA=\",\"organizerId\":\"8ea0e38b-efb3-4757-924a-5f94061cf8c2\"}",
"name": "Testing channel meeting",
"thumbnailUrl": null
}
],
示例:包含系统事件的消息
"body": {
"contentType": "html",
"content": "<systemEventMessage/>"
},
"channelIdentity": {
"teamId": "68a3e365-f7d9-4a56-b499-24332a9cc572",
"channelId": "19:0b50940236084d258c97b21bd01917b0@thread.skype"
},
"attachments": [],
"mentions": [],
"reactions": [],
"eventDetail": {
"@odata.type": "#microsoft.graph.conversationMemberRoleUpdatedEventMessageDetail",
"conversationMemberRoles": [],
"conversationMemberUser": {
"id": "c4aefc8e-f890-4aa6-b586-6cce899ff7f8",
"displayName": null,
"userIdentityType": "aadUser"
},
"initiator": {
"application": null,
"device": null,
"user": {
"id": "8ea0e38b-efb3-4757-924a-5f94061cf8c2",
"displayName": null,
"userIdentityType": "aadUser"
}
}
}
示例:带有表情符号的邮件
{
"body": {
"contentType": "html",
"content": "<p><emoji id=\"smile\" alt=\"🙂\" title=\"Smile\"></emoji></p>"
}
}
示例:带有自定义表情符号的邮件
{
"body": {
"contentType": "html",
"content": "<p><customemoji id=\"dGVzdHNjOzAtd3VzLWQyLTdiNWRkZGQ2ZGVjMDNkYzIwNTgxY2NkYTE1MmEyZTM4\" alt=\"testsc\" source=\"https://graph.microsoft.com/beta/chats/19:bcf84b15c2994a909770f7d05bc4fe16@thread.v2/messages/1706638496169/hostedContents/aWQ9LHR5cGU9MSx1cmw9aHR0cHM6Ly91cy1jYW5hcnkuYXN5bmNndy50ZWFtcy5taWNyb3NvZnQuY29tL3YxL29iamVjdHMvMC13dXMtZDItN2I1ZGRkZDZkZWMwM2RjMjA1ODFjY2RhMTUyYTJlMzgvdmlld3MvaW1ndDJfYW5pbQ==/$value\"></customemoji></p>"
}
}
示例:包含代码块的消息
注意:使用Microsoft图形 API发送带有代码块的消息时,不支持突出显示的代码块。
{
"body": {
"contentType": "html",
"content": "\n<codeblock class=\"\"><code>Hello world</code></codeblock>"
}
}
示例:包含具有特定于语言的突出显示的代码块的消息
{
"body": {
"contentType": "html",
"content": "<p> </p>\n\n<codeblock class=\"Json\"><code>{<br> <span class=\"hljs-function\">\"body\"</span>: {<br> <span class=\"hljs-function\">\"contentType\"</span>: <span class=\"hljs-string\">\"html\"</span>,<br> <span class=\"hljs-function\">\"content\"</span>: <span class=\"hljs-string\">\"<codeblock><code>Hello world</code></codeblock>\"</span><br> }<br>}</code></codeblock>\n<p> </p>"
}
}
channelIdentity
如果在频道中发送 chatMessage,则 channelIdentity 属性包含有关该通道的详细信息。 这包括 频道 和 团队的 ID。 此属性是只读的。
以下示例显示了消息中 channelIdentity 的 架构。
"channelIdentity": {
"teamId": "68a3e365-f7d9-4a56-b499-24332a9cc572",
"channelId": "19:0b50940236084d258c97b21bd01917b0@thread.skype"
},
chatId
如果在聊天中发送 chatMessage,则 chatId 属性包含聊天的 ID。 此属性是只读的。
以下示例显示了 chatId 的架构。
"chatId": "19:8ea0e38b-efb3-4757-924a-5f94061cf8c2_976f4b31-fd01-4e0b-9178-29cc40c14438@unq.gbl.spaces",
createdDateTime
createdDateTime 属性表示在服务器上创建消息的时间。 此时间戳可能与调用方发送消息的时间不同。 服务器仅记录服务器端时间戳。 此属性为只读;但是, 当从外部系统导入消息时,可以编写它。
deletedDateTime
如果删除 chatMessage ,则 deletedDateTime 属性包含删除消息的时间。 此属性是只读的。
注意: 删除的消息并不总是由所有 API 返回。 如果订阅的 changeType 包含
deleted
,则更改通知始终返回已删除的消息通知。
etag
etag 属性表示消息的版本。 对消息的任何更改 (包括反应和编辑) 更改消息的 etag 值。 此属性是只读的。
eventDetail
如果存在, eventDetails 属性表示 聊天、 频道或 团队中发生的事件的详细信息;例如,添加新成员。 对于事件消息,chatMessage 的 messageType 属性设置为 systemEventMessage
。 有关详细信息,请参阅 获取系统消息。
起始数量
from 属性表示消息的发件人。 Microsoft Teams 支持以下发件人类型。
Entra ID 用户 - 具有有效 Entra ID 的用户。 这包括 Entra 外部 ID 来宾和外部访问用户。
以下示例显示 Entra ID 用户发送的消息的 from 属性。
"from": { "application": null, "device": null, "user": { "id": "8ea0e38b-efb3-4757-924a-5f94061cf8c2", "displayName": "Alex Wilber", "userIdentityType": "aadUser" } },
匿名来宾 - 使用加入链接加入会议的用户。 这些用户在加入会议时提供显示名称。 它们在 Microsoft 365 中没有永久标识。
以下示例显示了匿名来宾发送的消息的 from 属性。
"from": { "application": null, "device": null, "user": { "id": "8578568e393e4ffe8763e0b7c3da01fe", "displayName": "Anon (Guest)", "userIdentityType": "anonymousGuest" } },
个人Microsoft帐户用户 - 使用个人Microsoft帐户登录 Teams 的用户。
以下示例显示了匿名来宾发送的消息的 from 属性。
"from": { "application": null, "device": null, "user": { "id": "d78f5bc88c39f6b8", "displayName": "TFL 1017", "userIdentityType": "personalMicrosoftAccountUser" } },
Skype 用户 - 面向使用者) 用户的 Skype (。 有关详细信息,请参阅 Teams 和 Skype 互作性。
以下示例显示 Skype 用户发送的消息的 from 属性。
"from": { "application": null, "device": null, "user": { "id": "alex1122", "displayName": "Alex", "userIdentityType": "skypeUser" } },
Skype for Business 本地用户 - 使用 Skype For Business 本地产品/服务的用户。 有关详细信息,请参阅 Teams 和 Skype for Business共存和互作性。
以下示例显示了由 Skype for business 本地用户发送的消息的 from 属性。
"from": { "application": null, "device": null, "user": { "id": "b0eddfe2-659b-437d-b289-cf55c8b3bb1d", "displayName": "Alex", "userIdentityType": "onPremiseAadUser" } },
机器人 - 通过Microsoft Bot Framework创建的聊天机器人。
以下示例显示了机器人发送的消息的 from 属性。
"from": { "device": null, "user": null, "application": { "id": "358f0194-6b0e-4dd3-af35-c24fe8a9ec87", "displayName": "Flow", "applicationIdentityType": "bot" } }
传出 Webhook - 传出 Webhook 允许开发人员构建类似于机器人的低成本解决方案。 有关详细信息,请参阅 创建传出 Webhook。
以下示例显示了机器人发送的消息的 from 属性。
"from": { "device": null, "user": null, "application": { "id": "22e50a9b-80cc-4eab-a092-ce64796d28d7", "displayName": "Custom bot", "applicationIdentityType": "outgoingWebhook" } }
Microsoft 365 个组的连接器 - 连接器允许将单向邮件发布到 Teams。 有关详细信息,请参阅为Microsoft 365 组创建连接器。
以下示例显示来自Office 365连接器的消息的 from 属性。
"from": { "device": null, "user": null, "application": { "id": "4c6cfc6e-cf78-44e8-87fd-bbb0efcad6a2", "displayName": "Bing News", "applicationIdentityType": "office365Connector" } }
Email - Teams 允许将电子邮件发送到频道。 当用户未知时,发件人的标识将显示为电子邮件用户,其中包含用于发送邮件的电子邮件的详细信息。
以下示例显示了从电子邮件用户发送的邮件 的 from 属性 。
"from": { "application": null, "device": null, "user": { "@odata.type": "#microsoft.graph.teamworkUserIdentity", "id": "testemailuser@outlook.com", "displayName": "Test User", "userIdentityType": "emailUser" } }
Azure 通信服务用户 - 如果消息由Azure 通信服务用户发送,发件人的标识详细信息将用发件人字段表示。
以下示例显示从Azure 通信服务用户发送电子邮件的 from 属性。
"from": { "application": null, "device": null, "user": { "@odata.type": "#microsoft.graph.teamworkUserIdentity", "id": "8:acs:a04d09ad-aaa9-4e25-90de-475594b0fb52_00000006-96d3-711c-6a0b-343a0d000eb4", "displayName": null, "userIdentityType": "azureCommunicationServicesUser" } }
此属性为只读;但是,在 从外部系统导入消息时,可以写入它。
注意: 显示名称并不总是存在。
id
id 属性包含表示消息的唯一 ID。 此属性是只读的。
注意: ID 仅在特定范围(如聊天或频道)内是唯一的。 聊天和频道中的不同消息可能具有相同的 ID。
importance
importance 属性表示消息的重要性。 以下是可能的值:
- 正常
- 高
- 紧急
以下示例显示了一条消息,其重要性设置为“高”。
"importance": "high",
lastEditedDateTime
lastEditedDateTime 属性表示用户编辑消息时的时间戳。 这在 Teams UI Edited
中使用 标志表示。 如果从未编辑过消息,则将其设置为 null
。
lastModifiedDateTime
lastModifiedDateTime 属性表示上次修改消息时的时间戳。 这包括反应等更改。 修改消息时 ,eTag 和 lastModifiedDateTime 属性。
提及
提及属性表示用户、应用程序 (机器人、webhook) 、频道、团队或标记@mentioned。
示例:其他用户的消息@mentions
"body": {
"contentType": "html",
"content": "<div><div><div><div><at id=\"0\">Alex</at> Test123</div></div></div></div>"
},
"mentions": [
{
"id": 0,
"mentionText": "Alex",
"mentioned": {
"application": null,
"device": null,
"conversation": null,
"tag": null,
"user": {
"id": "c27c1b19-3904-4822-9813-4f6bdaab2eae",
"displayName": "Alex",
"userIdentityType": "aadUser"
}
}
}
],
示例:机器人的消息@mentions
"body": {
"contentType": "html",
"content": "<div><div><at id=\"0\">Power Automate</at> Learn more </div></div>"
},
"mentions": [
{
"id": 0,
"mentionText": "Power Automate",
"mentioned": {
"device": null,
"user": null,
"conversation": null,
"tag": null,
"application": {
"id": "358f0194-6b0e-4dd3-af35-c24fe8a9ec87",
"displayName": "Power Automate",
"applicationIdentityType": "bot"
}
}
}
],
示例:团队的消息@mentions
"body": {
"contentType": "html",
"content": "<div><div><at id=\"0\">WebhookTesting</at> Hello team</div></div>"
},
"mentions": [
{
"id": 0,
"mentionText": "WebhookTesting",
"mentioned": {
"application": null,
"device": null,
"user": null,
"tag": null,
"conversation": {
"id": "68a3e365-f7d9-4a56-b499-24332a9cc572",
"displayName": "WebhookTesting",
"conversationIdentityType": "team"
}
}
}
],
注意:@mentions 也可以显示在卡片内。
messageType
messageType 属性表示消息的类型。 以下是可能的值:
- message - 表示用户和应用程序发送的消息。
- systemEventMessage - 表示 Teams 发送的消息,其中包含有关添加成员或删除频道等各种事件的详细信息。 有关详细信息,请参阅 获取系统消息。
以下值当前未使用:
- 打字
- chatEvent
onBehalfOf
onBehalfOf 属性表示机器人代表用户发送的消息的用户属性。 有关详细信息,请参阅 机器人消息的用户属性。
以下示例显示机器人代表用户发送的消息。
"from": {
"device": null,
"user": null,
"application": {
"id": "8a34cb8d-65dc-44e2-8375-a2261d1f2a4b",
"displayName": "PolicyMaker",
"applicationIdentityType": "bot"
}
},
"onBehalfOf": {
"application": null,
"device": null,
"user": {
"id": "8ea0e38b-efb3-4757-924a-5f94061cf8c2",
"displayName": "Alex Wilber",
"userIdentityType": "aadUser"
}
},
policyViolation
如果消息违反租户设置的任何数据丢失防护 (DLP) 策略,则可以使用违反的策略的详细信息调用消息 PATCH。 这会在 Teams UI 中隐藏消息。 policyViolation 属性表示已违反的策略的详细信息以及作。
以下示例显示了由于策略而被阻止的消息。
"body": {
"contentType": "text",
"content": ""
},
"policyViolation": {
"dlpAction": "blockAccess",
"justificationText": null,
"userAction": "none",
"verdictDetails": "none",
"policyTip": null
},
反应
reactions 属性表示其他用户对消息的反应,例如赞。 每个元素都表示有关反应和做出反应的用户的信息。
以下示例显示了一条包含反应的消息。
注意: 显示名称并不总是出现在 用户 属性中。
{
"reactions": [
{
"reactionType": "💯",
"displayName": "Hundred points",
"createdDateTime": "2022-01-18T23:41:57.573Z",
"user": {
"application": null,
"device": null,
"user": {
"id": "8ea0e38b-efb3-4757-924a-5f94061cf8c2",
"displayName": null,
"userIdentityType": "aadUser"
}
}
}
]
}
以下示例显示具有自定义反应的消息。
注意:
- 自定义反应仅在终结点上
/beta
可用。- 用户的显示名称并非始终存在。
{
"reactions": [
{
"reactionType": "custom",
"displayName": "microsoft_teams",
"reactionContentUrl": "https://graph.microsoft.com/beta/chats/19:bcf84b15c2994a909770f7d05bc4fe16@thread.v2/messages/1706763669648/hostedContents/aWQ9MC13dXMtZDExLTc3ZmI2NmY4MTMwMGI2OGEzYzRkOWUyNmU1YTc5ZmMyLHR5cGU9MSx1cmw9/$value",
"createdDateTime": "2024-02-14T22:07:02.288Z",
"user": {
"application": null,
"device": null,
"user": {
"@odata.type": "#microsoft.graph.teamworkUserIdentity",
"id": "28c10244-4bad-4fda-993c-f332faef94f0",
"displayName": null,
"userIdentityType": "aadUser"
}
}
}
]
}
replyToId
replyToId 属性表示邮件是答复链中答复的邮件的 ID。 此属性仅为通道消息设置。 此属性是只读的。
注意: 若要回复聊天中的消息,请使用消息引用。
subject
subject 属性包含邮件的主题。 这仅适用于在通道中发送的消息。
webUrl
webUrl 属性包含指向 Teams UI 中的消息的 URL。 此 URL 直接在浏览器中的 Teams UI 中打开消息。
为方案选择正确的 API
选择正确的 API 对于构建最佳体验至关重要。 使用正确的 API 集还可以确保在不达到限制的情况下提取数据。
Microsoft Graph 中的消息传递 API 分为三种:
- 映射到 Teams UI 的 API。 任何更改都会立即可见。
- 导出侧重于用户和团队的数据的 API。 任何更改最长可能需要 24 小时才能可用。
- 更改基于通知的 API 以实时获取通知。
与 Teams UI 一致的 API
与 Teams UI 保持一致的 API 的工作方式与 Teams UI 的工作方式类似。 这些 API 是针对一 次 同步构建的,用于获取特定上下文中的消息。 这些 API 具有很高的性能,) 发送、编辑或删除的消息 (更改都会立即可见。
以下是与 Teams UI 一致的 API:
- 列出聊天中的消息
- 列出频道中的消息
- 列出频道中邮件的答复
- 在聊天中发送消息
- 在频道中发送消息
- 在渠道中回复消息
- 列出与消息关联的 hostedContents
- 获取与消息关联的 hostedContent
此外,以下 API 与这些 API 一起为特定方案提供服务,例如提取特定实例或更改遍历顺序。
用于从 Teams 导出数据的 API
导出数据的 API 通常以比 UI 对齐的 API 更高的粒度工作。 这些 API 侧重于允许提取大量数据。 在某些情况下,可能需要一段时间 (长达 24 小时,) 数据才能通过这些 API 进行同步和获取。
以下 API 属于此类别:
实时 API
实时 API 允许调用方在) 发送、编辑、删除消息等 (进行更改后立即收到通知。 这些 API 适用于实时应用程序,例如在 Teams UI 外部呈现消息。 此外,这些 API 允许创建订阅,从而接收大量数据,而不会达到限制。 有关详细信息,请参阅 更改口号和聊天通知。