meshgroup/megafon-notification-channel

v1.0.8 2022-07-28 13:41 UTC

This package is auto-updated.

Last update: 2024-04-28 17:30:47 UTC


README

This package makes it easy to send notifications using megafon with Laravel 5.3+.

Contents

Installation

You can install the package via composer:

composer require meshgroup/megafon-notification-channel

Then you must install the service provider:

// config/app.php
'providers' => [
    ...
    Meshgroup\Megafon\MegafonServiceProvider::class,
],

Setting up the Megafon service

Add your Megafon login, password and default sender name (or phone number) to your config/services.php:

// config/services.php
...
'megafon' => [
    'login'  => env('MEGAFON_LOGIN'),
    'password' => env('MEGAFON_PASSWORD'),
    'sender' => 'John_Doe'
],
...

If you want use other host than https://a2p-api.megalabs.ru/, you MUST set custom host WITH trailing slash.

// .env
...
MEGAFON_HOST=https://a2p-api.megalabs.ru/
...
// config/services.php
...
'megafon' => [
    ...
    'host' => env('MEGAFON_HOST'),
    ...
],
...

Usage

You can use the channel in your via() method inside the notification:

use Illuminate\Notifications\Notification;
use Meshgroup\Megafon\MegafonMessage;
use Meshgroup\Megafon\MegafonChannel;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [MegafonChannel::class];
    }

    public function toMegafon($notifiable)
    {
        return MegafonMessage::create("Task #{$notifiable->id} is complete!");
    }
}

In your notifiable model, make sure to include a routeNotificationForMegafon() method, which returns a phone number or an array of phone numbers.

public function routeNotificationForMegafon()
{
    return $this->phone;
}

Available methods

from(): Sets the sender's name or phone number.

content(): Set a content of the notification message.

sendAt(): Set a time for scheduling the notification message.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test