Telegram
Interact with Telegram using the Bot API.
Setup
-
Check existing credentials:
vault_get telegram_bot_token -
If not configured:
- Talk to @BotFather on Telegram
- Send
/newbotand follow instructions - Copy the bot token
- Save to vault:
vault_save telegram_bot_token "123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
The token is auto-injected as
$TELEGRAM_BOT_TOKEN.
Get Chat ID
# Send a message to your bot first, then:
curl -s "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/getUpdates" | jq '.result[-1].message.chat.id'
# For groups/channels, add bot as admin and send a message
Send Messages
# Send text message
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
-H "Content-Type: application/json" \
-d '{"chat_id": "CHAT_ID", "text": "Hello from DevClaw!"}'
# Markdown formatting
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
-H "Content-Type: application/json" \
-d '{
"chat_id": "CHAT_ID",
"text": "*Bold* _italic_ `code`",
"parse_mode": "MarkdownV2"
}'
# HTML formatting
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
-H "Content-Type: application/json" \
-d '{
"chat_id": "CHAT_ID",
"text": "<b>Bold</b> <i>italic</i> <code>code</code>",
"parse_mode": "HTML"
}'
Send Photos & Files
# Send photo by URL
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendPhoto" \
-H "Content-Type: application/json" \
-d '{"chat_id": "CHAT_ID", "photo": "https://example.com/image.png"}'
# Send document
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendDocument" \
-F "chat_id=CHAT_ID" \
-F "document=@/path/to/file.pdf"
Interactive Messages
# Message with inline keyboard buttons
curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
-H "Content-Type: application/json" \
-d '{
"chat_id": "CHAT_ID",
"text": "Choose an option:",
"reply_markup": {
"inline_keyboard": [
[{"text": "Yes", "callback_data": "yes"}, {"text": "No", "callback_data": "no"}]
]
}
}'
Get Updates (Polling)
# Get new messages
curl -s "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/getUpdates?offset=-1" | jq '.result'
# Get all pending updates
curl -s "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/getUpdates" | jq '.result[]'
Tips
- Chat ID for users: positive number (e.g., 123456789)
- Chat ID for groups: negative number (e.g., -100123456789)
- Channel posts need
@channelnameor channel ID - Use
parse_mode: "MarkdownV2"for rich formatting - Escape special chars in MarkdownV2: _ * [ ] ( ) ~ ` > # + - = | { } . !
Triggers
telegram, send telegram message, telegram bot, telegram notification, notify telegram, tg message
