新增了完整的Signal渠道适配器实现,包含RPC客户端、守护进程管理、安全策略、消息处理、安装配置工具等全套功能,支持通过signal-cli与Signal网络进行通信,包含账户管理、消息收发、反应处理、媒体分析、健康检查等能力。
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
import logging
|
|
|
|
from yuxi.channels.adapters.signal.client import RpcClient, RpcError
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def get_identities(rpc_client: RpcClient, account: str) -> list[dict]:
|
|
try:
|
|
result = await rpc_client.call("getIdentities", {"account": account})
|
|
return result.get("identities", [])
|
|
except RpcError as e:
|
|
logger.warning(f"Failed to get identities: {e}")
|
|
return []
|
|
|
|
|
|
async def trust_identity(
|
|
rpc_client: RpcClient,
|
|
account: str,
|
|
recipient: str,
|
|
fingerprint: str | None = None,
|
|
) -> bool:
|
|
try:
|
|
params: dict = {"account": account, "recipient": recipient}
|
|
if fingerprint:
|
|
params["fingerprint"] = fingerprint
|
|
else:
|
|
params["trustAllKeys"] = True
|
|
await rpc_client.call("trustIdentity", params)
|
|
return True
|
|
except RpcError as e:
|
|
logger.warning(f"Failed to trust identity {recipient}: {e}")
|
|
return False
|
|
|
|
|
|
async def get_self_number(rpc_client: RpcClient, account: str) -> str | None:
|
|
try:
|
|
result = await rpc_client.call("getSelf", {"account": account})
|
|
return result.get("number")
|
|
except RpcError:
|
|
return account
|