ForcePilot/backend/package/yuxi/channel/extensions/wecom/status.py

41 lines
1.3 KiB
Python
Raw Normal View History

import logging
from yuxi.channel.protocols import ChannelAccountSnapshot
logger = logging.getLogger(__name__)
class WeComStatus:
def __init__(self, gateway=None):
self._gateway = gateway
async def probe(self, account: dict | None = None) -> bool:
if self._gateway is None:
return False
token = self._gateway.access_token
return token is not None and len(token) > 0
def build_summary(self, snapshot: object) -> dict:
return {
"channel": "wecom",
"running": self._gateway is not None and getattr(self._gateway, "_running", False),
"token_valid": self._gateway is not None and self._gateway.access_token is not None,
}
def build_account_snapshot(
self,
account: dict,
config: dict,
runtime: ChannelAccountSnapshot | None = None,
probe_result: object | None = None,
audit: object | None = None,
) -> ChannelAccountSnapshot:
return ChannelAccountSnapshot(
account_id=account.get("account_id", "default"),
name=account.get("name"),
configured=True,
running=True,
connected=bool(probe_result),
dm_policy=account.get("dm_policy"),
)