新增Slack适配器全套核心模块,包括消息处理流水线、会话管理、配置适配、权限控制等完整功能: 1. 新增语音、视觉相关的TTS和图像分析导出接口 2. 实现消息预处理、路由、线程上下文处理的完整流水线 3. 新增账号管理、缓存机制、房间上下文提取功能 4. 支持Webhook和Socket Mode两种事件接收方式 5. 实现权限白名单、审批配对、自动状态管理功能 6. 新增配置迁移、作用域校验、重连策略等辅助模块
58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
import asyncio
|
|
|
|
from slack_sdk.errors import SlackApiError
|
|
from slack_sdk.socket_mode.aiohttp import SocketModeClient
|
|
from slack_sdk.web.async_client import AsyncWebClient
|
|
|
|
|
|
async def probe_bot_token(token: str) -> dict:
|
|
if not token.startswith("xoxb-"):
|
|
return {"status": "error", "message": "Token must start with 'xoxb-'"}
|
|
|
|
try:
|
|
client = AsyncWebClient(token=token)
|
|
auth = await client.auth_test()
|
|
if not auth.get("ok"):
|
|
return {"status": "error", "message": f"auth.test failed: {auth.get('error')}"}
|
|
|
|
return {
|
|
"status": "ok",
|
|
"bot_id": auth.get("bot_id", ""),
|
|
"bot_user_id": auth.get("user_id", ""),
|
|
"team": auth.get("team", ""),
|
|
"team_id": auth.get("team_id", ""),
|
|
"url": auth.get("url", ""),
|
|
}
|
|
except SlackApiError as e:
|
|
err = e.response.get("error", str(e))
|
|
return {"status": "error", "message": err}
|
|
except Exception as e:
|
|
return {"status": "error", "message": str(e)}
|
|
|
|
|
|
async def probe_app_token(token: str) -> dict:
|
|
if not token.startswith("xapp-"):
|
|
return {"status": "error", "message": "Token must start with 'xapp-'"}
|
|
|
|
handler = SocketModeClient(app_token=token)
|
|
connect_task = asyncio.create_task(handler.connect_async())
|
|
try:
|
|
try:
|
|
await asyncio.wait_for(connect_task, timeout=5.0)
|
|
except TimeoutError:
|
|
connect_task.cancel()
|
|
return {"status": "ok", "message": "Socket Mode connection timed out (expected without full setup)"}
|
|
except Exception:
|
|
pass
|
|
finally:
|
|
if not connect_task.done():
|
|
connect_task.cancel()
|
|
try:
|
|
handler.disconnect()
|
|
except Exception:
|
|
pass
|
|
|
|
return {"status": "ok", "message": "Socket Mode handshake completed"}
|