Giter Site home page Giter Site logo

telenor-sms's Introduction

TelenorBulkSms

Latest Version on Packagist

This package makes it easy to send sms notification using Telenor Myanmar Business SMS service with laravel. You can access Telenor Myanmar Developer Portal from here.

Installation

Via Composer

$ composer require solvecase/telenorbulksms

Setting Up

Open up .env file and add the following:

TELENOR_API_BASE_URL=https://prod-apigw.mytelenor.com.mm/
TELENOR_SMS_CALLBACK_URL=oauth2/telenorsms/callback
TELENOR_SMS_CLIENT_ID=
TELENOR_SMS_CLIENT_SECRET=
TELENOR_SMS_SENDER=
TELENOR_SMS_USERNAME=
TELENOR_SMS_PASSWORD=

Open up config/app.php and find the providers key.

'providers' => [
    ...
    SolveCase\TelenorBulkSms\TelenorBulkSmsServiceProvider::class,
]

Laravel Task Scheduling is used to request bearer access token every hour and save it in cache. So, add the following Cron entry to your server interval every minute.

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Usage

<?php

namespace App;

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

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Route notifications for the telenor sms channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
     */
    public function routeNotificationForTelenorSms($notification)
    {
        return $this->mobile_no; // 959xxxxxxxx
    }
}
<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use SolveCase\TelenorBulkSms\TelenorMessage;
use SolveCase\TelenorBulkSms\TelenorSmsChannel;

class InvoicePaid extends Notification
{

    /**
     * Get the notification channels.
     *
     * @param  mixed  $notifiable
     * @return array|string
     */
    public function via($notifiable)
    {
        return [TelenorSmsChannel::class];
    }

    /**
     * Get the sms representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return TelenorMessage
     */
    public function toTelenorSms($notifiable)
    {
        return TelenorMessage::create()
			->content($notifiable->inovice->id . ' has been paid!');
    }
}
$user->notify(new InvoicePaid($invoice));
Using The Notification Facade
Notification::send($users, new InvoicePaid($invoice));
Sending Sms using TelenorSmsClient
<?php

namespace App\Http\Controllers;

use SolveCase\TelenorBulkSms\TelenorSmsClient;
use SolveCase\TelenorBulkSms\TelenorMessage;

class SmsController extends Controller{

	public function sendsms(){
		try{
			$message = TelenorMessage::create('Hello, Good Morning!')
				->to(959xxxxxxxx)->toArray();
			$client = new TelenorSmsClient();
			$response = $client->send($message)->getBody();
		}catch(\Exception $ex){
			return back()->withErrors('Something went wrong.');
		}
	}

}

Change log

Please see the changelog for more information on what has changed recently.

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

License

license. Please see the license file for more information.

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.