microsoft-teams
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDrive Microsoft Teams chats via Microsoft Graph with . The user's
OAuth bearer token is in ; every call needs
. Base URL:
.
curl + jq$MICROSOFT_TEAMS_TOKENAuthorization: Bearer $MICROSOFT_TEAMS_TOKENhttps://graph.microsoft.com/v1.0Failures are — show verbatim. =
re-install. / on send = the user granted read-only
() → re-connect with + .
{"error":{"code","message"}}message401403ForbiddenChat.ReadChat.ReadWriteChatMessage.Send403 "No authorization information present on the request"/me/chats/me/chatsChat.*bash
G="https://graph.microsoft.com/v1.0"; AUTH="Authorization: Bearer $MICROSOFT_TEAMS_TOKEN"通过借助Microsoft Graph驱动Microsoft Teams聊天。用户的
OAuth承载令牌存储在中;每次调用都需要
。基础URL:
。
curl + jq$MICROSOFT_TEAMS_TOKENAuthorization: Bearer $MICROSOFT_TEAMS_TOKENhttps://graph.microsoft.com/v1.0失败返回格式为——直接显示内容。错误
表示需要重新安装。发送时出现/错误,说明用户仅授予了只读权限
() → 需要重新连接并申请 + 权限。
{"error":{"code","message"}}message401403ForbiddenChat.ReadChat.ReadWriteChatMessage.Send调用时出现错误,说明关联的账户是个人Microsoft账户**。Teams聊天是工作/学校(组织)功能——Microsoft Graph不会为个人MSA账户(outlook.com/hotmail等)开放接口或授予权限范围。直接告知用户:"Microsoft Teams聊天需要使用工作或学校账户;你当前关联的是个人Microsoft账户。请重新连接Teams并选择工作/学校账户。"不要重试——该账户无法成功调用相关接口。
/me/chats403 "No authorization information present on the request"/me/chatsChat.*bash
G="https://graph.microsoft.com/v1.0"; AUTH="Authorization: Bearer $MICROSOFT_TEAMS_TOKEN"My chats (1:1 + group), most recent first; expand members for names
My chats (1:1 + group), most recent first; expand members for names
curl -sS -H "$AUTH" "$G/me/chats?$top=20&$expand=members"
| jq '.value[] | {id, chatType, topic, members: [.members[].displayName]}'
| jq '.value[] | {id, chatType, topic, members: [.members[].displayName]}'
undefinedcurl -sS -H "$AUTH" "$G/me/chats?$top=20&$expand=members"
| jq '.value[] | {id, chatType, topic, members: [.members[].displayName]}'
| jq '.value[] | {id, chatType, topic, members: [.members[].displayName]}'
undefinedRead & send chat messages
读取和发送聊天消息
bash
CHAT="CHAT_ID"bash
CHAT="CHAT_ID"Recent messages
Recent messages
curl -sS -H "$AUTH" "$G/chats/$CHAT/messages?$top=20"
| jq '.value[] | {from: .from.user.displayName, created: .createdDateTime, text: .body.content}'
| jq '.value[] | {from: .from.user.displayName, created: .createdDateTime, text: .body.content}'
curl -sS -H "$AUTH" "$G/chats/$CHAT/messages?$top=20"
| jq '.value[] | {from: .from.user.displayName, created: .createdDateTime, text: .body.content}'
| jq '.value[] | {from: .from.user.displayName, created: .createdDateTime, text: .body.content}'
Send a message (confirm content with the user first). contentType html|text.
Send a message (confirm content with the user first). contentType html|text.
curl -sS -X POST -H "$AUTH" -H "Content-Type: application/json"
-d '{"body":{"contentType":"html","content":"Hi from the assistant 👋"}}'
"$G/chats/$CHAT/messages" | jq '{id, created: .createdDateTime}'
-d '{"body":{"contentType":"html","content":"Hi from the assistant 👋"}}'
"$G/chats/$CHAT/messages" | jq '{id, created: .createdDateTime}'
undefinedcurl -sS -X POST -H "$AUTH" -H "Content-Type: application/json"
-d '{"body":{"contentType":"html","content":"Hi from the assistant 👋"}}'
"$G/chats/$CHAT/messages" | jq '{id, created: .createdDateTime}'
-d '{"body":{"contentType":"html","content":"Hi from the assistant 👋"}}'
"$G/chats/$CHAT/messages" | jq '{id, created: .createdDateTime}'
undefinedGotchas
注意事项
- Chats only. Reading Teams channel messages needs
— a Microsoft "protected API" requiring tenant-admin consent — which this connector deliberately does not request. Don't try
ChannelMessage.Read.All; it will 403./teams/{id}/channels/.../messages - for HTML messages contains markup — strip tags when summarizing.
body.content - OData /
$topneed the$expandescaped in the shell; quote the URL.$
- 仅支持聊天。读取Teams频道消息需要
权限——这是Microsoft的“受保护API”,需要租户管理员同意——本连接器特意未申请该权限。不要尝试调用
ChannelMessage.Read.All接口;会返回403错误。/teams/{id}/channels/.../messages - HTML消息的包含标记——在总结时需要去除标签。
body.content - 在shell中,OData的/
$top需要对$expand进行转义;请给URL加上引号。$