A lightweight and simple library for working with the Telegram Bot API, is under active development. But some methods are already available for work, see paragraph 3.
- PHP >= 7.2.5
composer require teh9/apigram
$client = \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
1. Messages
$chatId = 1;
$apigram = new \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
$response = $apigram->messages()->to($chatId)->send('text');
$response->getMessageId(); // Get message id
$chatId = 1;
$apigram = new \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
$response = $apigram->messages()->edit('TELEGRAM_CHAT_ID', 'MESSAGE_ID', 'lorem ipsum new text');
var_dump($response->getMessageText()); // lorem ipsum new text
2. Webhook
$webhookUrl = 'https://yourwebhook.net';
$apigram = new \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
$response = $apigram->webhook()->set($webhookUrl);
var_dump($response->status()); // true/false
$apigram = new \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
$response = $apigram->webhook()->remove();
var_dump($response->status()); // true/false
3. Bot
$apigram = new \Teh9\Apigram\Client\TelegramClient('BOT_API_TOKEN');
$response = $apigram->bot()->getMe();
var_dump($response->getId()); // Bot id
var_dump($response->getFirstName()); // Bot name
var_dump($response->getUserName()); // Bot login
4. Assets
$imagePath = 'https://i.imgur.com/SVm9n13_d.jpg';
$apigram = new TelegramClient(getenv('TELEGRAM_BOT_TOKEN'));
$response = $apigram->assets()->to(getenv('TELEGRAM_CHAT_ID'))->sendPhoto($imagePath);
// or
$response = $apigram->assets()->to(getenv('TELEGRAM_CHAT_ID'))->caption('test caption')->sendPhoto($imagePath);
var_dump($response->status());
var_dump($response->getMessageId());
The MIT License (MIT). Please see License File for more information.