Skip to content

fix(telegram): add document message support (docx/pdf/etc)#2069

Merged
RockChinQ merged 1 commit intolangbot-app:masterfrom
sliverp:fix/telegram-document-messages
Mar 21, 2026
Merged

fix(telegram): add document message support (docx/pdf/etc)#2069
RockChinQ merged 1 commit intolangbot-app:masterfrom
sliverp:fix/telegram-document-messages

Conversation

@sliverp
Copy link
Contributor

@sliverp sliverp commented Mar 20, 2026

Problem

The Telegram adapter cannot receive document messages (docx, pdf, etc.) from users. While photos and voice messages work correctly, documents are silently dropped. This means file-based workflows (e.g., Dify document processing) cannot be triggered from Telegram.

Root Cause

Four gaps in the Telegram adapter:

  1. Handler filter (__init__): Only TEXT | COMMAND | PHOTO | VOICE — missing Document.ALL
  2. Inbound parsing (target2yiri): No message.document branch — documents are ignored
  3. Outbound conversion (yiri2target): No platform_message.File branch — cannot convert File components for Telegram
  4. Send handler (send_message): No document component type — cannot send documents

Fix

File Change
telegram.py:__init__ Add filters.Document.ALL to MessageHandler
telegram.py:target2yiri Add message.documentplatform_message.File conversion (downloads file via Bot API, extracts name/size/mime_type)
telegram.py:yiri2target Add platform_message.File{type: "document"} conversion
telegram.py:send_message Add document type handling via bot.send_document()

This is consistent with how other adapters (Lark, KOOK, Discord, WeCom) already handle file messages.

Testing

  • Telegram photo messages: still work (no regression)
  • Telegram document messages (pdf/docx): now properly converted to platform_message.File and forwarded to the pipeline
  • Document sending: bot.send_document() with proper filename

Closes #2065

The Telegram adapter only handles TEXT, COMMAND, PHOTO, and VOICE
messages. Document files (docx, pdf, etc.) sent by users are silently
dropped because:

1. MessageHandler filters lack filters.Document.ALL
2. target2yiri() has no message.document branch
3. yiri2target() has no platform_message.File branch
4. send_message() has no 'document' component handler

Changes:
- Add filters.Document.ALL to the MessageHandler filter set
- Add message.document parsing in target2yiri() → platform_message.File
- Add platform_message.File handling in yiri2target() → document component
- Add 'document' type handling in send_message() via bot.send_document()

This allows Telegram document messages to flow through the existing
PreProcessor and Dify file upload pipeline, consistent with how other
adapters (Lark, KOOK, Discord, WeCom) already handle files.

Closes langbot-app#2065
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. eh: Improve enhance: 现有功能的改进 / improve current features m: Platform 机器人管理相关 / Bots management labels Mar 20, 2026
@RockChinQ RockChinQ merged commit ea07d8a into langbot-app:master Mar 21, 2026
1 of 2 checks passed
@sliverp
Copy link
Contributor Author

sliverp commented Mar 23, 2026

Is there a developer group? We would like to join and have the opportunity to communicate with others.

@RockChinQ
Copy link
Member

@sliverp join in QQ: 1032327138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eh: Improve enhance: 现有功能的改进 / improve current features m: Platform 机器人管理相关 / Bots management size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Telegram adapter cannot receive document messages (docx/pdf), while photo works

2 participants