Skip to main content
Glama

telegram_send_code

Send code snippets with syntax highlighting to Telegram for error debugging, bug fixes, code reviews, or when users request specific code examples.

Instructions

        发送代码段到 Telegram(带语法高亮)

        ⚠️ 使用场景(仅在必要时使用):
        - 遇到关键错误需要展示问题代码
        - 修复了重要 bug,需要展示修复方案
        - 用户明确要求查看某段代码
        - 需要用户 review 关键代码片段

        ❌ 不要使用的场景:
        - 一般性任务完成(使用 telegram_notify)
        - 创建了新文件(使用 telegram_send_file)
        - 例行操作(使用 telegram_notify 总结即可)

        参数:
        - code: 代码内容(建议不超过50行)
        - language: 编程语言(python/javascript/go/rust/bash/json/yaml等)
        - caption: 可选说明文字(建议填写,解释发送这段代码的原因)

        示例:
        telegram_send_code(
            code="def hello():\n    print('Hello')",
            language="python",
            caption="修复了空指针异常的关键函数"
        )
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
captionNo可选说明文字
codeYes代码内容
languageNo编程语言(python/javascript/go/rust/bash/json/yaml等)

Implementation Reference

  • The main handler function for the 'telegram_send_code' tool. Extracts code, language, and caption from arguments, formats a Markdown code block message, updates session activity, and sends it to Telegram via send_telegram_message. Returns success or error message.
    async def handle_telegram_send_code(session, arguments: dict) -> list[TextContent]:
        """Handle telegram_send_code tool"""
        code = arguments.get("code", "")
        language = arguments.get("language", "")
        caption = arguments.get("caption", "")
    
        if not code:
            return [TextContent(type="text", text="错误: code 参数不能为空")]
    
        # Build message
        if caption:
            message = f"📝 [`{session.session_id}`] {caption}\n\n"
        else:
            message = f"💻 [`{session.session_id}`] 代码段\n\n"
    
        # Add code block with syntax highlighting
        message += f"```{language}\n{code}\n```"
    
        # Update session
        session.update_activity()
    
        # Send to Telegram
        try:
            await send_telegram_message(session.chat_id, message)
            return [TextContent(
                type="text",
                text=f"✅ 已发送代码段到 Telegram (会话: {session.session_id}, 语言: {language or '未指定'})"
            )]
        except Exception as e:
            return [TextContent(
                type="text",
                text=f"❌ 发送代码段失败: {str(e)}"
            )]
  • Tool schema definition including name, description, and inputSchema for validation of parameters: code (required string), language (optional string), caption (optional string).
    Tool(
        name="telegram_send_code",
        description="""
        发送代码段到 Telegram(带语法高亮)
    
        ⚠️ 使用场景(仅在必要时使用):
        - 遇到关键错误需要展示问题代码
        - 修复了重要 bug,需要展示修复方案
        - 用户明确要求查看某段代码
        - 需要用户 review 关键代码片段
    
        ❌ 不要使用的场景:
        - 一般性任务完成(使用 telegram_notify)
        - 创建了新文件(使用 telegram_send_file)
        - 例行操作(使用 telegram_notify 总结即可)
    
        参数:
        - code: 代码内容(建议不超过50行)
        - language: 编程语言(python/javascript/go/rust/bash/json/yaml等)
        - caption: 可选说明文字(建议填写,解释发送这段代码的原因)
    
        示例:
        telegram_send_code(
            code="def hello():\\n    print('Hello')",
            language="python",
            caption="修复了空指针异常的关键函数"
        )
        """,
        inputSchema={
            "type": "object",
            "properties": {
                "code": {
                    "type": "string",
                    "description": "代码内容"
                },
                "language": {
                    "type": "string",
                    "description": "编程语言(python/javascript/go/rust/bash/json/yaml等)",
                    "default": ""
                },
                "caption": {
                    "type": "string",
                    "description": "可选说明文字"
                }
            },
            "required": ["code"]
        }
    ),
  • Dispatch registration in the main call_tool handler that routes calls to 'telegram_send_code' to the handle_telegram_send_code function.
    elif name == "telegram_send_code":
        return await handle_telegram_send_code(session, arguments)

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

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