Coder Social home page Coder Social logo

hinimajesty / hubtel-laravel-sms-channel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from norris1z/hubtel-laravel-sms-channel

0.0 1.0 0.0 28 KB

A package that makes it easy to send SMS using Hubtel in a Laravel 5.3+ application

License: MIT License

PHP 100.00%

hubtel-laravel-sms-channel's Introduction

Hubtel notification channel for Laravel 5.3+

Latest Stable Version Total Downloads License

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

Contents

Installation

To get the latest version of Hubtel Notification channel for Laravel 5.3+, simply require the project using Composer:

$ composer require norris1z/hubtel-laravel-sms-channel

If you use Laravel 5.5+ you don't need the following step. If not, once package is installed, you need to register the service provider. Open up config/app.php and add the following to the providers key.

  • NotificationChannels\Hubtel\HubtelServiceProvider::class

Setting up the Hubtel service

In your Hubtel account go to Applications page. Click on the details of the desired application and copy your apiKey and apiSecret

In your terminal run

$ php artisan vendor:publish --provider="NotificationChannels\Hubtel\HubtelServiceProvider"

This creates a hubtel.php file in your config directory.

Paste your apiCredentials in the config/hubtel.php configuration file. You may copy the example configuration below to get started:

'account' => [
        'key' => env('HUBTEL_API_KEY'),
        'secret' => env('HUBTEL_API_SECRET')
]

Or

Add the HUBTEL_API_KEY and HUBTEL_API_SECRET to your .env file

Usage

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

use Illuminate\Notifications\Notification;
use NotificationChannels\Hubtel\HubtelChannel;
use NotificationChannels\Hubtel\HubtelMessage;

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

    public function toSMS($notifiable)
    {
        return (new HubtelMessage)
			->from("JabClari")
			->to("2331234567890")
           	 	->content("Kim Kippo... Sup with you");
    }
}

In order to let your Notification know which phone number you are sending to, add the routeNotificationForSMS method to your Notifiable model e.g your User Model

public function routeNotificationForSMS()
{
    return $this->phone; // where phone is a cloumn in your users table;
}

Available Message methods

  • from($from) : set the sender's name or phone number
  • to($to) : set the recipient's phone number
  • content($content) : set the message content
  • registeredDelivery() : set delivery report request
  • clientReference($reference) : set the client reference number
  • type($type) : set the message type to be sent
  • udh($udh) : set the User Data Header of the SMS Message being sent
  • time($time) : set the time to deliver the message
  • flashMessage() : sends the message as a flash message

Read more about the avialable methods on the Hubtel Documentation Page

Changelog

Latest Notice

For developers who would want to use this package on VPS hosted applications, if the server location is US for which you have a US IP Address, you may need to seek whitelisting of the US Ip address from hubtel by mailing [email protected]. As i discovered through experience that the package would work fine on local machine because the IP used is a Ghanaian IP address but fails to work on a production server. Note however that this is not a package problem, as the package just organizes components for sending successful SMS messages within Laravel. It is even more challenging to know the cause of the problem when you are using laravel queues, because the response codes are not logged, the queue just logs Processing failed.Hubtels SMS server responds with a 403 Forbidden, when the same SMS is sent directly using Guzzlehttp on the production server (VPS). A 403 HTTP Response according to their website (hubtel) indicates the recipient has not given his/her approval to receive messages which is even more confusing. :)

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.

hubtel-laravel-sms-channel's People

Contributors

norris1z avatar hinimajesty avatar ovac avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.