appslabke/laravel-notification-channels-africastalking

This package makes it easy to send notifications via AfricasTalking with Laravel

v2.4.1 2020-10-13 05:54 UTC

This package is auto-updated.

Last update: 2024-09-18 15:46:32 UTC


README

Latest Version on Packagist Software License StyleCI Quality Score Total Downloads

This package makes it easy to send notifications using AfricasTalking with Laravel.

Contents

About

This package is part of the Laravel Notification Channels project. It provides additional Laravel Notification channels to the ones given by Laravel itself.

The AfricasTalking channel makes it possible to send out Laravel notifications as a SMS using AfricasTalking API.

Installation

You can install this package via composer:

composer require laravel-notification-channels/africastalking

The service provider gets loaded automatically.

Setting up the AfricasTalking service

You will need to Register and then go to your sandbox app Go To SandBox App. Click on settings Within this page, you will generate your Username and key. Place them inside your .env file. Remember to add your Sender ID that you will be using to send the messages.

AT_USERNAME=""
AT_KEY=""
AT_FROM=""

To load them, add this to your config/services.php . This will load the AfricasTalking data from the .env file.file:

'africastalking' => [
    'username'      => env('AT_USERNAME'),
    'key'           => env('AT_KEY'),
    'from'          => env('AT_FROM'),
]

Add the routeNotifcationForAfricasTalking method on your notifiable Model. If this is not added, the phone_number field will be automatically used.

<?php

namespace App;

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

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Route notifications for the Africas Talking channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
     */
    public function routeNotificationForAfricasTalking($notification)
    {
        return $this->phone;
    }
}

Usage

To use this package, you need to create a notification class, like NewsWasPublished from the example below, in your Laravel application. Make sure to check out Laravel's documentation for this process.

<?php

use NotificationChannels\AfricasTalking\AfricasTalkingChannel;
use NotificationChannels\AfricasTalking\AfricasTalkingMessage;

class NewsWasPublished extends Notification
{

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

    public function toAfricasTalking($notifiable)
    {
		return (new AfricasTalkingMessage())
                    ->content('Your SMS message content');

    }
}

Testing

$ composer test

Security

If you discover any security-related issues, please email osaigbovoemmanuel1@gmail.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.

How do I say Thank you?

Leave a star and follow me on Twitter .