andisiahaan/telegram-channel
最新稳定版本:1.0.1
Composer 安装命令:
composer require andisiahaan/telegram-channel
包简介
Simple Laravel Notification Channel for Telegram
README 文档
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
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-22