The package provides a PSR-18 and PSR-17 compatible transport implementation for phptg/bot-api. It allows you to use any PSR-compliant HTTP client to make requests to the Telegram Bot API.
- PHP 8.2 - 8.5.
The package can be installed with Composer:
composer require phptg/transport-psrFirst, install a PSR-18 HTTP client and PSR-17 HTTP factories. For example, you can use php-http/curl-client and httpsoft/http-message:
composer require php-http/curl-client httpsoft/http-messageThen create an instance of PsrTransport and pass it to TelegramBotApi:
use Http\Client\Curl\Client;
use HttpSoft\Message\RequestFactory;
use HttpSoft\Message\ResponseFactory;
use HttpSoft\Message\StreamFactory;
use Phptg\BotApi\TelegramBotApi;
use Phptg\TransportPsr\PsrTransport;
$streamFactory = new StreamFactory();
$responseFactory = new ResponseFactory();
$requestFactory = new RequestFactory();
$client = new Client($responseFactory, $streamFactory);
$transport = new PsrTransport(
$client,
$requestFactory,
$streamFactory,
);
$api = new TelegramBotApi(
token: '110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw',
transport: $transport,
);
// Now you can use the API as usual
$api->sendMessage(
chatId: 123456789,
text: 'Hello from PSR transport!',
);PsrTransport constructor parameters:
$client— PSR-18 HTTP client;$requestFactory— PSR-17 HTTP request factory;$streamFactory— PSR-17 HTTP stream factory.
If you have any questions or problems with this package, use author telegram chat for communication.
The phptg/transport-psr is free software. It is released under the terms of the BSD License.
Please see LICENSE for more information.