Using the Api Instance¶
This page shows simple examples of using the Api instance.
All examples assume the command is already running and the Api instance is already available.
Api.sendMessage¶
Used to send text messages to a chat.
Simple Message¶
This sends a message to the current chat (the chat where the command was triggered).
Tip
You usually donβt need to pass chat_id.
Api automatically knows which chat to reply to.
Message with Formatting¶
Telegram Markdown can be used to format text such as bold, italic, and inline code.
Tip
Keep formatting simple to avoid Telegram Markdown parsing issues.
Message with Inline Buttons¶
Api.sendMessage({
text: "Choose an option below:",
reply_markup: {
inline_keyboard: [
[{ text: "Visit Website", url: "https://telebothost.com" }],
[{ text: "Help", callback_data: "help" }]
]
}
})
Inline buttons let users interact with your bot without typing messages.
Api.sendPhoto¶
Used to send images to a chat.
Send a Photo with Caption¶
Api.sendPhoto({
photo: "https://images.pexels.com/photos/1108099/pexels-photo-1108099.jpeg",
caption: "Cute dog π"
})
This photo is sent to the current chat by default.
Tip
You can use URLs or file IDs for the photo field.
Using chat_id Explicitly¶
By default, Api methods send messages to the current chat.
If you want to send a message to a different chat, you can pass chat_id manually.
Warning
Only use explicit chat_id when you are sure the bot has access to that chat.
Telegram API Reference¶
The Api instance supports all methods available in the Telegram Bot API.
To see all possible methods and options, refer to the official Telegram documentation:
Any method listed there can be used in TBL as:
Api.methodName({ ... })
Summary¶
- Api methods accept an object as input
- Messages are sent to the current chat by default
chat_idcan be passed explicitly if needed- Formatting and buttons are supported
- Api directly maps to Telegram Bot API methods