Sending Messages¶
The most common thing a bot does is send text. In TBL that's one call:
No chat_id unless you're deliberately sending somewhere else. TBL uses the chat where the command was triggered.
Formatting¶
Telegram supports Markdown and HTML in messages. Pick one with parse_mode:
Keep formatting simple. Unclosed bold markers or nested styles are the usual reason a message fails to send. If a formatted message keeps erroring, strip the markup and add it back piece by piece.
Sending to a different chat¶
Sometimes you need to notify an admin channel or message a user from a background command:
Only do this when you're sure the bot can post in that chat — it's a member of the group, hasn't been blocked by the user, etc. Telegram will reject the call otherwise, and by default that rejection lands in your error logs rather than crashing the command.
Silent sends¶
Pass disable_notification: true if the message shouldn't buzz the user's phone:
Useful for admin alerts in busy groups.
Getting a handle on the message¶
If your next line needs to edit or delete what you just sent, await the call:
See Method Chaining for everything you can do with that returned object.
Handing off to another command¶
When the response matters but you don't want the rest of the logic in this command:
The afterGetChat command receives Telegram's response in options. Callbacks covers that pattern properly.
Everything else Telegram supports¶
Api.sendMessage accepts any parameter the Telegram Bot API documents — reply markup, link previews, protected content, message threading in groups, the lot.
If you need buttons under the message, read Inline Keyboards. For files and media, Media and Files.