ForcePilot/backend/package/yuxi/channel/extensions/flock/channel.py
Kris 0bad70ec19 feat(flock): 新增Flock团队协作IM渠道插件
实现了完整的Flock渠道接入能力,包含消息收发、Webhook事件监听、账号配置、安全校验、媒体文件处理等功能,支持私聊和群组聊天,适配ForcePilot插件规范。
2026-05-21 10:47:01 +08:00

65 lines
1.7 KiB
Python

from __future__ import annotations
import logging
from .constants import (
ENDPOINT_CHANNEL_GET_INFO,
ENDPOINT_CHANNEL_GET_MEMBERS,
ENDPOINT_CHANNEL_LIST,
)
from .utils import create_http_client, flock_api_call
logger = logging.getLogger(__name__)
async def list_channels(
bot_token: str,
) -> list[dict]:
client = create_http_client()
try:
result = await flock_api_call(client, ENDPOINT_CHANNEL_LIST, bot_token, {})
channels = result.get("channels", [])
logger.info("Flock listed %d channels", len(channels))
return channels
except Exception as e:
logger.error("Flock list_channels failed: %s", e)
return []
finally:
await client.aclose()
async def get_channel_info(
channel_id: str,
bot_token: str,
) -> dict | None:
client = create_http_client()
try:
result = await flock_api_call(
client, ENDPOINT_CHANNEL_GET_INFO, bot_token, {"channelId": channel_id}
)
return result
except Exception as e:
logger.error("Flock get_channel_info failed for %s: %s", channel_id, e)
return None
finally:
await client.aclose()
async def get_channel_members(
channel_id: str,
bot_token: str,
) -> list[dict]:
client = create_http_client()
try:
result = await flock_api_call(
client, ENDPOINT_CHANNEL_GET_MEMBERS, bot_token, {"channelId": channel_id}
)
members = result.get("members", [])
logger.info("Flock got %d members for channel %s", len(members), channel_id)
return members
except Exception as e:
logger.error("Flock get_channel_members failed for %s: %s", channel_id, e)
return []
finally:
await client.aclose()