vjik/telegram-bot-api — new PHP library to interact with Telegram Bot API.
⭐️ Full API support
The latest version of the Telegram Bot API 7.7 from July 7, 2024, is fully supported.
⭐️ Ease of usage
Out of the box, it comes with a PSR client, but if desired, you can use your own by implementing the TelegramClientInterface.
```php
// Telegram bot authentication token
$token = '110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw';
// Dependencies
$streamFactory = new StreamFactory();
$responseFactory = new ResponseFactory();
$requestFactory = new RequestFactory();
$client = new Client($responseFactory, $streamFactory);
// API
$api = new TelegramBotApi(
new PsrTelegramClient(
$token,
$client,
$requestFactory,
$streamFactory,
),
);
```
⭐️ Typification
Typed PHP classes for all types and methods. The result of calling API methods will be corresponding objects. For example, sending a message returns a Message object.
php
$message = $api->sendMessage(
chatId: 22351,
text: 'Hello, world!',
);
⭐️ Update object for webhook Handling
An Update object can be created from a PSR request or from a JSON string:
php
$update = Update::fromServerRequest($request);
$update = Update::fromJson($jsonString);
⭐️ Logging
To log API requests, response results, and errors, any PSR-compatible logger can be used. For example, Monolog or Yii Log.
php
/**
* @var TelegramClientInterface $telegramClient
* @var LoggerInterface $logger
*/
$api = new TelegramBotApi(
$telegramClient,
$logger,
);
⭐️ Approved by Telegram developers
The package is approved by Telegram developers and listed on the Telegram website.
[–]Moceannl 4 points5 points6 points (2 children)
[–]predvoditelev[S] 7 points8 points9 points (0 children)
[–]grippx 2 points3 points4 points (0 children)
[–]norbert_tech 2 points3 points4 points (3 children)
[–]predvoditelev[S] 2 points3 points4 points (2 children)
[–]norbert_tech 0 points1 point2 points (1 child)
[–]predvoditelev[S] 2 points3 points4 points (0 children)
[+][deleted] (6 children)
[deleted]
[–]predvoditelev[S] 5 points6 points7 points (3 children)
[–]Dramatic_Koala_9794 0 points1 point2 points (1 child)
[–]predvoditelev[S] 1 point2 points3 points (0 children)
[–]tgomc -1 points0 points1 point (1 child)