Skip to main content
Glama
archetyx
by archetyx

telegram_wait_reply

Wait for user responses in Telegram conversations with configurable timeout periods and polling intervals, enabling automated interaction handling and command processing.

Instructions

        等待用户回复(阻塞式轮询)

        参数:
        - max_wait: 最长等待时间(秒),默认604800(7天/1周)

        行为:
        - 前10分钟:每30秒检查一次
        - 10分钟-1小时:每60秒检查一次
        - 1小时以上:每120秒检查一次
        - 用户可以按 Ctrl+C 中断等待
        - 超时返回 timeout: true

        返回:
        - reply: 用户回复内容
        - timeout: 是否超时
        - interrupted: 是否被用户中断
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_waitNo最长等待时间(秒),默认604800(7天)

Implementation Reference

  • Core implementation of the telegram_wait_reply tool handler. Polls message_queue for user replies with progressive backoff (30s/60s/120s based on elapsed time), handles timeout, interruption (Ctrl+C), and returns the reply or status.
    async def handle_telegram_wait_reply(session, arguments: dict) -> list[TextContent]:
        """Handle telegram_wait_reply tool"""
        max_wait = arguments.get("max_wait", config.TELEGRAM_MAX_WAIT)
    
        logger.info(f"Session {session.session_id} waiting for reply (max {max_wait}s)")
    
        # Mark session as waiting
        session.set_waiting()
        registry.update_session(session)  # Save to shared storage
    
        # Poll for messages
        start_time = time.time()
    
        try:
            while True:
                elapsed = time.time() - start_time
    
                # Check timeout
                if elapsed >= max_wait:
                    session.set_running()
                    registry.update_session(session)  # Save to shared storage
                    logger.info(f"Session {session.session_id} wait timeout")
                    return [TextContent(
                        type="text",
                        text=f"超时: 等待了 {int(elapsed)} 秒未收到回复"
                    )]
    
                # Check message queue
                if message_queue.has_messages(session.session_id):
                    reply = message_queue.pop(session.session_id)
                    session.set_running()
                    registry.update_session(session)  # Save to shared storage
                    logger.info(f"Session {session.session_id} received reply: {reply}")
                    return [TextContent(
                        type="text",
                        text=f"用户回复: {reply}"
                    )]
    
                # Progressive polling
                interval = get_poll_interval(elapsed)
                logger.debug(f"Session {session.session_id} polling (interval={interval}s, elapsed={int(elapsed)}s)")
                await asyncio.sleep(interval)
        except (KeyboardInterrupt, asyncio.CancelledError):
            session.set_running()
            registry.update_session(session)  # Save to shared storage
            logger.info(f"Session {session.session_id} wait interrupted by user")
            return [TextContent(
                type="text",
                text=f"⚠️ 等待被用户中断 (Ctrl+C)\n\n已等待: {int(time.time() - start_time)} 秒\n\n你可以继续正常对话。"
            )]
  • Input schema definition for the telegram_wait_reply tool, specifying the optional max_wait parameter.
    inputSchema={
        "type": "object",
        "properties": {
            "max_wait": {
                "type": "integer",
                "description": "最长等待时间(秒),默认604800(7天)",
                "default": 604800
            }
        }
    }
  • Registration of the telegram_wait_reply tool in the list_tools() function, including name, description, and input schema.
    Tool(
        name="telegram_wait_reply",
        description="""
        等待用户回复(阻塞式轮询)
    
        参数:
        - max_wait: 最长等待时间(秒),默认604800(7天/1周)
    
        行为:
        - 前10分钟:每30秒检查一次
        - 10分钟-1小时:每60秒检查一次
        - 1小时以上:每120秒检查一次
        - 用户可以按 Ctrl+C 中断等待
        - 超时返回 timeout: true
    
        返回:
        - reply: 用户回复内容
        - timeout: 是否超时
        - interrupted: 是否被用户中断
        """,
        inputSchema={
            "type": "object",
            "properties": {
                "max_wait": {
                    "type": "integer",
                    "description": "最长等待时间(秒),默认604800(7天)",
                    "default": 604800
                }
            }
        }
    ),
  • Helper function used by the handler to determine progressive polling intervals based on elapsed waiting time.
    def get_poll_interval(elapsed_seconds: float) -> int:
        """
        Get polling interval based on elapsed time
        Progressive slowdown: 30s -> 60s -> 120s
        """
        if elapsed_seconds < config.POLL_THRESHOLDS[0]:  # < 10 minutes
            return config.POLL_INTERVALS[0]  # 30 seconds
        elif elapsed_seconds < config.POLL_THRESHOLDS[1]:  # < 1 hour
            return config.POLL_INTERVALS[1]  # 60 seconds
        else:
            return config.POLL_INTERVALS[2]  # 120 seconds
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and excels by detailing behavioral traits: polling intervals (30s/60s/120s based on time), user interruptibility (Ctrl+C), timeout behavior (returns timeout: true), and return structure (reply, timeout, interrupted). This provides comprehensive operational context beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (参数, 行为, 返回) and front-loaded purpose. It's appropriately sized, but minor redundancy exists (e.g., parameter details partially overlap with schema). Every sentence adds value, though it could be slightly more concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (blocking polling with intervals and interrupts), no annotations, and no output schema, the description is complete. It covers purpose, parameters, detailed behavior, and return values, providing all necessary context for an agent to use the tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the parameter 'max_wait' fully documented in the schema. The description repeats the parameter name and default value but adds minimal extra context (e.g., '最长等待时间(秒)' is already in schema). Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as '等待用户回复(阻塞式轮询)' (wait for user reply with blocking polling), which is a specific verb+resource combination. It distinguishes itself from sibling tools like telegram_send (which sends messages) by focusing on receiving replies through a polling mechanism.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context through its behavioral details (blocking polling with timeout), suggesting it should be used when waiting for user responses. However, it doesn't explicitly state when to use this tool versus alternatives like telegram_notify or how it relates to other tools in the workflow, missing explicit alternative guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/archetyx/telegram-mcp-server'

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