PHPackages                             webpajooh/telebot - 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. webpajooh/telebot

ActiveLibrary[API Development](/categories/api)

webpajooh/telebot
=================

A minimal library to develop your new Telegram bot

v1.7.0(2y ago)532123[1 PRs](https://github.com/muhammadmp97/TeleBot/pulls)MITPHPPHP &gt;=8.0CI failing

Since Jun 2Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/muhammadmp97/TeleBot)[ Packagist](https://packagist.org/packages/webpajooh/telebot)[ RSS](/packages/webpajooh-telebot/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (1)Versions (19)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/b3b6044c1ae039ec0090955efea30d5615d226dc1557eac7cbf3b29e05048a70/687474703a2f2f706f7365722e707567782e6f72672f77656270616a6f6f682f74656c65626f742f76)](https://packagist.org/packages/webpajooh/telebot) [![Total Downloads](https://camo.githubusercontent.com/e7f01a383c62ca0dd0cf28d4e54d814d102f4d862339c3be4bc49b0cd0c4447d/687474703a2f2f706f7365722e707567782e6f72672f77656270616a6f6f682f74656c65626f742f646f776e6c6f616473)](https://packagist.org/packages/webpajooh/telebot) [![PHP Version Require](https://camo.githubusercontent.com/b9f68b280b59b511e1f59113664c50246e65d4dec7755d7c35f354e3866319d1/687474703a2f2f706f7365722e707567782e6f72672f77656270616a6f6f682f74656c65626f742f726571756972652f706870)](https://packagist.org/packages/webpajooh/telebot) [![License](https://camo.githubusercontent.com/25f2158dcba859ede0b83540b972187b69f58588f3c4fd09aca9ab813491c353/687474703a2f2f706f7365722e707567782e6f72672f77656270616a6f6f682f74656c65626f742f6c6963656e7365)](https://packagist.org/packages/webpajooh/telebot)

TeleBot
=======

[](#telebot)

A minimal library to develop your new Telegram bot

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

[](#installation)

`composer require webpajooh/telebot`

How to use
----------

[](#how-to-use)

### Start point

[](#start-point)

We start by creating an instance of `TeleBot` class:

```
try {
    $tg = new TeleBot('YOUR_BOT_TOKEN');
} catch (Throwable $th) {...}
```

### Get the update object

[](#get-the-update-object)

There are short ways to access the `update` object and some important fields. I recommend you to read [the official documentation](https://core.telegram.org/bots/api) to understand these objects well.

```
$tg->update
$tg->message
$tg->chat
$tg->user

```

You also can use the `hasCallbackQuery()` method, when you want to check if the `update` object has a `callback_query` field.

### Methods

[](#methods)

Thanks to [magic methods](https://www.php.net/manual/en/language.oop5.magic.php), we can use API methods without implementing them, and just call them by name and pass an array as parameter:

```
$tg->editMessageText([...])
```

### Router

[](#router)

You may define some routes to your bot features; define them by the `listen()` method:

```
$tg->listen('/start', function () use ($tg) {
    $tg->sendMessage([
        'chat_id' => $tg->user->id,
	'text' => 'Hello, world!',
    ]);
}, false);
```

The third parameter that is true by default, makes you able to terminate the script after running a command. In the previous example we passed `false` so script continues.

You can also get parameters and use them as variables:

```
$tg->listen('set_age_%d', function ($age) use ($tg) {
    // TODO
});
```

TeleBot translates them to regex, so it will be good to take a look at this table to know how to use them properly:

TypeTeleBotRegexDigits%d(\\d+)String (Anything but a whitespace)%s(\\S+)Character%c(\\S)Everything including an empty string%p(.\*)### Logger

[](#logger)

You may need to log something into a `log.txt` file:

```
Logger::log($tg->user->id);
tl($tg->user->id); // Does the same thing
```

### Keyboard

[](#keyboard)

TeleBot includes two classes for making keyboards; `InlineKeyboard` and `ReplyKeyboard`. Here you see an example:

```
$keyboard = (new InlineKeyboard())
    ->addCallbackButton('📕 Help', 'help_callback')
    ->addUrlButton('📱 Share', 'https://t.me/share/url?url=https://t.me/your_awesome_bot&text=Some text')
    ->chunk(1)
    ->rightToLeft()
    ->get();
```

Then you can use it as bellow:

```
$tg->sendMessage([
    // Other parameters
    'reply_markup' => $keyboard,
]);
```

Consider that the `chunk()` method supports more complex orders, just pass an array like \[1, 3, 2\] to build such a keyboard:

```
[        1        ]
[ 2 ]  [ 3️ ]  [ 4 ]
[   5   ] [   6   ]
```

### Default parameters

[](#default-parameters)

Sometimes you do not want to repeat yourself by passing a parameter everywhere, so you can define default parameters for each method. Here are three example that makes it clear how to use it:

```
$tg->setDefaults('sendMessage', ['parse_mode' => 'html']); // You will not need passing parse_mode anymore
$tg->setDefaults(['sendMessage', 'banChatMember'], ['chat_id' => $chatId]);
$tg->setDefaults('*', ['chat_id' => $chatId]); // a default parameter for all methods
```

### Extend it!

[](#extend-it)

You may want to add some methods to TeleBot class to improve your code readability and avoid duplication. Look at this simple example as an inspiration:

```
TeleBot::extend('isReply', function () {
    return property_exists($this->message, 'reply_to_message');
});

if ($tg->isReply()) { ... }
```

Have you seen a problem?
------------------------

[](#have-you-seen-a-problem)

Create an issue and explain your problem!

Made with TeleBot
-----------------

[](#made-with-telebot)

- [AntiBot](https://github.com/muhammadmp97/AntiBot)
- [MediumBot](https://github.com/muhammadmp97/MediumBot)
- [ToigBot](https://github.com/MahdiyarGHD/ToigBot)

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance50

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 87.2% 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 ~84 days

Recently: every ~152 days

Total

17

Last Release

863d ago

PHP version history (4 changes)v1.0.0PHP ^7.2

v1.1.3PHP &gt;=7.2

v1.3.0PHP &gt;=7.4

v1.6.1PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/da3e41c617ba79ead2c9a86143efae56d82cdfa8056ea6cbd1e1f7024e61150e?d=identicon)[muhammadmp97](/maintainers/muhammadmp97)

---

Top Contributors

[![muhammadmp97](https://avatars.githubusercontent.com/u/17279395?v=4)](https://github.com/muhammadmp97 "muhammadmp97 (82 commits)")[![MahdiyarGHD](https://avatars.githubusercontent.com/u/86115606?v=4)](https://github.com/MahdiyarGHD "MahdiyarGHD (7 commits)")[![amir-827](https://avatars.githubusercontent.com/u/77408494?v=4)](https://github.com/amir-827 "amir-827 (3 commits)")[![sadegh19b](https://avatars.githubusercontent.com/u/54643531?v=4)](https://github.com/sadegh19b "sadegh19b (2 commits)")

---

Tags

php-telegram-bottelegramtelegram-apitelegram-bottelegram-sdktelegramtelegram bottelegram bot apitelegram sdktelegram php

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webpajooh-telebot/health.svg)

```
[![Health](https://phpackages.com/badges/webpajooh-telebot/health.svg)](https://phpackages.com/packages/webpajooh-telebot)
```

###  Alternatives

[irazasyed/telegram-bot-sdk

The Unofficial Telegram Bot API PHP SDK

3.3k4.8M93](/packages/irazasyed-telegram-bot-sdk)[telegram-bot-sdk/telegram-bot-sdk

The Telegram Bot API PHP SDK

32981.3k](/packages/telegram-bot-sdk-telegram-bot-sdk)

PHPackages © 2026

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