ishaarat/lara-ishaarat

Send Whatsapp notifications from your laravel application using Ishaarat

1.0.4 2023-09-03 12:35 UTC

This package is auto-updated.

Last update: 2024-12-03 15:46:25 UTC


README

GitHub License Latest Version on Packagist Total Downloads

This is a Laravel Package for Ishaarat Gateway Integration. Now Sending Whatsapp messages is easy.

📦 Install

Via Composer

$ composer require ishaarat/lara-ishaarat

If you are using Laravel 5.5 and higher, the service provider will be automatically registered.

For older versions, you have to add the service provider and alias to your config/app.php:

'providers' => [
    ...
    Ishaarat\LaraIshaarat\Providers\IshaaratServiceProvider::class,
]

'alias' => [
    ...
    'Ishaarat' => Ishaarat\LaraIshaarat\Facades\WA::class,
]

⚡ Configure

Publish the config file

php artisan vendor:publish --provider="Ishaarat\LaraIshaarat\Providers\IshaaratServiceProvider"

Then fill your auth key and app key you got from your Ishaarat Account.

// Eg. for SNS.
'auth_key' => env('ISHAARAT_AUTH_KEY', 'xxxxxx'),
'app_key' => env('ISHAARAT_APP_KEY', 'xxxx'),

or you can add these keys in your .env file

ISHAARAT_AUTH_KEY=xxxxxx
ISHAARAT_APP_KEY=xxxxx

🔥 Usage

By using Facade method.

# On the top of the file.
use Ishaarat\LaraIshaarat\Facades\WA;

////

# In your Controller.
WA::send("this message", function($waMsg) {
    $waMsg->to(['Number 1', 'Number 2']); # The numbers to send to.
});
# OR...
WA::send("this message")->to(['Number 1', 'Number 2'])->dispatch();

By using helper method

ishaaratWA()->send("this message", function($waMsg) {
    $waMsg->to(['Number 1', 'Number 2']); # The numbers to send to.
});

ishaaratWA()->send("this message")->to(['Number 1', 'Number 2'])->dispatch();

😍 Channel Usage

First you have to create your notification using php artisan make:notification command. then WAChannel::class can be used as channel like the below:

namespace App\Notifications;

use Ishaarat\LaraIshaarat\Builder;
use Illuminate\Bus\Queueable;
use Ishaarat\LaraIshaarat\Channels\WAChannel;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;

class InvoicePaid extends Notification
{
    use Queueable;

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

    /**
     * Get the repicients and body of the notification.
     *
     * @param  mixed  $notifiable
     * @return Builder
     */
    public function toWhatsapp($notifiable)
    {
        return (new Builder)
            ->send('this message')
            ->to('some number');
    }
}

Tip: You can use the same Builder Instance in the send method.

$builder = (new Builder)
    ->send('this message')
    ->to('some number');

WA::send($builder);