Skip to main content
Glama
archetyx
by archetyx

telegram_send_file

Send files directly to Telegram when users need to review specific documents, code files, images, or reports. Use this tool for sharing files that require user examination, such as configuration files, generated outputs, or when explicitly requested.

Instructions

        发送文件到 Telegram

        ⚠️ 使用场景(仅在必要时使用):
        - 用户明确要求查看某个文件:"查看 config.json"、"发送 main.py 给我"
        - 创建了重要的输出文件需要用户确认(如配置文件、报告等)
        - 生成了图表、图片等需要展示的文件
        - 需要用户下载某个文件进行后续操作

        ❌ 不要使用的场景:
        - 创建普通代码文件(用 telegram_notify 总结即可)
        - 修改了文件但不需要用户查看内容
        - 例行的文件操作

        优先级:
        1. 优先使用 telegram_notify 总结文件变更
        2. 如果用户明确要求,或确实需要查看,才发送文件
        3. 对于代码文件,如果只需要展示关键片段,优先使用 telegram_send_code

        参数:
        - file_path: 文件路径(相对于项目目录或绝对路径)
        - caption: 可选说明文字

        支持:
        - 文本文件、代码文件
        - 图片、PDF、文档等任意文件类型
        - 自动处理大文件

        示例:
        telegram_send_file(
            file_path="src/main.py",
            caption="修复后的主文件(用户要求查看)"
        )
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
captionNo可选说明文字
file_pathYes文件路径

Implementation Reference

  • Main handler function for executing the telegram_send_file tool. Validates arguments, resolves file path relative to project, checks file existence, constructs caption, and sends the file as a document via Telegram Bot API's sendDocument endpoint using httpx.
    async def handle_telegram_send_file(session, arguments: dict) -> list[TextContent]:
        """Handle telegram_send_file tool"""
        file_path = arguments.get("file_path", "")
        caption = arguments.get("caption", "")
    
        if not file_path:
            return [TextContent(type="text", text="错误: file_path 参数不能为空")]
    
        # Resolve file path (relative to project or absolute)
        if not os.path.isabs(file_path):
            full_path = os.path.join(session.project_path, file_path)
        else:
            full_path = file_path
    
        # Check if file exists
        if not os.path.exists(full_path):
            return [TextContent(
                type="text",
                text=f"❌ 文件不存在: {file_path}"
            )]
    
        if not os.path.isfile(full_path):
            return [TextContent(
                type="text",
                text=f"❌ 不是文件(可能是目录): {file_path}"
            )]
    
        # Build caption
        if not caption:
            caption = f"📄 [{session.session_id}] {file_path}"
        else:
            caption = f"📄 [{session.session_id}] {caption}"
    
        # Update session
        session.update_activity()
    
        # Send file to Telegram using HTTP API
        try:
            import httpx
    
            url = f"https://api.telegram.org/bot{config.TELEGRAM_BOT_TOKEN}/sendDocument"
    
            with open(full_path, 'rb') as f:
                files = {'document': (os.path.basename(file_path), f, 'application/octet-stream')}
                data = {
                    'chat_id': session.chat_id,
                    'caption': caption
                }
    
                async with httpx.AsyncClient() as client:
                    response = await client.post(url, files=files, data=data, timeout=60.0)
                    response.raise_for_status()
    
            return [TextContent(
                type="text",
                text=f"✅ 已发送文件到 Telegram (会话: {session.session_id}, 文件: {file_path})"
            )]
        except Exception as e:
            return [TextContent(
                type="text",
                text=f"❌ 发送文件失败: {str(e)}"
            )]
  • Tool registration in the list_tools() handler, defining the name, description, and inputSchema for the telegram_send_file tool.
    Tool(
        name="telegram_send_file",
        description="""
        发送文件到 Telegram
    
        ⚠️ 使用场景(仅在必要时使用):
        - 用户明确要求查看某个文件:"查看 config.json"、"发送 main.py 给我"
        - 创建了重要的输出文件需要用户确认(如配置文件、报告等)
        - 生成了图表、图片等需要展示的文件
        - 需要用户下载某个文件进行后续操作
    
        ❌ 不要使用的场景:
        - 创建普通代码文件(用 telegram_notify 总结即可)
        - 修改了文件但不需要用户查看内容
        - 例行的文件操作
    
        优先级:
        1. 优先使用 telegram_notify 总结文件变更
        2. 如果用户明确要求,或确实需要查看,才发送文件
        3. 对于代码文件,如果只需要展示关键片段,优先使用 telegram_send_code
    
        参数:
        - file_path: 文件路径(相对于项目目录或绝对路径)
        - caption: 可选说明文字
    
        支持:
        - 文本文件、代码文件
        - 图片、PDF、文档等任意文件类型
        - 自动处理大文件
    
        示例:
        telegram_send_file(
            file_path="src/main.py",
            caption="修复后的主文件(用户要求查看)"
        )
        """,
        inputSchema={
            "type": "object",
            "properties": {
                "file_path": {
                    "type": "string",
                    "description": "文件路径"
                },
                "caption": {
                    "type": "string",
                    "description": "可选说明文字"
                }
            },
            "required": ["file_path"]
        }
    ),
  • Input schema defining parameters: file_path (required string), caption (optional string).
    inputSchema={
        "type": "object",
        "properties": {
            "file_path": {
                "type": "string",
                "description": "文件路径"
            },
            "caption": {
                "type": "string",
                "description": "可选说明文字"
            }
        },
        "required": ["file_path"]
    }
  • Dispatch logic in call_tool() that routes calls to the specific handler based on tool name.
    elif name == "telegram_send_file":
        return await handle_telegram_send_file(session, arguments)
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key traits: it's a file-sending operation (implies mutation/action), supports various file types (text, code, images, PDFs, documents), handles large files automatically, and includes a caption parameter. However, it doesn't mention potential limitations like file size caps, authentication needs, or error conditions, leaving some gaps for a tool with no annotation coverage.

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 (purpose, usage scenarios, exclusions, priority, parameters, support, example), making it easy to scan. It's appropriately sized for the complexity, though some redundancy exists (e.g., repeating parameter info). Every sentence contributes to understanding, but it could be slightly more streamlined.

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 moderate complexity (2 parameters, no output schema, no annotations), the description is highly complete. It covers purpose, detailed usage guidelines, behavioral aspects (file types, large file handling), parameter basics, and includes an example. This provides sufficient context for an agent to use the tool effectively, compensating for the lack of annotations and output schema.

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?

The schema description coverage is 100%, with both parameters (file_path, caption) documented in the schema. The description adds minimal value beyond the schema: it reiterates that file_path is relative or absolute and caption is optional, but doesn't provide additional context like format examples or constraints. This meets the baseline of 3 for high schema coverage.

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 explicitly states the tool's purpose as '发送文件到 Telegram' (send file to Telegram), which is a specific verb+resource combination. It clearly distinguishes this tool from siblings like telegram_notify (for summaries), telegram_send_code (for code snippets), and telegram_send_image (for images only), making its role unambiguous.

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

Usage Guidelines5/5

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

The description provides extensive usage guidance, including explicit '使用场景' (usage scenarios) with four bullet points of when to use it, '不要使用的场景' (scenarios not to use) with three bullet points, and a '优先级' (priority) section that names alternatives (telegram_notify, telegram_send_code) and specifies when to choose this tool over them. This covers when, when-not, and alternatives comprehensively.

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