ForcePilot/backend/package/yuxi/channels/adapters/slack/pairing_notification.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

57 lines
1.7 KiB
Python

from __future__ import annotations
from yuxi.channels.models import DeliveryResult
from yuxi.utils.logging_config import logger
async def send_pairing_notification(
client,
user_id: str,
pairing_code: str,
*,
expires_in_minutes: int = 10,
) -> DeliveryResult:
try:
text = (
f"*Security Pairing Request*\n\n"
f"Your pairing code is: `{pairing_code}`\n"
f"This code expires in {expires_in_minutes} minutes.\n\n"
f"Use `/yuxi pair {pairing_code}` to complete pairing."
)
result = await client.chat_postMessage(
channel=user_id,
text=text,
mrkdwn=True,
)
ok = result.get("ok", False)
return DeliveryResult(
success=ok,
message_id=result.get("ts"),
error=result.get("error") if not ok else None,
)
except Exception as e:
logger.error(f"Failed to send pairing notification: {e}")
return DeliveryResult(success=False, error=str(e))
async def send_pairing_approved_notification(
client,
user_id: str,
) -> DeliveryResult:
try:
text = "✅ *Pairing Approved!*\n\nYou are now authorized to interact with the bot."
result = await client.chat_postMessage(
channel=user_id,
text=text,
mrkdwn=True,
)
ok = result.get("ok", False)
return DeliveryResult(
success=ok,
message_id=result.get("ts"),
error=result.get("error") if not ok else None,
)
except Exception as e:
logger.error(f"Failed to send pairing approval notification: {e}")
return DeliveryResult(success=False, error=str(e))