leochien / laravel-notification-channel-line
LINE Notifications Channel for Laravel
Requires
- php: >=8.1
- illuminate/notifications: ~10.0 || ~11.0
- illuminate/support: ~10.0 || ~11.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^10.0
README
Introduction
This package makes it easy to send notifications using LINE with Laravel 5.6+.
Contents
Installation
You can install the package via composer:
$ composer require leochien/laravel-notification-channel-line
Setting up the LINE service
In order to send message to LINE channels, you need to obtain Messaging API overview.
Add your LINE Message API Token to your config/services.php
:
// config/services.php ... 'line_message_api' => [ 'token' => env('LINE_MESSAGE_TOKEN', 'YOUR MESSAGE TOKEN HERE'), ], ...
Usage
Text Message
Reference: Text Message
You can use the channel in your via()
method inside the notification:
use Illuminate\Notifications\Notification; use LeoChien\LaravelNotificationChannelLine\LineMessage; use LeoChien\LaravelNotificationChannelLine\LineWebhookChannel; class TaskCompleted extends Notification { public function via($notifiable): array { return [ 'line', ]; } public function toLine($notifiable): LineMessage { return LineMessage::create() ->to('line_user_id') ->from('message_api_token') // optional if set in config ->content('Test message'); } }
Available methods
create()
: Initial a message instance.
from()
: Optional. Sets the sender's access token. Default to the set in config.
to()
: Required. Specifies the line user id to send the notification to.
content()
: Required. Sets a content of the notification message. Only support plain text for now.
Template Messages
Reference: Template messages
Currently, only 'buttons' and 'confirm' template types are supported. We will update to support 'carousel' and 'image carousel' as soon as possible.
use Illuminate\Notifications\Notification; use LeoChien\LaravelNotificationChannelLine\LineTemplateMessage; use LeoChien\LaravelNotificationChannelLine\LineWebhookChannel; class TaskCompleted extends Notification { public function via($notifiable): array { return [ 'line', ]; } public function toLine($notifiable): LineMessage { return LineTemplateMessage::create() ->to('line_user_id') ->from('message_api_token') // optional if set in config ->type('buttons') ->thumbnailImageUrl('https://fakeimg.pl/350x200') ->text("This is the text of the message") ->actions([ [ 'type' => 'uri', 'label' => 'See more', 'uri' => 'https://example.com', ], ]); } }
Available methods
from()
: Sets the sender's access token.
to()
: Specifies the line user id to send the notification to.
type()
: Required. template type, allowed value: buttons, confirm, carousel, image_carousel.
thumbnailImageUrl()
: Optional. Image URL (Max character limit: 2000). Protocol: HTTPS (TLS 1.2 or later). Image format: JPEG or PNG. Max width: 1024px. Max file size: 10 MB.
imageAspectRatio()
: Optional. Aspect ratio of the image. Allowed values: rectangle(1.51:1), square(1:1). Default: rectangle.
imageSize()
: Optional. Size of the image. Allowed Values: cover, contain. Default: cover.
imageBackgroundColor()
: Optional. Background color of the image. Specify a RGB color value. Default: #FFFFFF (white)
title()
: Optional. Message Title, max character limit: 40.
text()
: Required. Message text, max character limit: 160 (no image or title), max character limit: 60 (message with an image or title).
defaultAction()
: Optional. Action when image, title or text area is tapped.
actions()
: Required. Action when tapped, max objects: 4.
Security
If you discover any security related issues, please email s950329@hotmail.com instead of using the issue tracker.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.