Package Data | |
---|---|
Maintainer Username: | laravel-notification-channels |
Maintainer Contact: | github@lukonet.net (Irfaq Syed) |
Package Create Date: | 2016-08-11 |
Package Last Update: | 2024-10-17 |
Home Page: | https://laravel-notification-channels.com/telegram/ |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-19 03:12:19 |
Package Statistics | |
---|---|
Total Downloads: | 2,142,058 |
Monthly Downloads: | 60,508 |
Daily Downloads: | 2,355 |
Total Stars: | 998 |
Total Watchers: | 30 |
Total Forks: | 165 |
Total Open Issues: | 3 |
This package makes it easy to send Telegram notification using Telegram Bot API with Laravel 5.3.
You can install the package via composer:
composer require laravel-notification-channels/telegram
You must install the service provider:
// config/app.php
'providers' => [
...
NotificationChannels\Telegram\TelegramServiceProvider::class,
],
Talk to @BotFather and generate a Bot API Token.
Then, configure your Telegram Bot API Token:
// config/services.php
...
'telegram-bot-api' => [
'token' => env('TELEGRAM_BOT_TOKEN', 'YOUR BOT TOKEN HERE')
],
...
You can now use the channel in your via()
method inside the Notification class.
use NotificationChannels\Telegram\TelegramChannel;
use NotificationChannels\Telegram\TelegramMessage;
use Illuminate\Notifications\Notification;
class InvoicePaid extends Notification
{
public function via($notifiable)
{
return [TelegramChannel::class];
}
public function toTelegram($notifiable)
{
$url = url('/invoice/' . $this->invoice->id);
return TelegramMessage::create()
->to($this->user->telegram_user_id) // Optional.
->content("*HELLO!* \n One of your invoices has been paid!") // Markdown supported.
->button('View Invoice', $url); // Inline Button
}
}
Here's a screenshot preview of the above notification on Telegram Messenger:
...
public function toTelegram($notifiable)
{
$url = url('/file/' . $this->file->id);
return TelegramMessage::create()
->to($this->user->telegram_user_id) // Optional.
->content("*bold text* [inline URL](http://www.example.com/)") // Markdown supported.
->file('/storage/archive/6029014.jpg', 'photo') // local photo
// OR
// ->file('https://pisces.bbystatic.com/image2/BestBuy_US/images/products/6029/6029014_rd.jpg', 'photo') // remote photo
->button('Download PDF', $url); // Inline Button
}
...
Sample :
...
public function toTelegram($notifiable)
{
$url = url('/file/' . $this->file->id);
return TelegramMessage::create()
->to($this->user->telegram_user_id) // Optional.
->content("*bold text* [inline URL](http://www.example.com/)") // Markdown supported.
->file('/storage/archive/file.pdf', 'document') // local file
// OR
// ->file('http://www.domain.com/file.pdf', 'document') // remote file
->button('Download PDF', $url); // Inline Button
}
...
Sample :
You can either send the notification by providing with the chat id of the recipient to the to($chatId)
method like shown in the above example or add a routeNotificationForTelegram()
method in your notifiable model:
...
/**
* Route notifications for the Telegram channel.
*
* @return int
*/
public function routeNotificationForTelegram()
{
return $this->telegram_user_id;
}
...
to($chatId)
: (integer) Recipient's chat id.content('')
: (string) Notification message, supports markdown. For more information on supported markdown styles, check out these docs.button($text, $url)
: (string) Adds an inline "Call to Action" button. You can add as many as you want and they'll be placed 2 in a row.options([])
: (array) Allows you to add additional or override sendMessage
payload (A Telegram Bot API method used to send message internally). For more information on supported parameters, check out these docs.For advance usage, please consider using telegram-bot-sdk instead.
Please see CHANGELOG for more information what has changed recently.
$ composer test
If you discover any security related issues, please email syed@lukonet.com instead of using the issue tracker.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.