mavinoo/telegrambot is a Laravel package for telegram notifications driver.
It currently has 1 GitHub stars and 24 downloads on Packagist.
Install it with composer require mavinoo/telegrambot.
Discover more Laravel packages by mavinoo
or browse all Laravel packages to compare alternatives.
Last updated
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 mavinoo/telegrambot:dev-master
You must install the service provider:
// config/app.php
'providers' => [
...
NotificationChannelsPlus\Telegrambot\TelegrambotServiceProvider::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 NotificationChannelsPlus\Telegrambot\TelegramChannel;
use NotificationChannelsPlus\Telegrambot\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);
$tg = TelegramMessage::create()
->to($this->user->telegram_user_id)
->content("*HELLO!* \n One of your invoices has been paid!")
->button('View Invoice', $url)
->getResult();
return $tg;
}
}
You can now use the channel in your via() method inside the Notification class.
use NotificationChannelsPlus\Telegrambot\TelegramChannel;
use NotificationChannelsPlus\Telegrambot\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);
$tg = TelegramMessage::create()
->to($this->user->telegram_user_id)
->sendPhoto([
'caption' => 'Hello Mohammad',
'photo' => 'http://www.ilovegenerator.com/large/i-love-mohamed-132309992962.png',
])
->button('View Invoice', $url)
->getResult();
return $tg;
}
}
For advance usage, please consider using telegram-bot-sdk instead.
The MIT License (MIT). Please see License File for more information.