ForcePilot/backend/package/yuxi/channel/extensions/feishu/threading.py
Kris 5e91bb9985 feat(feishu): 新增飞书渠道完整插件实现
新增飞书渠道插件,包含基础配置、事件处理、消息收发、工具调用、权限管理等完整功能模块,支持WebSocket长连接、卡片消息、流式响应、群管理、审批通知等能力
2026-05-21 10:46:42 +08:00

56 lines
1.7 KiB
Python

from __future__ import annotations
import asyncio
import logging
from yuxi.channel.extensions.feishu.types import FeishuGroupSessionScope
from yuxi.channel.extensions.feishu.session import FeishuSessionAdapter
logger = logging.getLogger(__name__)
class FeishuThreadingAdapter:
def __init__(self):
self._session = FeishuSessionAdapter()
def resolve_session_scope(
self,
account: dict,
chat_id: str,
*,
sender_id: str | None = None,
thread_id: str | None = None,
) -> str:
scope = account.get("group_session_scope", "group")
groups = account.get("groups", {})
if chat_id in groups:
group_cfg = groups[chat_id]
if "group_session_scope" in group_cfg:
scope = group_cfg["group_session_scope"]
return self._session.build_session_key(
chat_id,
sender_id=sender_id,
thread_id=thread_id,
scope=scope,
)
def get_thread_info(self, thread_id: str) -> dict | None:
return {
"thread_id": thread_id,
"is_topic": thread_id.startswith("omt_") if thread_id else False,
}
def should_reply_in_thread(self, account: dict, chat_id: str | None = None) -> bool:
reply_in_thread = account.get("reply_in_thread", "disabled")
if chat_id:
groups = account.get("groups", {})
group_cfg = groups.get(chat_id, {})
if "reply_in_thread" in group_cfg:
reply_in_thread = group_cfg["reply_in_thread"]
return reply_in_thread == "enabled"
def extract_thread_id(self, msg: object) -> str | None:
return self._session.extract_thread_id(msg)