新增企业微信、微博、WhatsApp、Workplace 四个渠道扩展。 企业微信渠道扩展主要模块:config, gateway, webhook, webhook_bot, outbound, streaming, pairing, security, crypto, dedupe, persistent_dedupe, card, directory, events, externalcontact, media, mentions, menu, message, oauth, status 微博渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, passive_reply, broadcast, message, menu, media, subscription, template, status WhatsApp 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, actions, monitor, status Workplace 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, actions, challenge, groups, media, mentions, menu, monitor, persona, quick_reply, signature, subscriptions, template, threading, users, status
98 lines
3.5 KiB
Python
98 lines
3.5 KiB
Python
import logging
|
|
|
|
import httpx
|
|
|
|
from yuxi.channel.extensions.weibo.gateway import PROBE_URL
|
|
from yuxi.channel.protocols import ChannelAccountSnapshot
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class WeiboStatus:
|
|
default_runtime = ChannelAccountSnapshot(account_id="default")
|
|
|
|
def __init__(self, gateway=None):
|
|
self._gateway = gateway
|
|
|
|
async def probe(self, account: dict | None = None) -> bool:
|
|
gateway = self._gateway
|
|
if gateway is None:
|
|
return False
|
|
|
|
token = gateway.access_token
|
|
if not token:
|
|
return False
|
|
|
|
url = f"{PROBE_URL}?access_token={token}&uid={gateway._account.app_key}"
|
|
try:
|
|
async with httpx.AsyncClient(timeout=10.0) as client:
|
|
resp = await client.get(url)
|
|
data = resp.json()
|
|
|
|
if "error_code" in data:
|
|
logger.warning("Weibo probe failed: error_code=%s", data.get("error_code"))
|
|
return False
|
|
|
|
return True
|
|
except Exception:
|
|
logger.exception("Weibo probe failed")
|
|
return False
|
|
|
|
def build_summary(self, snapshot: object) -> dict:
|
|
if not isinstance(snapshot, ChannelAccountSnapshot):
|
|
return {}
|
|
return {
|
|
"account_id": snapshot.account_id,
|
|
"running": snapshot.running,
|
|
"connected": snapshot.connected,
|
|
"health_state": snapshot.health_state,
|
|
}
|
|
|
|
def build_account_snapshot(
|
|
self,
|
|
account: dict,
|
|
config: dict,
|
|
runtime: ChannelAccountSnapshot | None = None,
|
|
probe_result: object | None = None,
|
|
audit: object | None = None,
|
|
) -> ChannelAccountSnapshot:
|
|
gateway = self._gateway
|
|
token = gateway.access_token if gateway else None
|
|
return ChannelAccountSnapshot(
|
|
account_id=account.get("account_id", "default"),
|
|
name=account.get("name", ""),
|
|
enabled=account.get("enabled", True),
|
|
configured=bool(account.get("app_key") and account.get("app_secret") and account.get("access_token")),
|
|
status_state="linked" if token else "not-linked",
|
|
running=getattr(runtime, "running", False) if runtime else False,
|
|
connected=bool(token),
|
|
last_message_at=getattr(runtime, "last_message_at", None) if runtime else None,
|
|
health_state="ok" if probe_result else "unknown",
|
|
dm_policy=account.get("dm_policy", "open"),
|
|
)
|
|
|
|
def collect_status_issues(self, accounts: list[ChannelAccountSnapshot]) -> list:
|
|
issues = []
|
|
for acc in accounts:
|
|
if not acc.configured:
|
|
issues.append(
|
|
{
|
|
"channel": "weibo",
|
|
"account_id": acc.account_id,
|
|
"kind": "not-configured",
|
|
"message": "Weibo credentials not configured",
|
|
"fix": "Set WEIBO_APP_KEY, WEIBO_APP_SECRET, WEIBO_CALLBACK_TOKEN, WEIBO_ACCESS_TOKEN",
|
|
}
|
|
)
|
|
elif not acc.connected:
|
|
issues.append(
|
|
{
|
|
"channel": "weibo",
|
|
"account_id": acc.account_id,
|
|
"kind": "not-connected",
|
|
"message": "Weibo gateway not running",
|
|
"fix": "Check environment variables and gateway status",
|
|
}
|
|
)
|
|
return issues
|