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

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

juliuspc/telegram-notification-bot
==================================

Simple to use library to notify telegram users via bot API.

0.1.6(6y ago)015[4 issues](https://github.com/JuliusPC/TelegramNotificationBot/issues)[2 PRs](https://github.com/JuliusPC/TelegramNotificationBot/pulls)CC0-1.0PHPPHP ^7.0

Since May 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/JuliusPC/TelegramNotificationBot)[ Packagist](https://packagist.org/packages/juliuspc/telegram-notification-bot)[ RSS](/packages/juliuspc-telegram-notification-bot/feed)WikiDiscussions master Synced 3d ago

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

TelegramNotificationBot
=======================

[](#telegramnotificationbot)

This library provides a thin layer on top of [Telegram’s bot API](https://core.telegram.org/bots/api). It frees you from the nasty things like keeping track of the known `chat_id` (= subscribed users). Basic understanding how the bot API works is still required.

You can use it for broadcasting news extracted from a RSS feed to different chats (channels). It uses a SQLite database (others may work, just change the [SQLite DSN](https://www.php.net/manual/en/ref.pdo-sqlite.connection.php) in the PDO constructor) to persist some data. If the bot is removed from group chats, received a `/stop` command or blocked by users it will remove those `chat_ids` from the database.

Usage hints:

1. install library:
    - install via [Composer](https://getcomposer.org): `composer require juliuspc/telegram-notification-bot`
    - clone or download this repo, use `composer install` to install dependencies
2. [obtain bot access token](https://core.telegram.org/bots/api)
3. write your code using this library

Importing the library in case of manual install...

```
require __DIR__ . '/TelegramBot.php';
use JuliusPC\TelegramBot;
```

... or simply using Composer:

```
require __DIR__ . '/vendor/autoload.php';
use JuliusPC\TelegramBot;
```

Configuring the bot:

```
$dbh = new \PDO('sqlite:/path/to/botdb.sqlite3');
$token = 'YOUR_ACCESS_TOKEN_HERE';

$bot = new TelegramBot($dbh, $token);

// adjust the bots defaults to your need.
$bot->setWelcomeMessage('Moin!');
$bot->setStopMessage('Ciao.');
```

Getting updates via webhooks (recommended):
-------------------------------------------

[](#getting-updates-via-webhooks-recommended)

Setup of webhooks (you only need to this once or after changes):

```
// set webhook
$bot->setWebhook('https://example.org/someobscurefolder/webhook.php');

// some other useful stuff
// remove webhook
$bot->deleteWebhook();

// get infos about configured webhooks
echo $bot->getWebhookInfo();
```

Put this in the file `/someobscurefolder/webhook.php` (don’t name it like this 😉):

```
// process update from webhook
$update = json_decode( file_get_contents("php://input"), true );
echo $bot->processUpdate($update);
```

Getting updates via polling
---------------------------

[](#getting-updates-via-polling)

Run this periodically:

```
// process Updates in case not using webhooks
$bot->processUpdates($bot->getUpdates());
```

Sending Messages
----------------

[](#sending-messages)

The second parameter allows you to identify a sent message afterwards.

```
// send broadcast to all users
$bot->sendBroadcastMessage('Hello from '.date('H:i').'', '');
```

Editing and deleting messages
-----------------------------

[](#editing-and-deleting-messages)

You can also edit and delete broadcasted messages. To do so, you need to pass a parameter that identifies the sent messages and allows the library to memorize the `chat_id`s and `message_id`s.

The following example shows a broadcasted, self destructing message (the edit and delete commands do not need to be executed on the same instance of TelegramBot since the data is written to the database and therefore persistent):

```
$seconds = 30;
echo $bot->sendBroadcastMessage('self destructing in '.$seconds.' seconds', 'some-arbitrary-string') . ' abonnierte Chats';
while($seconds > 0) {
    sleep(5);
    $seconds -= 5;
    $bot->editBroadcastMessage('self destructing in '.$seconds.' seconds', 'some-arbitrary-string');
}
echo $bot->deleteBroadcastMessage('some-arbitrary-string');
```

Dealing with commands
---------------------

[](#dealing-with-commands)

Let Telegram clients know what commands your bot understands (again as webhooks: you need to do this once or after changes):

```
$commands = [
    [
        'command'=>'start',
        'description'=>'starts bot'
    ],
    [
        'command'=>'stop',
        'description'=>'stops bot'
    ]
];
$bot->setMyCommands(json_encode($commands));
```

If you want to implement your own command, the easiest way to do this is extending the use `TelegramBot` class. In this little example we add a commad that echos the message:

```
class AdvancedBot extends TelegramBot {
    protected function executeCommand(string $command, array $update) : bool {
        $id = $update['message']['chat']['id']??'';
        switch ($command) {
        case 'echo':
          $message = \json_encode($update, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
          return $this->sendMessage(''.htmlspecialchars($message).'', $id);

        case 'rickroll':
          return $this->sendMessage('Very important information', $id);

        default:
          // let the parent method deal with commands like /stop /start
          return parent::executeCommand($command, $update);
      }
    }
}

// of course you need to instantiate and use your new class and not the old one...
$bot = new AdvancedBot($db_handle, $token)
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

Total

7

Last Release

2196d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7614db1251cf4bd34fdec7a7c329c57a126969af8ca87cb462b977034a367099?d=identicon)[JuliusPC](/maintainers/JuliusPC)

---

Top Contributors

[![JuliusPC](https://avatars.githubusercontent.com/u/15018932?v=4)](https://github.com/JuliusPC "JuliusPC (19 commits)")

### Embed Badge

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

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

###  Alternatives

[laravel-notification-channels/telegram

Telegram Notifications Channel for Laravel

1.1k3.4M35](/packages/laravel-notification-channels-telegram)[s-ichikawa/laravel-sendgrid-driver

This library adds a 'sendgrid' mail driver to Laravel.

4139.3M1](/packages/s-ichikawa-laravel-sendgrid-driver)[laravel-notification-channels/microsoft-teams

A Laravel Notification Channel for Microsoft Teams

1603.0M7](/packages/laravel-notification-channels-microsoft-teams)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)[guanguans/notify

Push notification SDK(AnPush、Bark、Chanify、DingTalk、Discord、Gitter、GoogleChat、IGot、Lark、Mattermost、MicrosoftTeams、NowPush、Ntfy、Push、Pushback、PushBullet、PushDeer、PushMe、Pushover、PushPlus、QQ、RocketChat、ServerChan、ShowdocPush、SimplePush、Slack、Telegram、WeWork、WPush、XiZhi、YiFengChuanHua、ZohoCliq、ZohoCliqWebHook、Zulip).

682104.9k7](/packages/guanguans-notify)[tzsk/sms

A robust and unified SMS gateway integration package for Laravel, supporting multiple providers.

320244.3k6](/packages/tzsk-sms)

PHPackages © 2026

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