Telegram Bot Integration
Role
You help the user send and receive Telegram messages through a Telegram Bot. All API calls go through the http tool using the Telegram Bot API.
Keywords: "telegram", "send telegram", "TG", "電報", "傳訊息到Telegram"
Setup
The user needs a Telegram Bot token:
- Open Telegram and message @BotFather
- Send
/newbot and follow the prompts to create a bot
- Copy the bot token (format:
123456789:ABCdefGhIjKlMnOpQrStUvWxYz)
- Configure the token in MobileClaw Settings > API Keys > Telegram
- The user must start a conversation with their bot (send
/start) before the bot can message them
- To find the user's chat_id, use the getUpdates workflow below after sending
/start to the bot
API Configuration
- Base URL:
https://api.telegram.org/bot{BOT_TOKEN}
- Most read operations use GET with query parameters
- Send operations can use GET (simple) or POST with JSON body (complex)
- No extra auth headers needed — the token is in the URL
Standard Workflows
Get Chat ID (First-Time Setup)
The user needs their chat_id to receive messages.
- Ask the user to open Telegram and send any message to their bot
- Fetch updates:
http GET https://api.telegram.org/bot{TOKEN}/getUpdates
- Parse the response:
result[0].message.chat.id is the chat_id
- Store this chat_id for future use (tell user to note it in Settings)
Send a Text Message
- Simple message via GET:
http GET https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={CHAT_ID}&text=Hello%20from%20MobileClaw&parse_mode=Markdown
- For longer or formatted messages, use POST:
http POST https://api.telegram.org/bot{TOKEN}/sendMessage
Headers: Content-Type: application/json
Body: {
"chat_id": "{CHAT_ID}",
"text": "*Bold title*\n\nMessage body with _italic_ and `code`",
"parse_mode": "Markdown",
"disable_web_page_preview": true
}
- Confirm success: response contains
ok: true and the sent message object
Send a Message with Buttons
Interactive inline keyboard for quick replies.
- Use http tool:
http POST https://api.telegram.org/bot{TOKEN}/sendMessage
Headers: Content-Type: application/json
Body: {
"chat_id": "{CHAT_ID}",
"text": "Choose an option:",
"reply_markup": {
"inline_keyboard": [
[
{"text": "Option A", "callback_data": "opt_a"},
{"text": "Option B", "callback_data": "opt_b"}
],
[
{"text": "Open Link", "url": "https://example.com"}
]
]
}
}
Get Recent Messages (Updates)
Check for new incoming messages.
- Basic fetch:
http GET https://api.telegram.org/bot{TOKEN}/getUpdates?limit=10
- To get only new messages since last check, use offset:
http GET https://api.telegram.org/bot{TOKEN}/getUpdates?offset={last_update_id + 1}&limit=10
- Parse each update:
update.message.text for text, update.message.from.first_name for sender
- Present messages to user in chronological order
Send a Photo
- Send photo by URL:
http POST https://api.telegram.org/bot{TOKEN}/sendPhoto
Headers: Content-Type: application/json
Body: {
"chat_id": "{CHAT_ID}",
"photo": "https://example.com/image.jpg",
"caption": "Check out this photo!"
}
- For local files, use multipart form data:
http POST https://api.telegram.org/bot{TOKEN}/sendPhoto
Content-Type: multipart/form-data
Form fields: chat_id={CHAT_ID}, photo=@/path/to/photo.jpg, caption=Photo caption
Send a Document/File
- By URL:
http POST https://api.telegram.org/bot{TOKEN}/sendDocument
Headers: Content-Type: application/json
Body: {
"chat_id": "{CHAT_ID}",
"document": "https://example.com/report.pdf",
"caption": "Here is the report"
}
Send Location
- Share a GPS location:
http POST https://api.telegram.org/bot{TOKEN}/sendLocation
Headers: Content-Type: application/json
Body: {
"chat_id": "{CHAT_ID}",
"latitude": 25.0330,
"longitude": 121.5654
}
Forward a Message
- Forward from one chat to another:
http POST https://api.telegram.org/bot{TOKEN}/forwardMessage
Headers: Content-Type: application/json
Body: {
"chat_id": "{TARGET_CHAT_ID}",
"from_chat_id": "{SOURCE_CHAT_ID}",
"message_id": {MESSAGE_ID}
}
Guidelines
- Always URL-encode text in GET query parameters (spaces as %20, newlines as %0A)
- Markdown parse_mode supports: bold, italic,
code, pre, link
- For MarkdownV2, escape special chars: _ * [ ] ( ) ~ ` > # + - = | { } . !
- Bot can only message users who have started a conversation with it first
- Rate limit: ~30 messages/second to the same chat, ~20 messages/minute to the same group
- Messages over 4096 characters must be split into multiple messages
- If sending fails with 403, the user likely blocked the bot or hasn't started it
- Always confirm before sending messages on behalf of the user
1---2name: telegram3description: Send and receive Telegram messages via Bot API4---5# Telegram Bot Integration6## Role7You help the user send and receive Telegram messages through a Telegram Bot. All API calls go through the http tool using the Telegram Bot API.8Keywords: "telegram", "send telegram", "TG", "電報", "傳訊息到Telegram"9## Setup10The user needs a Telegram Bot token:111. Open Telegram and message @BotFather122. Send `/newbot` and follow the prompts to create a bot133. Copy the bot token (format: `123456789:ABCdefGhIjKlMnOpQrStUvWxYz`)144. Configure the token in MobileClaw Settings > API Keys > Telegram155. The user must start a conversation with their bot (send `/start`) before the bot can message them166. To find the user's chat_id, use the getUpdates workflow below after sending `/start` to the bot17## API Configuration18- Base URL: `https://api.telegram.org/bot{BOT_TOKEN}`19- Most read operations use GET with query parameters20- Send operations can use GET (simple) or POST with JSON body (complex)21- No extra auth headers needed — the token is in the URL22## Standard Workflows23### Get Chat ID (First-Time Setup)24The user needs their chat_id to receive messages.251. Ask the user to open Telegram and send any message to their bot262. Fetch updates:27 ```28 http GET https://api.telegram.org/bot{TOKEN}/getUpdates29 ```303. Parse the response: `result[0].message.chat.id` is the chat_id314. Store this chat_id for future use (tell user to note it in Settings)32### Send a Text Message331. Simple message via GET:34 ```35 http GET https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={CHAT_ID}&text=Hello%20from%20MobileClaw&parse_mode=Markdown36 ```372. For longer or formatted messages, use POST:38 ```39 http POST https://api.telegram.org/bot{TOKEN}/sendMessage40 Headers: Content-Type: application/json41 Body: {42 "chat_id": "{CHAT_ID}",43 "text": "*Bold title*\n\nMessage body with _italic_ and `code`",44 "parse_mode": "Markdown",45 "disable_web_page_preview": true46 }47 ```483. Confirm success: response contains `ok: true` and the sent message object49### Send a Message with Buttons50Interactive inline keyboard for quick replies.511. Use http tool:52 ```53 http POST https://api.telegram.org/bot{TOKEN}/sendMessage54 Headers: Content-Type: application/json55 Body: {56 "chat_id": "{CHAT_ID}",57 "text": "Choose an option:",58 "reply_markup": {59 "inline_keyboard": [60 [61 {"text": "Option A", "callback_data": "opt_a"},62 {"text": "Option B", "callback_data": "opt_b"}63 ],64 [65 {"text": "Open Link", "url": "https://example.com"}66 ]67 ]68 }69 }70 ```71### Get Recent Messages (Updates)72Check for new incoming messages.731. Basic fetch:74 ```75 http GET https://api.telegram.org/bot{TOKEN}/getUpdates?limit=1076 ```772. To get only new messages since last check, use offset:78 ```79 http GET https://api.telegram.org/bot{TOKEN}/getUpdates?offset={last_update_id + 1}&limit=1080 ```813. Parse each update: `update.message.text` for text, `update.message.from.first_name` for sender824. Present messages to user in chronological order83### Send a Photo841. Send photo by URL:85 ```86 http POST https://api.telegram.org/bot{TOKEN}/sendPhoto87 Headers: Content-Type: application/json88 Body: {89 "chat_id": "{CHAT_ID}",90 "photo": "https://example.com/image.jpg",91 "caption": "Check out this photo!"92 }93 ```942. For local files, use multipart form data:95 ```96 http POST https://api.telegram.org/bot{TOKEN}/sendPhoto97 Content-Type: multipart/form-data98 Form fields: chat_id={CHAT_ID}, photo=@/path/to/photo.jpg, caption=Photo caption99 ```100### Send a Document/File1011. By URL:102 ```103 http POST https://api.telegram.org/bot{TOKEN}/sendDocument104 Headers: Content-Type: application/json105 Body: {106 "chat_id": "{CHAT_ID}",107 "document": "https://example.com/report.pdf",108 "caption": "Here is the report"109 }110 ```111### Send Location1121. Share a GPS location:113 ```114 http POST https://api.telegram.org/bot{TOKEN}/sendLocation115 Headers: Content-Type: application/json116 Body: {117 "chat_id": "{CHAT_ID}",118 "latitude": 25.0330,119 "longitude": 121.5654120 }121 ```122### Forward a Message1231. Forward from one chat to another:124 ```125 http POST https://api.telegram.org/bot{TOKEN}/forwardMessage126 Headers: Content-Type: application/json127 Body: {128 "chat_id": "{TARGET_CHAT_ID}",129 "from_chat_id": "{SOURCE_CHAT_ID}",130 "message_id": {MESSAGE_ID}131 }132 ```133## Guidelines134- Always URL-encode text in GET query parameters (spaces as %20, newlines as %0A)135- Markdown parse_mode supports: *bold*, _italic_, `code`, ```pre```, [link](url)136- For MarkdownV2, escape special chars: _ * [ ] ( ) ~ ` > # + - = | { } . !137- Bot can only message users who have started a conversation with it first138- Rate limit: ~30 messages/second to the same chat, ~20 messages/minute to the same group139- Messages over 4096 characters must be split into multiple messages140- If sending fails with 403, the user likely blocked the bot or hasn't started it141- Always confirm before sending messages on behalf of the user