Makarski Bot Connector for Telegram provides a clean foundation for building Telegram bots powered by WordPress. It handles all the low-level communication with the Telegram Bot API so you can focus on your bot’s logic.
register_bot_command()tgbot_message fires for all message types (text, photo, voice, video, document, callback_query) with a consistent object structuresend_message, `send_markdown_message`, `send_photo`, `send_document`, `send_audio`, `send_voice`, `send_video`, `send_animation`, `send_chat_action`, `send_location`, `send_stars_invoice`, `forward_message`, `copy_message`, `delete_message`, `delete_messages`, `edit_message`, `edit_message_markup`, `answer_callback_query`, `answer_pre_checkout_query`, `set_my_commands`, `set_webhook`, `delete_webhook`, `get_webhook_info`, `get_updates`, `get_document_url`, `get_photo_url`, `refund_star_payment`
tgbot_message (primary hook)
Fires for every non-command incoming message (text, media, callback_query).
add_action( 'tgbot_message', function( $bot, $user_id, $message ) {
// $message->type — 'text' | 'image' | 'voice' | 'video' | 'audio'
// | 'document' | 'sticker' | 'video_note' | 'callback_query'
// $message->text — message text, caption, or callback data
// $message->files — array of WP attachment IDs (downloaded files)
// $message->has_media_group — true if part of a multi-file album
// $message->media_group_id — Telegram media_group_id string
if ( $message->type === 'voice' ) {
$bot->send_message( 'Got a voice message!' );
}
}, 10, 3 );
tgbot_handle_custom_bot_commands
Fires when a slash command is received, before the built-in dispatcher.
add_action( 'tgbot_handle_custom_bot_commands', function( $bot, $user_id, $command ) {
// $command — e.g. '/mycommand'
}, 10, 3 );
tgbot_bot_call
Fires for every incoming update, including commands. Useful for cross-cutting concerns.
tgbot_pre_checkout_query
Fires when a Telegram Stars pre-checkout query arrives.
add_action( 'tgbot_pre_checkout_query', function( $bot, $query, $user_id ) {
$bot->answer_pre_checkout_query( $query->id, true );
}, 10, 3 );
tgbot_successful_payment
Fires after a successful Telegram Stars payment.
add_action( 'tgbot_successful_payment', function( $bot, $payment, $user_id ) {
// $payment->telegram_payment_charge_id — use for refunds
// $payment->total_amount — amount in Stars
}, 10, 3 );
tgbot_raw_message
Fires with the raw Telegram update object for advanced use cases.
Use TGBot\register_bot_command() inside an init hook:
add_action( 'init', function() {
TGBot\register_bot_command( 'hello', function( $bot ) {
$bot->send_message( 'Hello, ' . $bot->chat_id . '!' );
} );
TGBot\register_bot_command( 'ping', function( $bot ) {
$bot->send_message( 'Pong 🏓' );
} );
} );
add_action( 'init', function() {
TGBot\register_bot_command( 'start', function( $bot ) {
$bot->send_message( 'Welcome!' );
} );
} );
add_action( 'tgbot_message', function( $bot, $user_id, $msg ) {
if ( $msg->type === 'text' ) {
$bot->send_message( 'You said: ' . esc_html( $msg->text ) );
}
}, 10, 3 );
This plugin communicates with the Telegram Bot API (api.telegram.org) to operate a Telegram bot connected to your WordPress site.
What the service is: Telegram Bot API is a third-party service by Telegram FZ-LLC that allows applications to send and receive messages through Telegram bots.
What data is sent and when:
* Bot token — sent with every API request to authenticate the bot.
* Chat ID — sent when delivering messages to a specific user.
* Message text and media files — sent when the bot responds to users.
* Incoming updates (messages, commands, files) — received from Telegram via webhook (HTTP POST from Telegram to your site) or polling (your site requests updates from Telegram periodically via WP-Cron).
No data is sent to Telegram unless the bot is enabled and a valid token is configured.
Telegram Privacy Policy: https://telegram.org/privacy
Telegram Terms of Service: https://telegram.org/tos