Telegram Sender
Agent-facing guide for outbound Telegram communication.
Assumption: ANKA_TELEGRAM_BOT_TOKEN is already set in the environment.
Required Inputs
chat_id (required) — from inbound message metadata or config
- message content (required for send/edit)
- photo source (required for photo): local file path, HTTP(S) image URL, or Telegram
file_id
- photo caption (optional, max 1024 characters after Telegram entity parsing)
reply_to_message_id (optional, for threaded reply)
message_id (required for edit)
Execution Policy
- If handling a Telegram message and
message_id is known, prefer reply mode (--reply-to).
- If source metadata says sender is a bot (
sender_is_bot=true), do not use reply mode; use --source-is-bot --source-username <USERNAME> instead.
- For long-running tasks: send an acknowledgment first, then edit it with the final result.
- Use
photo when the response depends on an image artifact or generated picture.
- Prefer local file paths for newly generated images. Use a Telegram
file_id only when reusing a previously uploaded file.
- Keep content concise and action-oriented.
- Use literal newlines in message text and captions.
Active Response Policy
When this skill is in scope, prefer proactive and timely Telegram updates:
- Send immediate acknowledgment for newly assigned tasks
- Send progress updates for long-running operations using message edits
- Send completion notifications when work finishes
- Send failure notifications immediately with cause, impact, and next action
Recommended pattern:
- Send a short acknowledgment reply
- Continue processing
- Edit the acknowledgment with final result (or send a new update if edit fails)
Command Templates
Paths are relative to this skill directory.
# Send message
python ./scripts/telegram_send.py send \
--chat-id <CHAT_ID> \
--message "<TEXT>"
# Reply to a specific message
python ./scripts/telegram_send.py send \
--chat-id <CHAT_ID> \
--message "<TEXT>" \
--reply-to <MESSAGE_ID>
# Bot-source: no direct reply, use @username style
python ./scripts/telegram_send.py send \
--chat-id <CHAT_ID> \
--message "<TEXT>" \
--source-is-bot \
--source-username <USERNAME>
# Edit existing message
python ./scripts/telegram_send.py edit \
--chat-id <CHAT_ID> \
--message-id <MESSAGE_ID> \
--text "<TEXT>"
# Send photo from local path, URL, or Telegram file_id
python ./scripts/telegram_send.py photo \
--chat-id <CHAT_ID> \
--photo "<PATH_OR_URL_OR_FILE_ID>" \
--caption "<OPTIONAL_CAPTION>"
# Reply with a photo
python ./scripts/telegram_send.py photo \
--chat-id <CHAT_ID> \
--photo "<PATH_OR_URL_OR_FILE_ID>" \
--caption "<OPTIONAL_CAPTION>" \
--reply-to <MESSAGE_ID>
For actions not covered by this script, use curl to call Telegram Bot API directly:
https://api.telegram.org/bot$ANKA_TELEGRAM_BOT_TOKEN/<method>
Script Reference
telegram_send.py send
--chat-id, -c: required
--message, -m: required
--reply-to, -r: optional message ID
--token, -t: optional (normally not needed)
--source-is-bot: optional flag
--source-username: required when --source-is-bot is set
telegram_send.py edit
--chat-id, -c: required
--message-id, -i: required
--text, -x: required
--token, -t: optional (normally not needed)
telegram_send.py photo
--chat-id, -c: required
--photo, -p: required; local file path, HTTP(S) URL, or Telegram file_id
--caption, -m: optional caption; Markdown supported and converted to MarkdownV2
--reply-to, -r: optional message ID
--token, -t: optional (normally not needed)
--source-is-bot: optional flag
--source-username: required when --source-is-bot is set
Photo behavior:
- Local paths are uploaded with multipart/form-data.
- HTTP(S) URLs are downloaded to a temporary file and then uploaded, which avoids CDN
content-type issues that can make direct Telegram URL sends fail.
- Telegram
file_id values are sent directly to reuse an existing upload.
- Captions follow Telegram's
sendPhoto limit: 0-1024 characters after entity parsing.
Failure Handling
- On HTTP errors, inspect API response text and adjust identifiers/permissions.
- If edit fails (message not editable), fall back to a new send.
- If reply target is invalid, resend without
--reply-to.
- If photo upload fails, verify the file exists, the URL is publicly fetchable from the
current environment, or the
file_id belongs to this bot.
- For task-level failures, notify the user with what failed, what completed, and next steps.
1---2name: telegram-sender3description: Send and edit Telegram messages, and send photos via Bot API. Use when AnkaLoop needs to send text, reply to a specific message, edit an existing message, send an image, or push proactive notifications (cron results, heartbeat alerts, task status). Requires ANKA_TELEGRAM_BOT_TOKEN env var.4---56# Telegram Sender78Agent-facing guide for outbound Telegram communication.910Assumption: `ANKA_TELEGRAM_BOT_TOKEN` is already set in the environment.1112## Required Inputs1314- `chat_id` (required) — from inbound message metadata or config15- message content (required for send/edit)16- photo source (required for photo): local file path, HTTP(S) image URL, or Telegram `file_id`17- photo caption (optional, max 1024 characters after Telegram entity parsing)18- `reply_to_message_id` (optional, for threaded reply)19- `message_id` (required for edit)2021## Execution Policy22231. If handling a Telegram message and `message_id` is known, prefer reply mode (`--reply-to`).242. If source metadata says sender is a bot (`sender_is_bot=true`), do not use reply mode; use `--source-is-bot --source-username <USERNAME>` instead.253. For long-running tasks: send an acknowledgment first, then edit it with the final result.264. Use `photo` when the response depends on an image artifact or generated picture.275. Prefer local file paths for newly generated images. Use a Telegram `file_id` only when reusing a previously uploaded file.286. Keep content concise and action-oriented.297. Use literal newlines in message text and captions.3031## Active Response Policy3233When this skill is in scope, prefer proactive and timely Telegram updates:3435- Send immediate acknowledgment for newly assigned tasks36- Send progress updates for long-running operations using message edits37- Send completion notifications when work finishes38- Send failure notifications immediately with cause, impact, and next action3940Recommended pattern:41421. Send a short acknowledgment reply432. Continue processing443. Edit the acknowledgment with final result (or send a new update if edit fails)4546## Command Templates4748Paths are relative to this skill directory.4950```bash51# Send message52python ./scripts/telegram_send.py send \53 --chat-id <CHAT_ID> \54 --message "<TEXT>"5556# Reply to a specific message57python ./scripts/telegram_send.py send \58 --chat-id <CHAT_ID> \59 --message "<TEXT>" \60 --reply-to <MESSAGE_ID>6162# Bot-source: no direct reply, use @username style63python ./scripts/telegram_send.py send \64 --chat-id <CHAT_ID> \65 --message "<TEXT>" \66 --source-is-bot \67 --source-username <USERNAME>6869# Edit existing message70python ./scripts/telegram_send.py edit \71 --chat-id <CHAT_ID> \72 --message-id <MESSAGE_ID> \73 --text "<TEXT>"7475# Send photo from local path, URL, or Telegram file_id76python ./scripts/telegram_send.py photo \77 --chat-id <CHAT_ID> \78 --photo "<PATH_OR_URL_OR_FILE_ID>" \79 --caption "<OPTIONAL_CAPTION>"8081# Reply with a photo82python ./scripts/telegram_send.py photo \83 --chat-id <CHAT_ID> \84 --photo "<PATH_OR_URL_OR_FILE_ID>" \85 --caption "<OPTIONAL_CAPTION>" \86 --reply-to <MESSAGE_ID>87```8889For actions not covered by this script, use `curl` to call Telegram Bot API directly:90`https://api.telegram.org/bot$ANKA_TELEGRAM_BOT_TOKEN/<method>`9192## Script Reference9394### `telegram_send.py send`9596- `--chat-id`, `-c`: required97- `--message`, `-m`: required98- `--reply-to`, `-r`: optional message ID99- `--token`, `-t`: optional (normally not needed)100- `--source-is-bot`: optional flag101- `--source-username`: required when `--source-is-bot` is set102103### `telegram_send.py edit`104105- `--chat-id`, `-c`: required106- `--message-id`, `-i`: required107- `--text`, `-x`: required108- `--token`, `-t`: optional (normally not needed)109110### `telegram_send.py photo`111112- `--chat-id`, `-c`: required113- `--photo`, `-p`: required; local file path, HTTP(S) URL, or Telegram `file_id`114- `--caption`, `-m`: optional caption; Markdown supported and converted to MarkdownV2115- `--reply-to`, `-r`: optional message ID116- `--token`, `-t`: optional (normally not needed)117- `--source-is-bot`: optional flag118- `--source-username`: required when `--source-is-bot` is set119120Photo behavior:121122- Local paths are uploaded with multipart/form-data.123- HTTP(S) URLs are downloaded to a temporary file and then uploaded, which avoids CDN124 content-type issues that can make direct Telegram URL sends fail.125- Telegram `file_id` values are sent directly to reuse an existing upload.126- Captions follow Telegram's `sendPhoto` limit: 0-1024 characters after entity parsing.127128## Failure Handling129130- On HTTP errors, inspect API response text and adjust identifiers/permissions.131- If edit fails (message not editable), fall back to a new send.132- If reply target is invalid, resend without `--reply-to`.133- If photo upload fails, verify the file exists, the URL is publicly fetchable from the134 current environment, or the `file_id` belongs to this bot.135- For task-level failures, notify the user with what failed, what completed, and next steps.