PHPackages                             cawa0505/telegram-bot - 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. cawa0505/telegram-bot

ActiveLibrary[API Development](/categories/api)

cawa0505/telegram-bot
=====================

Create your Telegram Bot in 5 minutes with Laravel

0.8.1(7y ago)012MITPHP

Since Aug 22Pushed 7y ago1 watchersCompare

[ Source](https://github.com/cawa0505/laravel-telegram-bot)[ Packagist](https://packagist.org/packages/cawa0505/telegram-bot)[ RSS](/packages/cawa0505-telegram-bot/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Laravel Telegram Bot
====================

[](#laravel-telegram-bot)

[![cover](https://cloud.githubusercontent.com/assets/5261079/17837503/ac398cd0-67bd-11e6-8493-962ef6111d58.png)](https://cloud.githubusercontent.com/assets/5261079/17837503/ac398cd0-67bd-11e6-8493-962ef6111d58.png)

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

[](#installation)

Require this package, with [Composer](https://getcomposer.org/):

```
composer require black-river/telegram-bot
```

Add the service provider to the `providers` array of your `config/app.php`:

```
BlackRiver\TelegramBot\ServiceProvider::class,
```

Configuration
-------------

[](#configuration)

Publish the config file:

```
php artisan vendor:publish --provider="BlackRiver\TelegramBot\ServiceProvider"
```

Set environment variables in your `.env`:

```
APP_URL="http://your-bot.com"
...
TELEGRAM_TOKEN="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"

```

To use a [self-signed certificate](https://core.telegram.org/bots/self-signed), you should also specify the certificate path:

```
TELEGRAM_CERTIFICATE="/etc/nginx/ssl/your-bot.com.crt"

```

Quickstart
----------

[](#quickstart)

Define the default webhook route in your route file:

```
Route::post(config('telegram.token'), function (BlackRiver\TelegramBot\Bot $bot) {
    $bot->listen();
});
```

- Use the Bot's `listen` method to handle commands.

Set up the webhook url:

```
php artisan webhook:set
```

To ensure the bot is ready, send the `/ping` message:

[![ping-command](https://cloud.githubusercontent.com/assets/5261079/17837506/b808b3ba-67bd-11e6-911d-42d1568ab068.png)](https://cloud.githubusercontent.com/assets/5261079/17837506/b808b3ba-67bd-11e6-911d-42d1568ab068.png)

> To make sure there is no middleware or prefix that could "block" the default webhook route, check your `app/Providers/RouteServiceProvider.php`.

Webhook URL
-----------

[](#webhook-url)

You can change the default webhook route to your own:

```
Route::post('your-secret-path', function (BlackRiver\TelegramBot\Bot $bot) {
    $bot->listen();
});
```

```
php artisan webhook:set your-secret-path
```

To remove the webhook integration, run `php artisan webhook:remove`.

Bot Commands
------------

[](#bot-commands)

Create a new Bot Command in the `app/Http/BotCommands` directory:

```
php artisan make:bot-command NameCommand
```

Edit the `handle` method of `app/Http/BotCommands/NameCommand.php`:

```
$this->client->send('sendMessage', [
    'chat_id' => $this->request->json('message.chat.id'),
    'text' => 'Hello, '.trim($message),
]);
```

- Use the Client's `send` method to call any of the [available methods](https://core.telegram.org/bots/api#available-methods).
- Use the Client's `save` method to save Telegram files.
- The Client and Request are available within a Command via `$this->client` and `$this->request` respectively.

Add the new command to the `commands` array of your `config/telegram.php`:

```
'/name' => App\Http\BotCommands\NameCommand::class,
```

Send the `/name Johnny` message:

[![name-command](https://cloud.githubusercontent.com/assets/5261079/17837505/b5d147c4-67bd-11e6-8aa3-b65a59151815.png)](https://cloud.githubusercontent.com/assets/5261079/17837505/b5d147c4-67bd-11e6-8aa3-b65a59151815.png)

Raw Webhook
-----------

[](#raw-webhook)

```
Route::post('your-secret-path', function (Illuminate\Http\Request $request, BlackRiver\TelegramBot\Client $client) {
    // $bot->listen();

    $update = $request->json()->all();

    $client->send('sendMessage', [
        'chat_id' => $request->json('message.chat.id'),
        'text' => 'I\'ve got it!',
    ]);
});
```

Facades
-------

[](#facades)

Add facades to the `aliases` array of your `config/app.php`:

```
'TelegramBot' => BlackRiver\TelegramBot\Facades\TelegramBot::class,
'TelegramApi' => BlackRiver\TelegramBot\Facades\TelegramApi::class,
```

Usage:

```
Route::post('your-secret-path', function () {
    // TelegramBot::listen();

    TelegramApi::send('sendMessage', [
        'chat_id' => Request::json('message.chat.id'),
        'text' => 'Hey!',
    ]);
});
```

Examples
--------

[](#examples)

Send a photo to your chat:

```
Route::post('photo', function (BlackRiver\TelegramBot\Client $client) {
    $client->send('sendPhoto', [
        'chat_id' => 'your-chat-id',
        'photo' => fopen(storage_path('photo.png'), 'r'),
    ]);
});
```

Save incoming files:

```
Route::post('your-secret-path', function (Illuminate\Http\Request $request, BlackRiver\TelegramBot\Client $client) {
    $doc = $request->json('message.document');

    $filename = $doc['file_name'];

    $file = $client->send('getFile', ['file_id' => $doc['file_id']]);

    $client->save($file['result']['file_path'], storage_path($filename));
});
```

Extending
---------

[](#extending)

To extend the Client, add a new macro to the `boot` method of your `app/Providers/AppServiceProvider.php`:

```
app('BlackRiver\TelegramBot\Client')->macro('sendUploadedPhoto',
    function ($chatId, \Illuminate\Http\UploadedFile $photo) {
        $saved = $photo->move(storage_path(), $photo->getClientOriginalName());

        $this->send('sendPhoto', [
            'chat_id' => $chatId,
            'photo' => fopen($saved->getRealPath(), 'r'),
        ]);
    }
);
```

Send an uploaded photo to your chat:

```
Route::post('upload', function (Illuminate\Http\Request $request, BlackRiver\TelegramBot\Client $client) {
    $client->sendUploadedPhoto('your-chat-id', $request->file('photo'));
});
```

Handle errors
-------------

[](#handle-errors)

The Client uses [Guzzle Http Client](http://docs.guzzlephp.org/en/latest/) to interact with Telegram API, so you can handle [Guzzle Exceptions](http://docs.guzzlephp.org/en/latest/quickstart.html#exceptions):

```
try {
    $client->send('methodName', []);
} catch (GuzzleHttp\Exception\ClientException $e) {
    // 400 level errors...
} catch (GuzzleHttp\Exception\ServerException $e) {
    // 500 level errors...
} catch (GuzzleHttp\Exception\RequestException $e) {
    // Connection timeout, DNS errors, etc.
}
```

Lumen
-----

[](#lumen)

Require this package, with [Composer](https://getcomposer.org/):

```
composer require black-river/telegram-bot
```

Add the service provider to the `Register Service Providers` section of your `bootstrap/app.php`:

```
$app->register(BlackRiver\TelegramBot\ServiceProvider::class);
```

Set the `APP_URL`, `TELEGRAM_TOKEN` and `TELEGRAM_CERTIFICATE` variables in your `.env`.

Copy the vendor's `telegram.php` config file to your `config` directory:

```
mkdir config/ && cp vendor/black-river/telegram-bot/config/telegram.php config/
```

Define the default webhook route in your route file:

```
$app->post(config('telegram.token'), function (BlackRiver\TelegramBot\Bot $bot) {
    $bot->listen();
});
```

License
-------

[](#license)

Laravel Telegram Bot is licensed under [The MIT License (MIT)](LICENSE).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% 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 ~957 days

Total

2

Last Release

2593d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/467312520039c167c8b8932f58dabe479a0d4c5a6ff99ddfe95eee550c011b1f?d=identicon)[cawa0505](/maintainers/cawa0505)

---

Top Contributors

[![cawa0505](https://avatars.githubusercontent.com/u/3434037?v=4)](https://github.com/cawa0505 "cawa0505 (3 commits)")[![seleznevdev](https://avatars.githubusercontent.com/u/5261079?v=4)](https://github.com/seleznevdev "seleznevdev (1 commits)")

---

Tags

apilaravellumenbottelegram

### Embed Badge

![Health badge](/badges/cawa0505-telegram-bot/health.svg)

```
[![Health](https://phpackages.com/badges/cawa0505-telegram-bot/health.svg)](https://phpackages.com/packages/cawa0505-telegram-bot)
```

###  Alternatives

[spatie/laravel-fractal

An easy to use Fractal integration for Laravel applications

1.9k15.1M99](/packages/spatie-laravel-fractal)[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[mollie/laravel-mollie

Mollie API client wrapper for Laravel &amp; Mollie Connect provider for Laravel Socialite

3624.1M28](/packages/mollie-laravel-mollie)[vluzrmos/slack-api

Wrapper for Slack.com WEB API.

102589.1k3](/packages/vluzrmos-slack-api)[smodav/mpesa

M-Pesa API implementation

16363.7k1](/packages/smodav-mpesa)[bushlanov-dev/max-bot-api-client-php

Max Bot API Client library

281.6k](/packages/bushlanov-dev-max-bot-api-client-php)

PHPackages © 2026

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