Search by

balazstanka / laravel-telegram-alerts

asn1

Send alerts to Telegram from your Laravel app.

Package info

github.com/balazstanka/laravel-telegram-alerts

pkg:composer/balazstanka/laravel-telegram-alerts

Fund package maintenance!

balazstanka

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-10-01 19:31 UTC

This package is auto-updated.

Last update: 2026-10-01 20:01:13 UTC


README

Laravel Telegram Alerts

Send alerts to Telegram from your Laravel app.

Based on laravel/package-skeleton, thanks to the Laravel team!

Tests Latest Version Total Downloads PHP Version License

Installation

You can install the package via Composer:

composer require balazstanka/laravel-telegram-alerts

You may publish all of the package's resources at once:

php artisan vendor:publish --tag="laravel-telegram-alerts"

Or, you may publish each resource individually:

Publishing the Configuration File

php artisan vendor:publish --tag="laravel-telegram-alerts-config"

Add your bot token (from @BotFather) and the chat id to your .env:

TELEGRAM_ALERT_BOT_TOKEN=123456:ABC-your-token
TELEGRAM_ALERT_CHAT_ID=-1001234567890

Usage

use BalazsTanka\TelegramAlerts\Facades\TelegramAlerts;

TelegramAlerts::message("You have a new subscriber to the {$newsletter->name} newsletter!");

The message is sent by a queued job, so your app keeps working when Telegram is slow or down. The job retries server errors with a backoff, waits as long as Telegram asks when it is rate limited, and fails right away on errors that a retry cannot fix (for example an unknown chat or a blocked bot). A failed delivery is logged.

Sending without the queue

Some alerts must arrive even when the queue itself is broken, for example a queue health check. sync() sends the message immediately and retries a few times:

TelegramAlerts::sync()->message('The queue worker is not running!');

Multiple chats

Add named chats to the chats array of the config file, then pick one with to(). You may also pass a chat id or a @channelusername:

TelegramAlerts::to('ops')->message('Disk is almost full');
TelegramAlerts::to(-1001234567890)->message('Hello');

Formatting

Messages are sent as plain text by default. Use html() or markdown() (MarkdownV2) to format them, and escape() for any text you don't control:

TelegramAlerts::html()->message('<b>Payment failed</b>: '.TelegramAlerts::escape($exception->getMessage()));

If Telegram cannot parse the formatting, the message is sent again as plain text, so the alert is not lost.

More options

TelegramAlerts::to('ops')
    ->silent()           // no notification sound
    ->inThread(42)       // a topic in a forum group
    ->delayMinutes(5)    // also: delayHours()
    ->message('Nightly backup finished');

Errors

An empty message, an unknown chat or a missing token throws a TelegramException, so you notice it during development. In production these are logged instead, and the request keeps working.

Set TELEGRAM_ALERT_ENABLED=false to turn alerts off, for example in CI.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Thank you for considering contributing to Laravel Telegram Alerts! Please review our contributing guide to get started.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

Laravel Telegram Alerts is open-sourced software licensed under the MIT license.