PHPackages                             gusaln/simple-tg-bot-api - 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. gusaln/simple-tg-bot-api

ActiveLibrary[API Development](/categories/api)

gusaln/simple-tg-bot-api
========================

Minimalist strongly-typed Telegram bot API

0.1.0-alpha.2(4y ago)016MITPHPPHP ^8.0

Since Apr 26Pushed 4y ago1 watchersCompare

[ Source](https://github.com/gusaln/simple-tg-bot-api)[ Packagist](https://packagist.org/packages/gusaln/simple-tg-bot-api)[ Docs](https://github.com/gusaln/simple-tg-bot-api)[ RSS](/packages/gusaln-simple-tg-bot-api/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (4)Used By (0)

Simple Telegram Bot Api \[WIP\]
===============================

[](#simple-telegram-bot-api-wip)

[![Telegram bot api](https://camo.githubusercontent.com/e743e2d6c8219c14e6152071f44e4671d2b1701c9ec70b188b6eb4c6b91a501d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f426f742532304150492d362e302d626c75652e7376673f7374796c653d666c61742d737175617265)](https://core.telegram.org/bots/api)[![Latest Version on Packagist](https://camo.githubusercontent.com/88f3fa024ad014bb42c9a30aca1f922f9608c9218fe558d6614d36beb2b6e24e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677573616c6e2f73696d706c652d74672d626f742d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/gusaln/simple-tg-bot-api)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

Minimalist strongly-typed Telegram Bot API.

This package is heavily inspired by `tg-bot-api/bot-api-base`.

**BEWARE: This package is still in alpha.**

Read the [testing](#testing) section before using this package.

### What does this package provide?

[](#what-does-this-package-provide)

- It provides a way to interact with the Telegram API with strongly typed parameters.
- It provides a way to catch updates in a webhook.

### What does this package NOT provide?

[](#what-does-this-package-not-provide)

A framework for dealing with commands, inline queries or follow conversations. Those are for you to implement.

### Supported Telegram Bot API

[](#supported-telegram-bot-api)

Supports Telegram Bot API 6.0 (April 16, 2022)

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

[](#installation)

Via Composer

```
composer require gusaln/simple-tg-bot-api
```

Usage
-----

[](#usage)

You need to instantiate the `BotApi` class which provides all the methods of the Telegram Bot API.

```
$botToken = '';

$api = new \GusALN\TelegramBotApi\BotApi(
    $botToken,
    new \GusALN\TelegramBotApi\Client\GuzzleClient()
);

// If no ClientInterface is provided as second argument, a GuzzleClient is created by default.
$api = new \GusALN\TelegramBotApi\BotApi($botToken);
```

All the API methods have a corresponding method in the `BotApi` class, and that method takes in a `MethodRequest` object that takes all the arguments of said method.

```
$userId = '';

$message = $api->sendMessage(
    new \GusALN\TelegramBotApi\MethodRequests\SendMessageRequest($userId, "Hello")
);

$editedMessage = $api->editMessageText(
    new \GusALN\TelegramBotApi\MethodRequests\EditMessageTextRequest(
        $message->chat->id,
        $message->messageId,
        "Good bye!"
    )
);
```

This way you are prevented from mistyping any parameters or messing up their types.

**WARNING: Methods like `editMessageText` can take a `chat_id` and a `message_id` for regular messages, or a `inline_message_id` for inline messages, but not the three at the same time.****Currently, this package does not provide a safeguard against this invalid state, but it may in the future.****For now, always read the constructor descriptions.**

For more examples, check the `examples` folder.

### Types

[](#types)

All the types from the Telegram Bot API, like `Update`, `Message`, and the like, are provided as clases in the `GusALN\TelegramBotApi\Types\` namespace. They implement `JsonSerializable` and have a static `fromPayload(array $payload): self` that allows you to deserialize them.

The `fromPayload` method of abstract types, like `MenuButton` which has the child types `MenuButtonCommands`, `MenuButtonWebApp`, and `MenuButtonDefault`, return an instance of the specific child type where possible. Most abstract types have a property which's value specifies its subtype. Following with the `MethodButton` family of types, the property `type` can be either:

- `commands` for `MenuButtonCommands`,
- `web_app` for `MenuButtonWebApp`, or
- `default` for `MenuButtonDefault`.

This values are provided as constants in all abstract types:

```
// omitted code
abstract class MenuButton implements JsonSerializable
{
    public const MENU_BUTTON_COMMANDS_TYPE = 'commands';
    public const MENU_BUTTON_WEB_APP_TYPE = 'web_app';
    public const MENU_BUTTON_DEFAULT_TYPE = 'default';
    // omitted code
}
```

The first exception to this pattern is the `InputMessageContent` family of types which do not have a specific property-value pair that defines then, and other methods are used to identified them.

The other one is the type `MessageEntity`, that despite not being part of a family, has their type string specified in constants.

### Enums

[](#enums)

Enum classes are provided for certain *magic string*. There are two at the moment: `GusALN\TelegramBotApi\Enums\ParseMode::*` and `GusALN\TelegramBotApi\Enums\ChatAction::*`.

You can specify the `parse_mode` parameter for the messages using the `ParseMode::*` constants.

```
$message = $api->sendMessage(
    new \GusALN\TelegramBotApi\MethodRequests\SendMessageRequest(
        $userId,
        "bold, bold, italic, italic",
        parseMode: \GusALN\TelegramBotApi\Enums\ParseMode::HTML
    )
);
```

### Fetching updates from a webhook

[](#fetching-updates-from-a-webhook)

The `WebhookUpdateFetcher` can parse an update from either a `Psr\Http\Message\RequestInterface` or a `string`.

```
$fetcher = new \GusALN\TelegramBotApi\WebhookUpdateFetcher();
$update = $fetcher->fetch($request);
```

### Polling updates

[](#polling-updates)

Check an example inside the `examples/get_updates_polling.php`.

What can I expect to change as the package matures?
---------------------------------------------------

[](#what-can-i-expect-to-change-as-the-package-matures)

A better API, which would include:

1. Factory methods inside some requests. For example, the `editMessageText` could take a `chat_id` and a `message_id` for regular messages, or a `inline_message_id` for inline messages.
2. General methods on the `BotApi` for common tasks. For example, having a `send` method that accepts all the requests that *send* something (`sendMessage`, `sendPhoto`, `sendAudio`, etc.).

Testing
-------

[](#testing)

> I don’t always test my code, but when I do, I test in production.

In all seriousness, expect test to manifest after I play around with the API enough to have a clear idea of shape I want it to have. I have done some crude practical testing on a selection of all the methods to verify that they indeed work.

For the first beta release (0.1.0), there will be tests.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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 ~0 days

Total

3

Last Release

1477d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c191ce49b35f5034e5cbb71f4ffdb4d9e62e197b842aa626df973d4ef1c6480?d=identicon)[gusaln](/maintainers/gusaln)

---

Top Contributors

[![gusaln](https://avatars.githubusercontent.com/u/7484242?v=4)](https://github.com/gusaln "gusaln (12 commits)")

---

Tags

botsphptelegram-bottelegram-bot-apibottelegramtelegram bottelegram bot apitelegram phpphp-botphp-telegram-bot

###  Code Quality

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gusaln-simple-tg-bot-api/health.svg)

```
[![Health](https://phpackages.com/badges/gusaln-simple-tg-bot-api/health.svg)](https://phpackages.com/packages/gusaln-simple-tg-bot-api)
```

###  Alternatives

[irazasyed/telegram-bot-sdk

The Unofficial Telegram Bot API PHP SDK

3.3k4.5M84](/packages/irazasyed-telegram-bot-sdk)[tg-bot-api/bot-api-base

Clear and simple Telegram bot API

22278.8k2](/packages/tg-bot-api-bot-api-base)[telegram-bot-sdk/telegram-bot-sdk

The Telegram Bot API PHP SDK

32480.5k](/packages/telegram-bot-sdk-telegram-bot-sdk)[exileed/telegram-bot-api

The Telegram Bot API PHP

1614.1k](/packages/exileed-telegram-bot-api)[luzrain/telegram-bot-api

PHP Wrapper for Telegram Bot API

1032.8k1](/packages/luzrain-telegram-bot-api)

PHPackages © 2026

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