Skip to main content
Glama

get_chat_members_count

Retrieve the total number of participants in a Telegram chat using the chat ID to monitor group size and manage community engagement.

Instructions

Get the number of members in a chat.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_idYes

Implementation Reference

  • Implementation of the 'get_chat_members_count' tool handler, which uses the bot context to fetch the chat member count and logs the outcome.
    async def get_chat_members_count(chat_id: int) -> ChatMembersCountResult:
        """Get the number of members in a chat."""
        try:
            if ctx.rate_limiter:
                await ctx.rate_limiter.acquire()
            count = await ctx.bot.get_chat_member_count(chat_id=chat_id)
            result = ChatMembersCountResult(ok=True, count=count)
        except (TelegramBadRequest, TelegramForbiddenError) as exc:
            result = ChatMembersCountResult(ok=False, error=str(exc))
    
        if ctx.audit_logger:
            ctx.audit_logger.log(
                "get_chat_members_count",
                {"chat_id": chat_id},
                result.ok,
                result.error,
            )
        return result
  • Definition of the response model 'ChatMembersCountResult' used by the tool.
    class ChatMembersCountResult(ToolResponse):
        count: int | None = None
  • Registration/conditional logic for the tool in the 'register_chat_tools' function.
    if allowed_tools is None or "get_chat_members_count" in allowed_tools:

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Py2755/aiogram-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server