ForcePilot/backend/package/yuxi/channels/adapters/msteams/pins.py
Kris 939f1ba82a refactor(msteams): 整理代码结构并新增多项功能
本次提交对Microsoft Teams适配器代码进行了多维度优化与新增:
1.  调整多处导入顺序,优化代码可读性
2.  新增media_tools工具模块,提供媒体相关辅助函数
3.  新增thread_history模块,实现对话历史拉取与缓存功能
4.  新增connection_modes模块,支持webhook/websocket/polling三种连接模式
5.  扩展security.py与tool_policy.py,新增通配符配置校验与三级策略解析
6.  新增feedback会话记录功能
7.  为sent_message_cache添加自动清理任务
8.  优化normalizer模块,新增引用、编辑消息解析与线程上下文注入
9.  重构file_upload的SSRF防护逻辑,复用公共校验工具
10. 修复多处导入顺序与代码排版问题
11. 为消息发送添加断路器保护与异步去重锁
2026-05-13 16:12:31 +08:00

53 lines
1.4 KiB
Python

"""Microsoft Teams 消息 Pin/Unpin。
通过 Graph API 实现频道消息固定与取消固定。
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Any
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", [])