Skip to content

MEDIA: tag fails to send files - document upload not working #1803

@AxDSan

Description

@AxDSan

Bug Description

The MEDIA: tag for sending files via Telegram is broken. When including MEDIA:/path/to/file in a response, the file path is sent as plain text instead of the actual file being uploaded.

Reproduction Steps

  1. Create a file: echo "test content" > /tmp/test.txt
  2. Ask the agent to send it: "Send me this file: MEDIA:/tmp/test.txt"
  3. The bot responds with the literal text "MEDIA:/tmp/test.txt" instead of uploading the file

Expected Behavior

The file should be uploaded as a document attachment via the Telegram Bot API.

Actual Behavior

The file path is sent as plain text message.

Root Cause Analysis

Issue 1: Base Class Default Behavior

In base.py line 562, send_document() defaults to:

def send_document(self, file_path: str, caption: Optional[str] = None) -> str:
    return self.send_message(file_path)  # Just sends path as text!

Issue 2: Adapter Override Not Being Called

TelegramAdapter.send_document() exists (lines 282-294) but is not being invoked when processing MEDIA: tags. The gateway's message processing chain is not correctly routing to the adapter's method.

Issue 3: Regex Pattern Issues

The regex in platforms/messaging.py line 268 has issues with spaces in filenames:

MEDIA_PATTERN = re.compile(r'MEDIA:\s*(\S+)', re.IGNORECASE)

The \S+ stops at first space, breaking paths like /path/to/my file.txt.

Suggested Fix

  1. Trace the call chain in handle_message() to ensure TelegramAdapter.send_document() is invoked
  2. Fix the regex to handle spaces:
    MEDIA_PATTERN = re.compile(r'MEDIA:\s*(.+?)(?=\s+(?:MEDIA:|$|\n)|$)', re.IGNORECASE)
  3. Add logging to verify the adapter method is reached

Environment

  • Hermes Gateway version: latest
  • Platform: Telegram
  • Python version: 3.11+

Additional Context

I worked around this by using python-telegram-bot directly to call send_document(), which confirms the Telegram Bot API works fine - it's the gateway's internal routing that's broken.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions