andisiahaan/telegram-channel

Simple Laravel Notification Channel for Telegram

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/andisiahaan/telegram-channel

1.0.1 2025-12-22 06:33 UTC

This package is auto-updated.

Last update: 2025-12-22 06:35:00 UTC


README

Simple Laravel Notification Channel for sending messages via Telegram Bot API.

Installation

composer require andisiahaan/telegram-channel

Configuration

Publish the config file:

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

Add your Telegram Bot Token to .env:

TELEGRAM_BOT_TOKEN=your-bot-token-here

Usage

Add Route to Your Notifiable Model

use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;

    public function routeNotificationForTelegram($notification): ?string
    {
        return $this->telegram_chat_id;
    }
}

Create a Notification

use Illuminate\Notifications\Notification;
use AndiSiahaan\TelegramChannel\TelegramChannel;
use AndiSiahaan\TelegramChannel\TelegramMessage;

class OrderConfirmation extends Notification
{
    public function via($notifiable): array
    {
        return [TelegramChannel::class];
    }

    public function toTelegram($notifiable): TelegramMessage
    {
        return TelegramMessage::create()
            ->text("🎉 Your order has been confirmed!")
            ->line("Order ID: {$this->order->id}")
            ->line("Total: {$this->order->total}")
            ->html()
            ->button('View Order', url("/orders/{$this->order->id}"));
    }
}

Send the Notification

$user->notify(new OrderConfirmation($order));

Send to Specific Chat ID

TelegramMessage::create()
    ->to('123456789') // Specific chat ID
    ->text('Hello World!')
    ->html();

Available Methods

TelegramMessage

Method Description
create($text) Static factory method
to($chatId) Set recipient chat ID
text($text) Set message text
line($text) Append a new line
html() Use HTML parse mode
markdown() Use Markdown parse mode
markdownV2() Use MarkdownV2 parse mode
disableWebPagePreview() Disable link preview
disableNotification() Send silently
replyTo($messageId) Reply to a message
button($text, $url) Add URL button
buttons($array) Add multiple button rows

License

MIT License