Skip to content

phptg/transport-psr

PHPTG

PSR Transport for Telegram Bot API


Latest Stable Version Total Downloads Build status Coverage Status Mutation score Static analysis

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.

Requirements

  • PHP 8.2 - 8.5.

Installation

The package can be installed with Composer:

composer require phptg/transport-psr

General usage

First, 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-message

Then 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.

Documentation

If you have any questions or problems with this package, use author telegram chat for communication.

License

The phptg/transport-psr is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

About

PSR transport for Telegram Bot API

Topics

Resources

License

BSD-3-Clause, BSD-3-Clause licenses found

Licenses found

BSD-3-Clause
LICENSE
BSD-3-Clause
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published