新增 Facebook Messenger 渠道扩展,支持在 Yuxi 平台中集成 Messenger 即时通讯渠道。 包含以下功能模块: - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - streaming: 流式消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - actions: 动作处理 - template: 消息模板 - quick_reply: 快捷回复 - private_reply: 私密回复 - handover: 转人工切换 - persona: 人设管理 - profile: 主页配置 - user: 用户信息 - insights: 数据洞察 - notification: 通知推送 - media: 媒体资源处理 - types: 类型定义
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
import logging
|
|
|
|
import httpx
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class MessengerStatus:
|
|
async def probe(self, account: dict) -> dict:
|
|
page_id = account.get("page_id", "")
|
|
access_token = account.get("page_access_token", "")
|
|
|
|
if not page_id or not access_token:
|
|
return {"healthy": False, "reason": "missing credentials"}
|
|
|
|
try:
|
|
async with httpx.AsyncClient(timeout=httpx.Timeout(10.0)) as client:
|
|
resp = await client.get(
|
|
f"https://graph.facebook.com/v22.0/{page_id}",
|
|
params={"fields": "id,name,access_token", "access_token": access_token},
|
|
)
|
|
if resp.status_code == 200:
|
|
data = resp.json()
|
|
return {
|
|
"healthy": True,
|
|
"page_id": page_id,
|
|
"page_name": data.get("name", ""),
|
|
"token_valid": True,
|
|
}
|
|
return {"healthy": False, "reason": f"graph api error: {resp.status_code}"}
|
|
except Exception as e:
|
|
logger.exception("messenger probe error")
|
|
return {"healthy": False, "reason": str(e)}
|
|
|
|
@staticmethod
|
|
def build_summary(snapshot: dict) -> dict:
|
|
probes = {}
|
|
if snapshot:
|
|
if "page_name" in snapshot:
|
|
probes["page_name"] = snapshot["page_name"]
|
|
if "token_valid" in snapshot:
|
|
probes["token_valid"] = snapshot["token_valid"]
|
|
if "page_id" in snapshot:
|
|
probes["page_id"] = snapshot["page_id"]
|
|
return {
|
|
"channel": "messenger",
|
|
"probes": probes,
|
|
}
|