TIP

Looking for an SMS provider? Check out CompareSMS (opens new window) and find the best SMS provider for you

# AfricasTalking notification channel for Laravel

Latest Version on Packagist (opens new window) Software License (opens new window) StyleCI (opens new window) Quality Score (opens new window) Total Downloads (opens new window)

This package makes it easy to send notifications using AfricasTalking (opens new window) with Laravel.

# Contents

# About

This package is part of the Laravel Notification Channels (opens new window) project. It provides additional Laravel Notification channels to the ones given by Laravel (opens new window) 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 (opens new window) and then go to your sandbox app Go To SandBox App (opens new window). Click on settings (opens new window) 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.

Please note if you do not have a VALID sender_ID remove "AT_FROM" from your .env or leave it as ""

AT_USERNAME=""
AT_KEY=""
AT_FROM="" // please note if you do not have a valid sender_ID remove this or leave it as ""

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 (opens new window) 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');

    }
}

You can also modify who the notification(SMS) is sent from, this will overide the AT_FROM= in your .env Please only do this if you have a VALID sender_ID

        return (new AfricasTalkingMessage())
                    ->content('Your SMS message content')
                    ->setFrom("set any sender id/name here");

# 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 (opens new window) for details.

# Credits

# License

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

# How do I say Thank you?

Please buy me a cup of coffee https://www.paypal.com/paypalme/osaigbovoemmanuel , Leave a star and follow me on Twitter (opens new window) .