新增Slack适配器全套核心模块,包括消息处理流水线、会话管理、配置适配、权限控制等完整功能: 1. 新增语音、视觉相关的TTS和图像分析导出接口 2. 实现消息预处理、路由、线程上下文处理的完整流水线 3. 新增账号管理、缓存机制、房间上下文提取功能 4. 支持Webhook和Socket Mode两种事件接收方式 5. 实现权限白名单、审批配对、自动状态管理功能 6. 新增配置迁移、作用域校验、重连策略等辅助模块
35 lines
998 B
Python
35 lines
998 B
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from yuxi.channels.models import ChatType
|
|
|
|
|
|
def resolve_chat_id(channel: str, event: dict[str, Any]) -> str:
|
|
channel_type = event.get("channel_type", "")
|
|
if channel.startswith("D") or channel_type == "im":
|
|
user = event.get("user", "unknown")
|
|
return f"dm_{user}"
|
|
return f"channel_{channel}"
|
|
|
|
|
|
def resolve_chat_type(channel: str, event: dict[str, Any]) -> ChatType:
|
|
if channel.startswith("D"):
|
|
return ChatType.DIRECT
|
|
channel_type = event.get("channel_type", "")
|
|
if channel_type == "im":
|
|
return ChatType.DIRECT
|
|
thread_ts = event.get("thread_ts", "")
|
|
ts = event.get("ts", "")
|
|
if thread_ts and thread_ts != ts:
|
|
return ChatType.THREAD
|
|
return ChatType.CHANNEL
|
|
|
|
|
|
def extract_thread_ts(event: dict[str, Any]) -> str | None:
|
|
thread_ts = event.get("thread_ts")
|
|
ts = event.get("ts")
|
|
if thread_ts and thread_ts != ts:
|
|
return thread_ts
|
|
return None
|