fcorz/laravel-line-notify

1.0.0 2021-02-25 03:38 UTC

This package is auto-updated.

Last update: 2024-09-26 10:53:00 UTC


README

🌈 laravel line notify notification

Latest Version on Packagist Build Status Total Downloads License: MIT

Laravel implements the line notify message notification function. Including the binding of code in exchange for access token and notification channel message push.

Installation

you can install the package via composer:

composer require fcorz/laravel-line-notify

publish config

php artisan vendor:publish --provider="Fcorz\LaravelLineNotify\LaravelLineNotifyServiceProvider"

Usage

simple

// get access_token by code
app('line-notify')->getAccessToken("O97YoWeYMV6vW3uYPFgPAC");

// response
{
   "status":200,
   "message":"access_token is issued",
   "access_token":"1vIvPoq4aG4UOJYoQ6oriAUPvDNxxxxxxxxxxx"
}

// notify
$message = (new LaravelLineMessage())->message('hello world');
app('line-notify')->sendNotify($message, "access_token");

facade

// get access_token by code
LaravelLineNotifyFacade::getAccessToken("O97YoWeYMV6vW3uYPFgPAC");

// notify
$message = (new LaravelLineMessage())->message('hello world');
LaravelLineNotifyFacade::sendNotify($message, "access_token");

notification

user model notifiable

public function routeNotificationForLine($notification)
{
    return $this->notify_access_token;
}

create your notification ( you can also not use the queue )

use App\Models\UserMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Notification;


class LineNotification extends Notification implements ShouldQueue
{
    use Queueable;

    protected $message;

    public function __construct($message, $delay = 0)
    {
        $this->queue = 'notification';

        $this->delay = $delay;

        $this->message = $message;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param mixed $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['line'];
    }

    /**
     * @param $notifable
     * @return LineTemplateService
     */
    public function toLineNotify($notifable)
    {
        return (new LaravelLineMessage())->message($this->message);
    }
}

call notify()

$receiver->notify(new LineNotification('hello world'));

Security

If you discover any security related issues, please email fengchenorz@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.