This file is a practical reference for the public API of AsyncTelegram2 and the main helper types used by the library.
Header: src/AsyncTelegram2.h
AsyncTelegram2(Client &client, uint32_t bufferSize = BUFFER_BIG);
AsyncTelegram2(TelegramSecureClient &client, uint32_t bufferSize = BUFFER_BIG);Use the generic Client constructor for external transports such as SSLClient.
The secure-client overload is available for supported native ESP32 and ESP8266 secure clients and enables built-in insecure fallback support.
Starts the initial Telegram connection and loads bot information.
Call this after:
- network setup
- TLS setup
setTelegramToken()
Resets the connection state when the connection was lost.
Checks whether the connection is active and reconnects if required.
Usually you do not need to call this directly because message send/receive paths use it internally.
Sets the bot token.
Sets the polling interval in milliseconds.
Sets the default text formatting mode.
Available enum values:
AsyncTelegram2::NONEAsyncTelegram2::HTMLAsyncTelegram2::MARKDOWN
Changes the JSON buffer size used by the parser.
Useful when a command returns larger-than-usual JSON payloads.
Related constants from src/DataStructures.h:
BUFFER_SMALLBUFFER_MEDIUMBUFFER_BIG
Enables a retry path that switches a supported native secure client to insecure mode if the first TLS handshake fails.
Returns whether built-in insecure fallback is enabled.
Returns true when the current working connection is using the insecure fallback.
Registers a custom recovery callback invoked after a failed connection attempt.
Returns true when the last successful connection used the custom recovery path.
Returns the current ConnectionMode enum value.
Returns a printable string describing the active connection mode.
Fetches the first unread Telegram message and stores it in message.
Possible MessageType values are defined in src/DataStructures.h:
MessageNoDataMessageTextMessageQueryMessageLocationMessageContactMessageDocumentMessageReplyMessageNewMemberMessageLeftMemberMessageForwarded
Returns true if there are no more unread messages to process.
bool sendMessage(const TBMessage &msg, const char *message, char *keyboard = nullptr, bool wait = false);Overloads exist for:
StringInlineKeyboard &ReplyKeyboard &
Sends a direct message to a known user ID.
Requirement: the user must have started the bot at least once.
Sends a message to a Telegram channel.
Requirement: the bot must be an admin in that channel.
Forwards a Telegram message to another user or chat.
Supported patterns:
- photo by URL
- photo from
Stream - photo from filesystem if
FS.hsupport is available - photo from raw buffer
Sends a document from a Stream.
Document types:
ZIPPDFPHOTOANIMATIONAUDIOVOICEVIDEOCSVJSONTEXTBINARY
Sends an animation or GIF by URL.
Resolves a Telegram document ID into a downloadable file path and file metadata.
Closes a callback query triggered by an inline keyboard button.
Removes a reply keyboard for the target chat.
Registers an inline keyboard when you want button callbacks handled through the helper object.
Edits a previously sent message.
Overloads support:
- raw chat ID and message ID
TBMessage- keyboard update through
InlineKeyboard
Deletes a previously sent message.
Adds or updates a bot command.
Retrieves the current bot command list as JSON.
Clears all registered bot commands.
Registers a callback fired when the library verifies that a message was sent successfully.
Returns the bot username retrieved during initialization.
Header: src/DataStructures.h
struct TBUser {
bool isBot;
int64_t id;
String firstName;
String lastName;
String username;
};struct TBLocation {
float longitude;
float latitude;
};struct TBContact {
int64_t id;
String phoneNumber;
String firstName;
String lastName;
String vCard;
};struct TBDocument {
bool file_exists;
int32_t file_size;
String file_id;
String file_name;
String file_path;
};TBMessage is the main payload container returned by getNewMessage().
Important fields:
messageTypechatIdmessageIDtextsendermemberlocationcontactdocumentcallbackQueryIDcallbackQueryDatadisable_notificationforce_reply
See also Keyboards and Interactions.
Header: src/InlineKeyboard.h
Methods:
- constructor with optional buffer size
- constructor from existing JSON
getButtonsNumber()addRow()addButton()getJSON()getJSONPretty()clear()
Header: src/ReplyKeyboard.h
Methods:
- constructor with optional buffer size
addRow()addButton()enableResize()enableOneTime()enableSelective()getJSON()getJSONPretty()clear()