steadfast / telegram-bot-api
Telegram Bot API written in PHP
2.3.0
2018-09-24 21:26 UTC
Requires
- php: >=5.5.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-10-25 11:59:25 UTC
README
An extended native Telegram Bot API in PHP without requirements. Supports all methods and types of responses.
Installation
composer require steadfast/telegram-bot-api
Client usage
How to send message:
use TelegramBot\Api\BotApi; $bot = new BotApi($bot_api_token); $bot->sendMessage($chat_id, $message_text);
Server usage
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(); });