feat: add file support, markdown rendering, user identity and request interruption - #2
Open
moritzknecht wants to merge 4 commits into
Open
feat: add file support, markdown rendering, user identity and request interruption#2moritzknecht wants to merge 4 commits into
moritzknecht wants to merge 4 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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