Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Submit suggestions & pull requests here for new notification channels

License

Notifications You must be signed in to change notification settings

lkloon123/channels

 
 

Repository files navigation

MoceanAPI notifications channel for Laravel 5.5+

Latest Version on Packagist Software License Build Status StyleCI Quality Score Code Coverage Total Downloads

This package makes it easy to send notifications using MoceanAPI with Laravel 5.5+ and 6.0

Contents

Installation

To install the library, run this command in terminal:

composer require laravel-notification-channels/moceanapi

Setting up the MoceanAPI service

You must publish the config file as this will use Laravel Mocean as a package.

php artisan vendor:publish --provider="Mocean\Laravel\MoceanServiceProvider"

Setup ur configurations

// config/mocean.php
...
'MOCEAN_API_KEY' => 'YOUR MOCEAN_API_KEY',
'MOCEAN_API_SECRET' => 'YOUR MOCEAN_API_SECRET',
...

Usage

Create a notification class, refer laravel official docs

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\MoceanApi\MoceanApiChannel;
use NotificationChannels\MoceanApi\MoceanApiSmsMessage;

class InvoicePaid extends Notification
{
    use Queueable;
    
    public function via($notifiable)
    {
        return [MoceanApiChannel::class];
    }
    
    public function toMoceanapi($notifiable)
    {
        //return the text message u want to send here
        return 'You have received an invoice';
        
        //you can also return an array for custom options, refer moceanapi docs
        return [
            'mocean-text' => 'You have received an invoice',
            'mocean-dlr-url' => 'https://test.com'
        ];

        //you can also return a MoceanApiSmsMessage instance
        return (new MoceanApiSmsMessage())
            ->setText('You have received an invoice');
    }
}

to specify which attribute should be used to be a notifiable entity, create method routeNotificationForMoceanapi

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;
    
    public function routeNotificationForMoceanapi($notification)
    {
        //make sure user model has this attribute, else the notification will not be sent
        return $this->phone;
    }
}

send the notification to a user

$user->notify(new InvoicePaid());

you can also send the notification to a custom phone number without using user model

use Notification;

Notification:route('moceanapi', '60123456789')
    ->notify(new InvoicePaid());

Available Message methods

MoceanApiSmsMessage

  • setFrom(''): Set the SMS Sender ID
  • setTo(''): Set the phone number of the receiver
  • setText(''): Set the contents of the message

for more info, please visit MoceanAPI docs

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email [email protected] 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.

About

Submit suggestions & pull requests here for new notification channels

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%