ForcePilot/backend/package/yuxi/channels/adapters/slack/reaction_notify.py
Kris a2aa782b86 feat(slack adapter): 实现完整的Slack频道适配器基础功能
新增Slack适配器全套核心模块,包括消息处理流水线、会话管理、配置适配、权限控制等完整功能:
1. 新增语音、视觉相关的TTS和图像分析导出接口
2. 实现消息预处理、路由、线程上下文处理的完整流水线
3. 新增账号管理、缓存机制、房间上下文提取功能
4. 支持Webhook和Socket Mode两种事件接收方式
5. 实现权限白名单、审批配对、自动状态管理功能
6. 新增配置迁移、作用域校验、重连策略等辅助模块
2026-05-12 00:48:57 +08:00

51 lines
1.6 KiB
Python

from __future__ import annotations
from dataclasses import dataclass, field
from enum import StrEnum
from typing import Any
class ReactionNotifyMode(StrEnum):
OFF = "off"
ALL = "all"
ALLOWLIST = "allowlist"
@dataclass
class ReactionNotifyConfig:
mode: ReactionNotifyMode = ReactionNotifyMode.OFF
allowlist: set[str] = field(default_factory=set)
@classmethod
def from_config(cls, config: dict[str, Any] | None) -> ReactionNotifyConfig:
if not config:
return cls()
mode_raw = str(config.get("reaction_notifications", "off")).strip().lower()
mode_map = {
"off": ReactionNotifyMode.OFF,
"all": ReactionNotifyMode.ALL,
"allowlist": ReactionNotifyMode.ALLOWLIST,
}
mode = mode_map.get(mode_raw, ReactionNotifyMode.OFF)
allowlist_raw = config.get("reaction_allowlist", [])
if isinstance(allowlist_raw, str):
allowlist_raw = [x.strip() for x in allowlist_raw.split(",") if x.strip()]
elif not isinstance(allowlist_raw, (list, tuple)):
allowlist_raw = []
allowlist = {str(e) for e in allowlist_raw if e}
return cls(mode=mode, allowlist=allowlist)
def should_notify(self, emoji: str) -> bool:
if self.mode == ReactionNotifyMode.OFF:
return False
if self.mode == ReactionNotifyMode.ALL:
return True
if self.mode == ReactionNotifyMode.ALLOWLIST:
if "*" in self.allowlist:
return True
return emoji in self.allowlist
return False