ForcePilot/backend/package/yuxi/channels/adapters/msteams/pins.py
Kris bd60c15df0 feat(msteams): 新增完整的 Microsoft Teams 适配器模块
实现了 Teams 机器人所需的全功能组件,包括:
- 基础命令解析与帮助卡片生成
- 租户验证与访问控制
- 自定义 UA 与媒体工具
- 消息分块、批注处理与会话管理
- 防抖、缓存与配置路由能力
- 投票、配对、审计与运行时状态管理
- TTS 语音合成与卡片构建工具
- 群组管理与权限控制逻辑
2026-05-12 00:46:44 +08:00

53 lines
1.4 KiB
Python

"""Microsoft Teams 消息 Pin/Unpin。
通过 Graph API 实现频道消息固定与取消固定。
"""
from __future__ import annotations
from typing import Any, TYPE_CHECKING
if TYPE_CHECKING:
from .graph import GraphClient
from yuxi.utils.logging_config import logger
async def pin_message(
client: GraphClient,
team_id: str,
channel_id: str,
message_id: str,
) -> dict[str, Any]:
path = f"/teams/{team_id}/channels/{channel_id}/messages/{message_id}"
result = await client._request_with_retry("POST", path)
if "error" not in result:
logger.info(f"MSTeams message pinned: {message_id} in channel {channel_id}")
return result
async def unpin_message(
client: GraphClient,
team_id: str,
channel_id: str,
message_id: str,
) -> dict[str, Any]:
path = f"/teams/{team_id}/channels/{channel_id}/messages/{message_id}/undoSoftDelete"
result = await client._request_with_retry("POST", path)
if "error" not in result:
logger.info(f"MSTeams message unpinned: {message_id}")
return result
async def get_pinned_messages(
client: GraphClient,
team_id: str,
channel_id: str,
) -> list[dict[str, Any]]:
path = f"/teams/{team_id}/channels/{channel_id}/pinnedMessages"
params = {"$expand": "message"}
result = await client._get(path, params=params)
if "error" in result:
return []
return result.get("value", [])