Ngiler SH3LL 360
Home
Information
Create File
Create Folder
:
/
home
/
tbf
/
cursbackend
/
vendor
/
laravel-notification-channels
/
telegram
/
Information Server
MySQL :
OFF
Perl :
OFF
CURL :
ON
WGET :
OFF
PKEXEC :
OFF
Directive
Local Value
IP Address
89.40.16.97
System
Linux server.atelieruldeit.ro 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
User
tbf
PHP Version
7.3.33
Software
Apache
Doc root
Writable
close
Edit File :
README.md
| Size :
11.89
KB
Copy
# Telegram Notifications Channel for Laravel [![Join PHP Chat][ico-phpchat]][link-phpchat] [![Chat on Telegram][ico-telegram]][link-telegram] [![Latest Version on Packagist][ico-version]][link-packagist] [![Software License][ico-license]](LICENSE.md) [![SensioLabsInsight][ico-sensiolabs]][link-sensiolabs] [![Quality Score][ico-code-quality]][link-code-quality] [![Total Downloads][ico-downloads]][link-packagist] This package makes it easy to send Telegram notification using [Telegram Bot API](https://core.telegram.org/bots) with Laravel. ## Contents - [Installation](#installation) - [Setting up your Telegram bot](#setting-up-your-telegram-bot) - [Usage](#usage) - [Text Notification](#text-notification) - [Attach a Photo](#attach-a-photo) - [Attach a Document](#attach-a-document) - [Attach a Location](#attach-a-location) - [Attach a Video](#attach-a-video) - [Attach a GIF File](#attach-a-gif-file) - [Routing a Message](#routing-a-message) - [Handling Response](#handling-response) - [On-Demand Notifications](#on-demand-notifications) - [Available Message methods](#available-message-methods) - [Available Location methods](#available-location-methods) - [Available File methods](#available-file-methods) - [Alternatives](#alternatives) - [Changelog](#changelog) - [Testing](#testing) - [Security](#security) - [Contributing](#contributing) - [Credits](#credits) - [License](#license) ## Installation You can install the package via composer: ```bash composer require laravel-notification-channels/telegram ``` ## Setting up your Telegram Bot Talk to [@BotFather](https://core.telegram.org/bots#6-botfather) and generate a Bot API Token. Then, configure your Telegram Bot API Token: ```php // config/services.php ... 'telegram-bot-api' => [ 'token' => env('TELEGRAM_BOT_TOKEN', 'YOUR BOT TOKEN HERE') ], ... ``` ## Usage You can now use the channel in your `via()` method inside the Notification class. ### Text Notification ```php 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() // Optional recipient user id. ->to($notifiable->telegram_user_id) // Markdown supported. ->content("Hello there!\nYour invoice has been *PAID*") // (Optional) Inline Buttons ->button('View Invoice', $url) ->button('Download Invoice', $url); } } ``` Here's a screenshot preview of the above notification on Telegram Messenger:  ### Attach a Photo ```php public function toTelegram($notifiable) { return TelegramFile::create() ->to($notifiable->telegram_user_id) // Optional ->content('Awesome *bold* text and [inline URL](http://www.example.com/)') ->file('/storage/archive/6029014.jpg', 'photo'); // local photo // OR using a helper method with or without a remote file. // ->photo('https://file-examples.com/wp-content/uploads/2017/10/file_example_JPG_1MB.jpg'); } ``` Preview:  ### Attach a Document ```php public function toTelegram($notifiable) { return TelegramFile::create() ->to($notifiable->telegram_user_id) // Optional ->content('Did you know we can set a custom filename too?') ->document('https://file-examples.com/wp-content/uploads/2017/10/file-sample_150kB.pdf', 'sample.pdf'); } ``` Preview:  ### Attach a Location ```php public function toTelegram($notifiable) { return TelegramLocation::create() ->latitude('40.6892494') ->longitude('-74.0466891'); } ``` Preview:  ### Attach a Video ```php public function toTelegram($notifiable) { return TelegramFile::create() ->content('Sample *video* notification!') ->video('https://file-examples.com/wp-content/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'); } ``` Preview:  ### Attach a GIF File ```php public function toTelegram($notifiable) { return TelegramFile::create() ->content('Woot! We can send animated gif notifications too!') ->animation('https://sample-videos.com/gif/2.gif'); // Or local file // ->animation('/path/to/some/animated.gif'); } ``` Preview:  ### Routing a Message You can either send the notification by providing with the chat ID of the recipient to the `to($chatId)` method like shown in the previous examples or add a `routeNotificationForTelegram()` method in your notifiable model: ```php /** * Route notifications for the Telegram channel. * * @return int */ public function routeNotificationForTelegram() { return $this->telegram_user_id; } ``` ### Handling Response You can make use of the [notification events](https://laravel.com/docs/5.8/notifications#notification-events) to handle the response from Telegram. On success, your event listener will recieve a [Message](https://core.telegram.org/bots/api#message) object with various fields as appropriate to the notification type. For a complete list of response fields, please refer the Telegram Bot API's [Message object](https://core.telegram.org/bots/api#message) docs. ### On-Demand Notifications > Sometimes you may need to send a notification to someone who is not stored as a "user" of your application. Using the `Notification::route` method, you may specify ad-hoc notification routing information before sending the notification. For more details, you can check out the [on-demand notifications](https://laravel.com/docs/5.8/notifications#on-demand-notifications) docs. ```php use NotificationChannels\Telegram\TelegramChannel; Notification::route(TelegramChannel::class, 'TELEGRAM_CHAT_ID') ->notify(new InvoicePaid($invoice)); ``` ### Available Message methods - `to($chatId)`: (integer) Recipient's chat id. - `content('')`: (string) Notification message, supports markdown. For more information on supported markdown styles, check out these [docs](https://telegram-bot-sdk.readme.io/reference#section-formatting-options). - `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. - `disableNotification($disableNotification = true)`: (bool) Send the message silently. Users will receive a notification with no sound. - `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](https://telegram-bot-sdk.readme.io/docs/sendmessage). ### Available Location methods - `to($chatId)`: (integer) Recipient's chat id. - `latitude($latitude)`: (float|string) Latitude of the location. - `longitude($longitude)`: (float|string) Longitude of the location. - `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. - `disableNotification($disableNotification = true)`: (bool) Send the message silently. Users will receive a notification with no sound. - `options([])`: (array) Allows you to add additional or override the payload. ### Available File methods - `to($chatId)`: (integer) Recipient's chat id. - `content('')`: (string) File caption, supports markdown. For more information on supported markdown styles, check out these [docs](https://telegram-bot-sdk.readme.io/reference#section-formatting-options). - `file($file, $type, $filename = null)`: Local file path or remote URL, `$type` of the file (Ex:`photo`, `audio`, `document`, `video`, `animation`, `voice`, `video_note_`) and optionally filename with extension. Ex: `sample.pdf`. You can use helper methods instead of using this to make it easier to work with file attachment. - `photo($file)`: Helper method to attach a photo. - `audio($file)`: Helper method to attach an audio file (MP3 file). - `document($file, $filename = null)`: Helper method to attach a document or any file as document. - `video($file)`: Helper method to attach a video file. - `animation($file)`: Helper method to attach an animated gif file. - `voice($file)`: Helper method to attach a voice note (`.ogg` file with OPUS encoded). - `videoNote($file)`: Helper method to attach a video note file (Upto 1 min long, rounded square video). - `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. - `disableNotification($disableNotification = true)`: (bool) Send the message silently. Users will receive a notification with no sound. - `options([])`: (array) Allows you to add additional or override the payload. ## Alternatives For advance usage, please consider using [telegram-bot-sdk](https://github.com/irazasyed/telegram-bot-sdk) instead. ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. ## Testing ```bash $ composer test ``` ## Security If you discover any security related issues, please email syed@lukonet.com instead of using the issue tracker. ## Contributing Please see [CONTRIBUTING](CONTRIBUTING.md) for details. ## Credits - [Irfaq Syed][link-author] - [All Contributors][link-contributors] ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information. [ico-phpchat]: https://img.shields.io/badge/Slack-PHP%20Chat-5c6aaa.svg?style=flat-square&logo=slack&labelColor=4A154B [ico-telegram]: https://img.shields.io/badge/@PHPChatCo-2CA5E0.svg?style=flat-square&logo=telegram&label=Telegram [ico-version]: https://img.shields.io/packagist/v/laravel-notification-channels/telegram.svg?style=flat-square [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square [ico-travis]: https://img.shields.io/travis/laravel-notification-channels/telegram/master.svg?style=flat-square [ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/laravel-notification-channels/telegram.svg?style=flat-square [ico-code-quality]: https://img.shields.io/scrutinizer/g/laravel-notification-channels/telegram.svg?style=flat-square [ico-downloads]: https://img.shields.io/packagist/dt/laravel-notification-channels/telegram.svg?style=flat-square [ico-sensiolabs]: https://img.shields.io/sensiolabs/i/d28e31ec-55ce-4306-88a3-84d5d14ad3db.svg?style=flat-square [link-phpchat]: https://phpchat.co/?ref=laravel-channel-telegram [link-telegram]: https://t.me/PHPChatCo [link-repo]: https://github.com/laravel-notification-channels/telegram [link-packagist]: https://packagist.org/packages/laravel-notification-channels/telegram [link-travis]: https://travis-ci.org/laravel-notification-channels/telegram [link-scrutinizer]: https://scrutinizer-ci.com/g/laravel-notification-channels/telegram/code-structure [link-sensiolabs]: https://insight.sensiolabs.com/projects/d28e31ec-55ce-4306-88a3-84d5d14ad3db [link-code-quality]: https://scrutinizer-ci.com/g/laravel-notification-channels/telegram [link-author]: https://github.com/irazasyed [link-contributors]: ../../contributors
Back