新增 Zalo OA、Zoom Chat、Zulip 三个渠道扩展。 Zalo OA 渠道扩展主要模块:sidecar_client, config, gateway, outbound, streaming, pairing, security, auth, dedupe, directory, monitor, status, session, reactions, tools Zoom Chat 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, crypto, dedupe, actions, media, mentions, monitor, status, session, reactions, threading Zulip 渠道扩展主要模块:client, config, gateway, outbound, streaming, pairing, security, monitor, status
131 lines
5.1 KiB
Python
131 lines
5.1 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from yuxi.channel.extensions.zalouser.sidecar_client import ZcaSidecarClient
|
|
from yuxi.channel.extensions.zalouser.types import (
|
|
ZaloFriend,
|
|
ZaloGroup,
|
|
ZaloGroupMember,
|
|
ZaloUserInfo,
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ZaloUserDirectory:
|
|
def __init__(self):
|
|
self._client: ZcaSidecarClient | None = None
|
|
|
|
def set_client(self, client: ZcaSidecarClient) -> None:
|
|
self._client = client
|
|
|
|
async def get_self(self) -> ZaloUserInfo | None:
|
|
if not self._client:
|
|
return None
|
|
return await self._client.get_me()
|
|
|
|
async def list_friends(self, query: str | None = None) -> list[ZaloFriend]:
|
|
if not self._client:
|
|
return []
|
|
return await self._client.list_friends(query)
|
|
|
|
async def list_groups(self, query: str | None = None) -> list[ZaloGroup]:
|
|
if not self._client:
|
|
return []
|
|
return await self._client.list_groups(query)
|
|
|
|
async def list_group_members(self, group_id: str) -> list[ZaloGroupMember]:
|
|
if not self._client:
|
|
return []
|
|
return await self._client.list_group_members(group_id)
|
|
|
|
async def find_user(self, phone_number: str) -> dict | None:
|
|
if not self._client:
|
|
return None
|
|
return await self._client.find_user(phone_number)
|
|
|
|
async def get_user_info(self, user_id: str) -> ZaloUserInfo | None:
|
|
if not self._client:
|
|
return None
|
|
return await self._client.get_user_info(user_id)
|
|
|
|
async def get_group_info(self, group_id: str) -> ZaloGroup | None:
|
|
if not self._client:
|
|
return None
|
|
return await self._client.get_group_info(group_id)
|
|
|
|
async def create_group(self, name: str, member_ids: list[str]) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.create_group(name, member_ids)
|
|
|
|
async def disband_group(self, group_id: str) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.disband_group(group_id)
|
|
|
|
async def add_user_to_group(self, user_id: str, group_id: str) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.add_user_to_group(user_id, group_id)
|
|
|
|
async def remove_user_from_group(self, user_id: str, group_id: str) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.remove_user_from_group(user_id, group_id)
|
|
|
|
async def change_group_name(self, group_id: str, name: str) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.change_group_name(group_id, name)
|
|
|
|
async def change_group_avatar(self, group_id: str, avatar_url: str) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.change_group_avatar(group_id, avatar_url)
|
|
|
|
async def change_group_owner(self, group_id: str, member_id: str) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.change_group_owner(group_id, member_id)
|
|
|
|
async def add_group_deputies(self, group_id: str, member_ids: list[str]) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.add_group_deputies(group_id, member_ids)
|
|
|
|
async def remove_group_deputies(self, group_id: str, member_ids: list[str]) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.remove_group_deputies(group_id, member_ids)
|
|
|
|
async def block_user(self, user_id: str) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.block_user(user_id)
|
|
|
|
async def unblock_user(self, user_id: str) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.unblock_user(user_id)
|
|
|
|
async def change_friend_alias(self, user_id: str, alias: str) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.change_friend_alias(user_id, alias)
|
|
|
|
async def send_friend_request(self, user_id: str, msg: str = "") -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.send_friend_request(user_id, msg)
|
|
|
|
async def accept_friend_request(self, user_id: str) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.accept_friend_request(user_id)
|
|
|
|
async def pin_conversations(self, thread_ids: list[str]) -> dict:
|
|
if not self._client:
|
|
raise RuntimeError("ZcaSidecarClient not set")
|
|
return await self._client.pin_conversations(thread_ids) |