This package provides a simple and crisp way to access the Beem API endpoints. Sending notifications sms the laravel way.
You can install the package via composer:
composer require tomsgad/laravel-beem
After the package is installed, you can optionally publish the config file.
php artisan vendor:publish --tag="beem-config"
This is the contents of the published config file:
return [
'sms' => [
/*
|--------------------------------------------------------------------------
| Beem SMS API Key
|--------------------------------------------------------------------------
|
| Here we set sms api key that will be used to send the sms. Get your
| credentials from https://sms.beem.africa/#!/dashboard/profile/authentication
|
*/
'api_key' => env('BEEM_SMS_API_KEY', ''),
/*
|--------------------------------------------------------------------------
| Beem SMS Secret Key
|--------------------------------------------------------------------------
|
| Here we set sms secret key that will be used to send the sms. Get your
| credentials from https://sms.beem.africa/#!/dashboard/profile/authentication
|
*/
'secret_key' => env('BEEM_SMS_SECRET_KEY', ''),
/*
|--------------------------------------------------------------------------
| Beem SMS Sender Name
|--------------------------------------------------------------------------
|
| Here we set a sender name that will be used to send the sms. Default
| sender name is `INFO`. Please only use sender names that have been registered
| or the sms will not be sent.
|
*/
'sender_name' => env('BEEM_SMS_SENDER_NAME', ''),
]
];
You will need to get your api details from your profile. Here are the steps you can follow (Described by Beem):
- Create a free account on https://login.beem.africa.
- On completing your registration you will get a confirmation email. Click on the link or paste the link into your browser to validate the account.
- Log into your account with your username & password on https://login.beem.africa.
- You should have received some free test credits and a default sender ID of ‘INFO’ should be Active.
- Visit the 'Profile ' tab and click on ‘Authentication Information’.
- Click generate API Key and Secret to obtain these. Note that the Secret is only displayed once, so please store this safely.
- Use this API Key and Secret to start sending messages using the API defined below.
Set up your .env
file with the credentials you go from the procedure above
BEEM_SMS_API_KEY=""
BEEM_SMS_SECRET_KEY=""
BEEM_SMS_SENDER_NAME=""
Add routeNotificationForBeem
to your notifiable model and define how to get phone number. Note: The method should return an array or a countable. I have let it that way so you can implement it the way you see fit.
<?php
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use Notifiable;
public function routeNotificationForBeem()
{
return array($this->phone);
}
}
Now you can use the channel in your (via)
method inside the notification. This example will work with settings from .env
file.
use Illuminate\Notifications\Notification;
use Tomsgad\Beem\SMS\BeemMessage;
class Demo extends Notification
{
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['beem'];
}
public function toBeem($notifiable)
{
return (new BeemMessage())
->content('Message Goes Here');
}
}
You can also send a notification on the fly without setting the .env
variables. This is useful if you set the details dynamically or you have a multi-tenant application.
use Illuminate\Notifications\Notification;
use Tomsgad\Beem\SMS\BeemMessage;
class Demo extends Notification
{
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['beem'];
}
public function toBeem($notifiable)
{
return (new BeemMessage())
->content('Message Goes Here')
->sender('senderNameGoesHere')
->secretKey('secretKeyGoesHere')
->apiKey('apiKeyGoesHere');
}
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security-related issues, please email thomson@magurugroup.co.tz instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.