2.1 KiB
2.1 KiB
Telegram Bot API Field Notes
1) Base URL and request style
- Base format:
https://api.telegram.org/bot<token>/<method> - Use GET or POST with JSON or form-encoded payloads.
- File uploads use
multipart/form-dataandattach://references.
2) Updates and delivery models
Long polling
getUpdatesdelivers updates with anoffsetcursor andtimeout.
Webhook
setWebhookswitches the bot to webhook mode.- Webhook URLs must be HTTPS. Check the official docs for port restrictions.
Update types (examples)
message,edited_message,channel_post,edited_channel_postinline_query,chosen_inline_result,callback_queryshipping_query,pre_checkout_query,poll,poll_answer
Use allowed_updates to limit which updates you receive.
3) High-traffic-safe patterns
- Use
allowed_updatesto reduce noise. - Keep handlers idempotent (Telegram may retry).
- Return quickly from webhooks; process heavy work async.
4) Common methods (non-exhaustive)
getMe,getUpdates,setWebhooksendMessage,editMessageText,deleteMessagesendPhoto,sendDocument,sendChatActionanswerCallbackQuery,answerInlineQuery
5) Common fields (non-exhaustive)
sendMessage
chat_id,text,parse_modeentities,disable_web_page_previewreply_markup(inline keyboard, reply keyboard)
reply_markup (inline keyboard)
inline_keyboard: array of button rows- Buttons can contain
text+callback_dataorurl
callback_query
id,from,message,data
sendChatAction
action:typing,upload_photo,upload_document,upload_video,choose_sticker
6) Command UX checklist
/start: greet, explain features, and show main commands./help: include short examples and support contact./settings: show toggles with inline keyboards./status: show recent job results or queue size.
7) Error handling
429: back off and retry.400: validate chat_id, message length, and formatting.403: bot blocked or chat not accessible.