PHPackages                             rud99/laravel-telegram-cleanup - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. rud99/laravel-telegram-cleanup

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rud99/laravel-telegram-cleanup
==============================

Auto-delete Telegram bot messages in Laravel applications

v0.0.5(3mo ago)111MITPHPPHP ^8.2

Since Jan 23Pushed 3mo agoCompare

[ Source](https://github.com/rud99/laravel-telegram-cleanup)[ Packagist](https://packagist.org/packages/rud99/laravel-telegram-cleanup)[ RSS](/packages/rud99-laravel-telegram-cleanup/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

Laravel Telegram Cleanup
========================

[](#laravel-telegram-cleanup)

[Русская документация / Russian Documentation](README_RU.md)

Auto-delete Telegram bot messages in Laravel applications.

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

[](#installation)

```
composer require rud99/laravel-telegram-cleanup
php artisan migrate
```

Requirements
------------

[](#requirements)

This package extends [laravel-notification-channels/telegram](https://github.com/laravel-notification-channels/telegram) and uses the same bot token configuration.

Make sure you have configured the token in `config/services.php`:

```
'telegram-bot-api' => [
    'token' => env('TELEGRAM_BOT_TOKEN'),
],
```

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

[](#configuration)

Publish the configuration file to customize settings:

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

Available options in `config/telegram-cleanup.php`:

OptionDefaultDescription`default_delete_after_minutes`1440Default TTL for messages (24 hours)`delay_between_requests_ms`150Delay between API calls (rate limit)`max_retry_attempts`3Retries on 429 errors`prune_after_months`1Keep deleted records for N monthsUsage
-----

[](#usage)

### 1. Create a notification extending TelegramCleanupNotification

[](#1-create-a-notification-extending-telegramcleanupnotification)

```
use Rud99\TelegramCleanup\Notifications\TelegramCleanupNotification;
use NotificationChannels\Telegram\TelegramMessage;

class VerificationCodeNotification extends TelegramCleanupNotification
{
    public function __construct(
        protected string $code,
        ?int $deleteAfterMinutes = 5
    ) {
        $this->deleteAfterMinutes = $deleteAfterMinutes;
        $this->message = "Your code: {$code}";
        $this->meta = ['type' => 'verification'];
    }

    public function toTelegram(object $notifiable): TelegramMessage
    {
        return TelegramMessage::create()
            ->content($this->message);
    }
}
```

### 2. Send notification

[](#2-send-notification)

**Via queue (default):**

```
use Illuminate\Support\Facades\Notification;

Notification::route('telegram', $chatId)
    ->notify(new VerificationCodeNotification('1234', 5));
```

The notification will be queued and processed by your queue worker.

**Without queue (synchronous):**

```
Notification::route('telegram', $chatId)
    ->notifyNow(new VerificationCodeNotification('1234', 5));
```

The notification will be sent immediately.

The message will be automatically deleted after 5 minutes.

### Delete time options

[](#delete-time-options)

ValueBehaviornot set (`null`)Uses default from config (24 hours)`false`Disable auto-delete for this notification`N` (integer)Delete after N minutesExample with disabled auto-delete:

```
class ImportantNotification extends TelegramCleanupNotification
{
    public function __construct(protected string $text)
    {
        $this->deleteAfterMinutes = false; // Never delete
        $this->message = $text;
    }

    public function toTelegram(object $notifiable): TelegramMessage
    {
        return TelegramMessage::create()->content($this->text);
    }
}
```

### 3. Run cleanup command

[](#3-run-cleanup-command)

Add to your scheduler (`routes/console.php`):

```
use Illuminate\Support\Facades\Schedule;

Schedule::command('telegram:messages:delete-expired')
    ->everyFiveMinutes()
    ->withoutOverlapping();
```

### Manual registration

[](#manual-registration)

If sending messages without notifications:

```
use Rud99\TelegramCleanup\TelegramMessageCleanupService;

$service = app(TelegramMessageCleanupService::class);

$service->registerForDeletion(
    chatId: $chatId,
    messageId: $messageId,
    deleteAfterMinutes: 30,
    meta: ['type' => 'manual']
);
```

Commands
--------

[](#commands)

### Delete expired messages

[](#delete-expired-messages)

```
# Delete expired messages
php artisan telegram:messages:delete-expired

# Preview without deleting
php artisan telegram:messages:delete-expired --dry-run

# Limit number of deletions
php artisan telegram:messages:delete-expired --limit=100

# Delete only from specific chat
php artisan telegram:messages:delete-expired --chat-id=123456789
```

### Prune old records

[](#prune-old-records)

Remove old deleted message records from the database:

```
php artisan telegram:messages:prune
```

You can schedule it in `routes/console.php`:

```
Schedule::command('telegram:messages:prune')
    ->weekly()
    ->withoutOverlapping();
```

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance80

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

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

5

Last Release

107d ago

### Community

Maintainers

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

---

Top Contributors

[![rud99](https://avatars.githubusercontent.com/u/12742466?v=4)](https://github.com/rud99 "rud99 (10 commits)")

---

Tags

laravelbottelegramcleanupauto-delete

### Embed Badge

![Health badge](/badges/rud99-laravel-telegram-cleanup/health.svg)

```
[![Health](https://phpackages.com/badges/rud99-laravel-telegram-cleanup/health.svg)](https://phpackages.com/packages/rud99-laravel-telegram-cleanup)
```

###  Alternatives

[formapro/telegram-bot

PHP Telegram Bot

2532.5k](/packages/formapro-telegram-bot)[williamson/laragram

A Laravel Wrapper for telegram-cli

282.8k](/packages/williamson-laragram)

PHPackages © 2026

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