PHPackages                             codewiser/telegram-subscriber - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. codewiser/telegram-subscriber

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

codewiser/telegram-subscriber
=============================

Telegram Subscriber for Laravel

v1.1.8(9mo ago)0263MITPHPPHP ^8.0

Since Nov 1Pushed 9mo ago2 watchersCompare

[ Source](https://github.com/C0deWiser/telegram-subscriber)[ Packagist](https://packagist.org/packages/codewiser/telegram-subscriber)[ RSS](/packages/codewiser-telegram-subscriber/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (16)Used By (0)

Telegram Subscriber for Laravel
===============================

[](#telegram-subscriber-for-laravel)

The package provides a solution for retrieving chat ID.

Installation and setup
----------------------

[](#installation-and-setup)

Package uses `irazasyed/telegram-bot-sdk`. So above all follow [Telegram Bot SDK instructions](https://telegram-bot-sdk.com/docs/getting-started/installation)and set up your first Telegram Bot. Most likely you need to run:

```
php artisan vendor:publish --tag="telegram-config"

```

In `config/telegram.php` configuration file add bot `name` parameter and register `DeeplinkCommand`. You may not define `webhook_url` as it will be reconfigured on a fly.

```
# config/telegram.php

'bots' => [
    'my_bot' => [
        'name'             => env('TELEGRAM_BOT_NAME'),
        'token'            => env('TELEGRAM_BOT_TOKEN'),
        'certificate_path' => env('TELEGRAM_CERTIFICATE_PATH'),
        //'webhook_url'      => env('TELEGRAM_WEBHOOK_URL'),
        'commands'         => [
            \Codewiser\Telegram\Commands\DeeplinkCommand::class
        ],
    ],
]
```

Retrieving chat ID
------------------

[](#retrieving-chat-id)

Implement `\Codewiser\Telegram\Contracts\TelegramNotifiable` to a `User` model. You might need to write a migration...

```
use \Illuminate\Notifications\Notifiable;
use \Illuminate\Database\Eloquent\Model;
use \Codewiser\Telegram\Contracts\TelegramNotifiable;

class User extends Model implements TelegramNotifiable
{
    use Notifiable;

    public function routeNotificationForTelegram($notification = null): mixed
    {
        return $this->telegram_user_id;
    }

    public function setRouteForTelegram($route): void
    {
        $this->telegram_user_id = $route;

        $this->save();
    }
}
```

Now, create service to implement `\Codewiser\Telegram\Contracts\TelegramNotifiableProvider`. This is an example of implementation, your may implement it however you like.

```
use \Codewiser\Telegram\Contracts\TelegramNotifiableProvider;

class TelegramUserProvider implements TelegramNotifiableProvider
{
    /**
     * Issue and remember new token for a given notifiable.
     */
    public function generateToken(TelegramNotifiable $notifiable): string
    {
        $token = Str::random(40);

        cache()->set(
            $token,
            [
                'key'   => $notifiable->getKey(),
                'model' => get_class($notifiable),
            ],
            now()->addMinutes(5)
        );

        return $token;
    }

    /**
     * Find notifiable associated with a given token.
     */
    public function resolveToken(string $token): ?TelegramNotifiable
    {
        $notifiable = cache()->pull($token);

        if ($notifiable) {
            $key = $notifiable['key'];
            $model = $notifiable['model'];

            return $model::find($key);
        }

        return null;
    }
}
```

At last, register this service in `AppServiceProvider` of your application

```
public function register()
{
    $this->app->singleton(TelegramNotifiableProvider::class, fn() => new TelegramUserProvider);
}
```

We are ready to go.

Getting updates
---------------

[](#getting-updates)

### Register webhook

[](#register-webhook)

If you are properly configure bot in `config/telegram.php` this is enough to use `telegram:webhook` command provided by `Telegram Bot SDK`package. We recommend to read help:

```
php artisan help telegram:webhook

```

This package provides webhook controller to deal with incoming messages.

For example `DeeplinkCommand`, that was mentioned above, used to handle `/start` command with deeplink token.

You are free to add any other command handlers to `config/telegram.php`.

Read more about [Bot Commands](https://telegram-bot-sdk.com/docs/guides/commands-system).

### Long polling

[](#long-polling)

This package brings `telegram:poll` command to get updates without registering webhook. Just call a command.

Usage
-----

[](#usage)

### Subscribe user

[](#subscribe-user)

First, we need to issue a deeplink for a user.

```
use \Illuminate\Http\Request;
use \Codewiser\Telegram\TelegramService;

class DeeplinkController extends Controller
{
    public function __invoke(Request $request, TelegramService $service) {
        return $service->getDeeplink($request->user());
    }
}
```

User follows deeplink, opens telegram client and presses Start button.

`Codewiser\Telegram\Commands\DeeplinkCommand` handles incoming update, resolves deeplink token and update `User` with `chat_id`.

For now, this user has telegram route and may be notified via Telegram.

### Unsubscribe user

[](#unsubscribe-user)

If user blocks or delete a bot, app can not deliver notification: telegram responds with 403 status code. In that case we should count user as unsubscribed and may delete `chat_id`.

To do so, just register event listener:

```
use Codewiser\Telegram\Listeners\UnsubscribeTelegramNotifiable;
use Illuminate\Notifications\Events\NotificationFailed;
use Illuminate\Support\Facades\Event;

Event::listen(NotificationFailed::class, UnsubscribeTelegramNotifiable::class);
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance56

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

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

Recently: every ~55 days

Total

15

Last Release

293d ago

### Community

Maintainers

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

---

Top Contributors

[![Cellard](https://avatars.githubusercontent.com/u/1220316?v=4)](https://github.com/Cellard "Cellard (23 commits)")

---

Tags

laravelnotificationstelegramlaraveltelegramsubscriber

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codewiser-telegram-subscriber/health.svg)

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

###  Alternatives

[laravel-notification-channels/telegram

Telegram Notifications Channel for Laravel

1.1k3.4M35](/packages/laravel-notification-channels-telegram)[vemcogroup/laravel-sparkpost-driver

SparkPost driver to use with Laravel 6.x|7.x|8.x|9.x|10.x

421.7M1](/packages/vemcogroup-laravel-sparkpost-driver)[synergitech/laravel-postal

This library integrates Postal with the standard Laravel mail framework.

38107.1k](/packages/synergitech-laravel-postal)[babenkoivan/telegram-notifications

Telegram notifications for Laravel

3847.1k](/packages/babenkoivan-telegram-notifications)

PHPackages © 2026

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