An extended native Telegram Bot API in PHP without requirements. Supports all methods and types of responses.
composer require steadfast/telegram-bot-api
How to send message:
use TelegramBot\Api\BotApi;
$bot = new BotApi($bot_api_token);
$bot->sendMessage($chat_id, $message_text);
To handle commands:
use TelegramBot\Api\Client;
$bot = new Client($bot_api_token);
$bot->command('ping', function ($message) use ($bot) {
$bot->sendMessage($message->getChat()->getId(), 'pong!');
});
To handle an event when the bot was added to a group:
use TelegramBot\Api\Client;
$bot = new Client($bot_api_token);
$bot->wasAddedToAGroup(function ($message) use ($bot) {
$bot->sendMessage($message->getChat()->getId(), "Let's welcome our new member!");
});
To handle an event when the bot was removed from a group:
use TelegramBot\Api\Client;
$bot = new Client($bot_api_token);
$bot->wasRemovedFromAGroup(function ($message) use ($bot) {
$bot->sendMessage($message->getChat()->getId(), "Say goodbye to our friend!");
});
To handle any events:
use TelegramBot\Api\Client;
$bot = new Client($bot_api_token);
$bot->on(function ($update) {
echo $update->getUpdateId();
});