from typing import Any
from dooray_mcp.services.client import dooray_client
from dooray_mcp.types.messenger import Channel, ChannelListResult, MessageLog
async def list_channels() -> ChannelListResult:
path = "/messenger/v1/channels"
response = await dooray_client.get(path)
result = response.get("result", [])
if isinstance(result, list):
total_count = response.get("header", {}).get("totalCount", len(result))
return ChannelListResult(totalCount=total_count, contents=result)
return ChannelListResult.model_validate(result)
async def create_channel(
title: str,
member_ids: list[str],
channel_type: str = "private",
capacity: int | None = None,
) -> Channel:
path = "/messenger/v1/channels"
body: dict[str, Any] = {
"title": title,
"memberIds": member_ids,
"type": channel_type,
}
if capacity is not None:
body["capacity"] = capacity
response = await dooray_client.post(path, json_data=body)
return Channel.model_validate(response.get("result", {}))
async def send_channel_message(channel_id: str, content: str) -> MessageLog:
path = f"/messenger/v1/channels/{channel_id}/logs"
body: dict[str, Any] = {
"text": content,
}
response = await dooray_client.post(path, json_data=body)
return MessageLog.model_validate(response.get("result", {}))
async def send_direct_message(member_id: str, content: str) -> MessageLog:
path = "/messenger/v1/channels/direct-send"
body: dict[str, Any] = {
"text": content,
"organizationMemberId": member_id,
}
response = await dooray_client.post(path, json_data=body)
return MessageLog.model_validate(response.get("result", {}))
async def join_channel_members(channel_id: str, member_ids: list[str]) -> bool:
path = f"/messenger/v1/channels/{channel_id}/members/join"
body: dict[str, Any] = {
"memberIds": member_ids,
}
await dooray_client.post(path, json_data=body)
return True
async def leave_channel_members(channel_id: str, member_ids: list[str]) -> bool:
path = f"/messenger/v1/channels/{channel_id}/members/leave"
body: dict[str, Any] = {
"memberIds": member_ids,
}
await dooray_client.post(path, json_data=body)
return True