新增大量渠道适配器相关的协议、策略、工具类与基础设施代码,包括: 1. 多协议定义:认证、消息、配置、网关等核心接口 2. 策略模块:上下文、群聊、去重、防抖等业务策略 3. 工具集:重试、去重、文本分块、消息格式化等SDK工具 4. 基础设施:外部进程管理、事件广播、熔断机制等 5. 账户与管道系统:账户管理、消息处理管道实现 6. 运行时服务:状态收集、维护任务、日志等后台服务
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
|
class BaseDirectoryAdapter(ABC):
|
|
"""目录服务接口
|
|
|
|
定义三个标准查询方法,跨渠道统一:
|
|
- list_peers(config, account_id) → 列出可联系的人/用户
|
|
- list_groups(config, account_id) → 列出可交互的群组
|
|
- search_peers(query) → 搜索联系人(可选)
|
|
"""
|
|
|
|
@abstractmethod
|
|
async def list_peers(self, config: dict, account_id: str = "default") -> list[dict]:
|
|
"""列出所有可联系的人/用户
|
|
|
|
各渠道实现:
|
|
- 微信: WeCom 通讯录 API / Bridge /contacts
|
|
- 飞书: 飞书通讯录 API
|
|
- WhatsApp: Bridge /contacts
|
|
- QQBot: 频道成员 API
|
|
"""
|
|
...
|
|
|
|
@abstractmethod
|
|
async def list_groups(self, config: dict, account_id: str = "default") -> list[dict]:
|
|
"""列出所有可交互的群组"""
|
|
...
|
|
|
|
async def search_peers(self, query: str) -> list[dict]:
|
|
"""搜索联系人(可选实现,默认返回空)"""
|
|
return []
|