Skip to content

feat: add file support, markdown rendering, user identity and request interruption - #2

Open
moritzknecht wants to merge 4 commits into
winboost:mainfrom
moritzknecht:main
Open

feat: add file support, markdown rendering, user identity and request interruption#2
moritzknecht wants to merge 4 commits into
winboost:mainfrom
moritzknecht:main

Conversation

@moritzknecht

Copy link
Copy Markdown

This PR extends the Telegram bridge with several improvements that came up during real-world usage.

Inbound file support
Users can now send documents, photos, audio, voice messages, video and
stickers. Files are saved to disk at A0_UPLOAD_DIR before being forwarded
to the agent as an absolute path — avoiding the fragile base64-in-message
approach. Max file size is configurable via A0_MAX_FILE_BYTES (default 20 MB).

Outbound file support
When the agent saves a file and references it in its response, the bridge
now detects the path and sends it back as a native Telegram file. Supports
img://, file:// markdown links and backtick absolute paths.

Markdown rendering
Agent responses are converted from markdown to Telegram HTML before sending,
so formatting like bold, italic, code blocks and links renders correctly in
the chat instead of appearing as raw symbols.

User identity prefix
Each message to the agent is prefixed with [User: name | chat_id: id],
allowing the agent to address users by name and use the correct chat_id
in any proactive notification scripts it generates.

Request interruption
A new message now cancels any in-flight request for the same chat instead
of queuing behind it, preventing stale or out-of-order responses.

All changes are backwards compatible. New env variables (A0_UPLOAD_DIR,
A0_MAX_FILE_BYTES) are optional with sensible defaults.

Co-authored-by: Claude Sonnet 4.6 claude@anthropic.com

moritzknecht and others added 4 commits February 22, 2026 08:32
feat: add file support, markdown rendering, user identity, and request interruption

Inbound file handling
- Add handle_file handler covering documents, photos, audio, voice, video,
  video notes and stickers
- Download files from Telegram and save to disk at A0_UPLOAD_DIR before
  forwarding to the agent, avoiding base64-in-message approach
- Pass absolute file path to agent as [FILE name=... mime=... path=...] tag
- Skip files exceeding A0_MAX_FILE_BYTES (default 20 MB) with a warning

Outbound file handling
- Add extract_file_paths() to scan agent responses for file references
- Detect img://, file:// markdown links and bold/backtick absolute paths
- Send detected files back to user as native Telegram photo/video/audio/document
- Strip file reference markers from visible response text

Markdown rendering
- Add markdown_to_telegram() converting agent markdown to Telegram HTML
- Handles bold, italic, strikethrough, inline code, code blocks, headers, links
- Use parse_mode="HTML" instead of MarkdownV2 to avoid escaping issues
- Plain text fallback if HTML parsing fails

User identity prefix
- Prepend [User: <name> | chat_id: <id>] to every message sent to the agent
- Enables the agent to address users by name and use the correct chat_id
  in proactive notification scripts it generates

Request interruption
- Track active asyncio.Task per chat in active_tasks dict
- Cancel any in-flight request before processing a new message from the same chat
- Notify user with ⚡ confirmation on cancellation
- Each chat's task is independent; concurrent users are unaffected

Misc
- Add A0_UPLOAD_DIR and A0_MAX_FILE_BYTES env variables
- Show upload dir and max file size in /status and startup banner
… interruption

This PR extends the Telegram bridge with several improvements that came up
during real-world usage.

**Inbound file support**
Users can now send documents, photos, audio, voice messages, video and
stickers. Files are saved to disk at A0_UPLOAD_DIR before being forwarded
to the agent as an absolute path — avoiding the fragile base64-in-message
approach. Max file size is configurable via A0_MAX_FILE_BYTES (default 20 MB).

**Outbound file support**
When the agent saves a file and references it in its response, the bridge
now detects the path and sends it back as a native Telegram file. Supports
img://, file:// markdown links and backtick absolute paths.

**Markdown rendering**
Agent responses are converted from markdown to Telegram HTML before sending,
so formatting like bold, italic, code blocks and links renders correctly in
the chat instead of appearing as raw symbols.

**User identity prefix**
Each message to the agent is prefixed with [User: name | chat_id: id],
allowing the agent to address users by name and use the correct chat_id
in any proactive notification scripts it generates.

**Request interruption**
A new message now cancels any in-flight request for the same chat instead
of queuing behind it, preventing stale or out-of-order responses.

All changes are backwards compatible. New env variables (A0_UPLOAD_DIR,
A0_MAX_FILE_BYTES) are optional with sensible defaults.

Co-authored-by: Claude Sonnet 4.6 <claude@anthropic.com>
per user projects to isolate memories, files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant