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
- Create a file:
echo "test content" > /tmp/test.txt
- Ask the agent to send it: "Send me this file: MEDIA:/tmp/test.txt"
- 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
- Trace the call chain in
handle_message() to ensure TelegramAdapter.send_document() is invoked
- Fix the regex to handle spaces:
MEDIA_PATTERN = re.compile(r'MEDIA:\s*(.+?)(?=\s+(?:MEDIA:|$|\n)|$)', re.IGNORECASE)
- 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.
Bug Description
The
MEDIA:tag for sending files via Telegram is broken. When includingMEDIA:/path/to/filein a response, the file path is sent as plain text instead of the actual file being uploaded.Reproduction Steps
echo "test content" > /tmp/test.txtExpected 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.pyline 562,send_document()defaults to:Issue 2: Adapter Override Not Being Called
TelegramAdapter.send_document()exists (lines 282-294) but is not being invoked when processingMEDIA: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.pyline 268 has issues with spaces in filenames:The
\S+stops at first space, breaking paths like/path/to/my file.txt.Suggested Fix
handle_message()to ensureTelegramAdapter.send_document()is invokedEnvironment
Additional Context
I worked around this by using
python-telegram-botdirectly to callsend_document(), which confirms the Telegram Bot API works fine - it's the gateway's internal routing that's broken.