Skip to content

feat: add file/photo sending to Telegram bot#23

Open
Fenrur wants to merge 1 commit intomoazbuilds:masterfrom
Fenrur:feature/telegram-file-sending
Open

feat: add file/photo sending to Telegram bot#23
Fenrur wants to merge 1 commit intomoazbuilds:masterfrom
Fenrur:feature/telegram-file-sending

Conversation

@Fenrur
Copy link
Copy Markdown

@Fenrur Fenrur commented Mar 11, 2026

Summary

  • Adds [file:/path/to/file] directive support in Claude's responses to send local files via Telegram
  • Images (png, jpg, jpeg, gif, webp) are sent via sendPhoto API; all other files via sendDocument API
  • Uses Bun's native FormData and Blob — zero new dependencies
  • Graceful error handling: if a file doesn't exist or upload fails, sends an error message to the chat instead of crashing

How it works

When Claude includes [file:/absolute/path/to/file.png] in its response:

  1. The directive is extracted and stripped from the displayed text
  2. The file extension determines whether to use sendPhoto or sendDocument
  3. The file is uploaded via multipart/form-data to the Telegram Bot API
  4. The remaining text is sent as a normal message

Functions added

  • sendPhotoFile() — uploads an image via Telegram's sendPhoto endpoint
  • sendFileDocument() — uploads any file via Telegram's sendDocument endpoint
  • sendLocalFile() — auto-routes to photo or document based on extension
  • extractFileDirectives() — parses [file:/path] patterns from response text

Test plan

  • Send a message that triggers Claude to respond with [file:/path/to/image.png] → image is sent as photo
  • Send a message with [file:/path/to/doc.pdf] → file is sent as document
  • Test with a non-existent path → error message sent gracefully
  • Test with multiple [file:...] directives in one response
  • Verify remaining text is still sent correctly after directives are stripped
  • Verify existing functionality (reactions, typing, etc.) is unchanged

🤖 Generated with Claude Code

Add support for sending local files and photos via Telegram using
[file:/path/to/file] directives in Claude's response text.

- sendPhotoFile(): sends images (png, jpg, jpeg, gif, webp) via sendPhoto API
- sendFileDocument(): sends any other file via sendDocument API
- sendLocalFile(): auto-detects image vs document based on extension
- extractFileDirectives(): parses [file:/absolute/path] patterns from response
- File directives are stripped from displayed text before sending
- Errors (file not found, upload failure) send a user-friendly error message
- Uses Bun's native FormData and Blob APIs, no external dependencies

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fenrur added a commit to Fenrur/claudeclaw that referenced this pull request Mar 13, 2026
- Add [file:/path] directive extraction from Claude responses
- Send images via sendPhoto, other files via sendDocument
- Export sendLocalFile, sendPhotoFile, sendFileDocument

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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