PHPackages                             phptg/transport-psr - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. phptg/transport-psr

ActiveLibrary[API Development](/categories/api)

phptg/transport-psr
===================

PSR Transport for Telegram Bot API

0.3.1(1mo ago)11021BSD-3-ClausePHPPHP 8.2 - 8.5CI passing

Since Jan 24Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/phptg/transport-psr)[ Packagist](https://packagist.org/packages/phptg/transport-psr)[ Fund](https://boosty.to/vjik)[ Fund](https://pay.cloudtips.ru/p/192ce69b)[ RSS](/packages/phptg-transport-psr/feed)WikiDiscussions master Synced today

READMEChangelog (7)Dependencies (36)Versions (14)Used By (0)

 [ ![PHPTG](logo.png) ](https://github.com/phptg)PSR Transport for Telegram Bot API
==================================

[](#psr-transport-for-telegram-bot-api)

[![Latest Stable Version](https://camo.githubusercontent.com/6bc41ef19966728c4dd263b2229a7b739ba80d7f13b83f97a5a492232b443f9a/68747470733a2f2f706f7365722e707567782e6f72672f70687074672f7472616e73706f72742d7073722f76)](https://packagist.org/packages/phptg/transport-psr)[![Total Downloads](https://camo.githubusercontent.com/b1dd3d4f7c2da246533a67787a8741c1e7c37c7f76c45249dd265ae7bb05d6b5/68747470733a2f2f706f7365722e707567782e6f72672f70687074672f7472616e73706f72742d7073722f646f776e6c6f616473)](https://packagist.org/packages/phptg/transport-psr)[![Build status](https://github.com/phptg/transport-psr/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/phptg/transport-psr/actions/workflows/build.yml?query=branch%3Amaster)[![Coverage Status](https://camo.githubusercontent.com/4423558982e59ea374d3407fdf3aad321629a7ef073e403ecd4b1cbb969cf3a4/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f70687074672f7472616e73706f72742d7073722f62616467652e737667)](https://coveralls.io/github/phptg/transport-psr)[![Mutation score](https://camo.githubusercontent.com/49fe0358dd1f51dca86381dd5d07b50347a641fba913e1ed6035d57c1e44d7d2/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d25324670687074672532467472616e73706f72742d7073722532466d6173746572)](https://dashboard.stryker-mutator.io/reports/github.com/phptg/transport-psr/master)[![Static analysis](https://github.com/phptg/transport-psr/actions/workflows/psalm.yml/badge.svg?branch=master)](https://github.com/phptg/transport-psr/actions/workflows/psalm.yml?query=branch%3Amaster)

The package provides for [phptg/bot-api](https://github.com/phptg/bot-api):

- `PsrTransport` — [PSR-18](https://www.php-fig.org/psr/psr-18/) and [PSR-17](https://www.php-fig.org/psr/psr-17/)compatible transport implementation;
- `PsrWebhookResponseFactory` — [PSR-7](https://www.php-fig.org/psr/psr-7/) webhook response factory;
- `PsrUpdateFactory` — factory for creating `Update` objects from [PSR-7](https://www.php-fig.org/psr/psr-7/) server requests.

It allows you to use any PSR-compliant HTTP client to make requests to the Telegram Bot API.

Important

This project is developed and maintained by [Sergei Predvoditelev](https://github.com/vjik). Community support helps keep the project actively developed and well maintained. You can support the project using the following services:

- [Boosty](https://boosty.to/vjik)
- [CloudTips](https://pay.cloudtips.ru/p/192ce69b)

Thank you for your support ❤️

Requirements
------------

[](#requirements)

- PHP 8.2 - 8.5.

Installation
------------

[](#installation)

The package can be installed with [Composer](https://getcomposer.org/download/):

```
composer require phptg/transport-psr
```

General usage
-------------

[](#general-usage)

First, install a PSR-18 HTTP client and PSR-17 HTTP factories. For example, you can use [php-http/curl-client](https://github.com/php-http/curl-client)and [httpsoft/http-message](https://github.com/httpsoft/http-message):

```
composer require php-http/curl-client httpsoft/http-message
```

### PSR transport

[](#psr-transport)

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.

### PSR webhook response factory

[](#psr-webhook-response-factory)

The `PsrWebhookResponseFactory` creates PSR-7 compliant HTTP responses for webhook handlers:

```
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Phptg\BotApi\Method\SendMessage;
use Phptg\BotApi\WebhookResponse\PsrWebhookResponseFactory;
use Phptg\BotApi\WebhookResponse\WebhookResponse;

/**
 * @var ResponseFactoryInterface $responseFactory
 * @var StreamFactoryInterface $streamFactory
 */

$factory = new PsrWebhookResponseFactory($responseFactory, $streamFactory);

// Create response from WebhookResponse object
$webhookResponse = new WebhookResponse(new SendMessage(chatId: 12345, text: 'Hello!'));
$response = $factory->create($webhookResponse);

// Or create response directly from method, if you are sure that InputFile is not used
$method = new SendMessage(chatId: 12345, text: 'Hello!');
$response = $factory->byMethod($method);
```

The factory automatically:

- encodes the data as JSON;
- sets the `Content-Type` header to `application/json; charset=utf-8`;
- sets the `Content-Length` header.

### PSR update factory

[](#psr-update-factory)

The `PsrUpdateFactory` creates `Update` objects from PSR-7 server requests in webhook handlers:

```
use Phptg\TransportPsr\PsrUpdateFactory;
use Psr\Http\Message\ServerRequestInterface;

/**
 * @var ServerRequestInterface $request
 */

$update = PsrUpdateFactory::create($request);

// Now you can use the Update object
$message = $update->message;
```

Documentation
-------------

[](#documentation)

- [Internals](docs/internals.md)

If you have any questions or problems with this package, use [author telegram chat](https://t.me/predvoditelev_chat) for communication.

License
-------

[](#license)

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

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance89

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Total

9

Last Release

55d ago

Major Versions

0.1.1 → v015.x-dev2026-02-28

v015.x-dev → v016.x-dev2026-02-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/53e5ee1dedd50f71e4aeeac2929f786cdfb400359d4776e6cd806388d0d5df2c?d=identicon)[vjik](/maintainers/vjik)

---

Top Contributors

[![vjik](https://avatars.githubusercontent.com/u/525501?v=4)](https://github.com/vjik "vjik (24 commits)")

---

Tags

apibotpsrtelegramtransportpsrapitransportbottelegram

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phptg-transport-psr/health.svg)

```
[![Health](https://phpackages.com/badges/phptg-transport-psr/health.svg)](https://phpackages.com/packages/phptg-transport-psr)
```

###  Alternatives

[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k28.0M318](/packages/openai-php-client)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

1003.9M50](/packages/getbrevo-brevo-php)[mollie/mollie-api-php

Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment Button and various gift cards such as Podiumcadeaukaart and fashioncheque.

60216.0M85](/packages/mollie-mollie-api-php)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
