Skip to main content
Glama
prem-research

Telegram MCP Server

get_unread_messages

Retrieve all unread messages from a specific Telegram entity to monitor conversations without manual checking.

Instructions

get all unread messages from a given entity id

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idNo

Implementation Reference

  • Registration of the MCP tool 'get_unread_messages' using @mcp.tool decorator
    @mcp.tool(
        name="get_unread_messages",
        description="get all unread messages from a given entity id",
    )
  • Handler function for the 'get_unread_messages' MCP tool, which proxies the request to the HTTP API endpoint to fetch unread messages.
    async def get_unread_messages(id: int = None) -> list[dict]:
        return get(f"{api_endpoint}get_unread_messages/{id}").json()
  • HTTP API endpoint handler that implements the logic for retrieving unread messages by getting the unread count from chats and fetching that many messages, marking them as read.
    @app.get("/get_unread_messages/{chat_id}")
    async def get_unread_messages(chat_id: int):
        dialogs = await get_chats()
        if chat_id not in dialogs:
            raise HTTPException(status_code=404, detail=f"Entity {chat_id} not found")
    
        dialog = dialogs[chat_id]
        unread_count = dialog["unread_count"]
    
        return await get_messages(chat_id=chat_id, count=unread_count)

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/prem-research/telegram-mcp'

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