karix/karix-notification

Allow you to use karix sms and whatsapp as custom channel in laravel notifications

1.0.1 2020-07-06 13:21 UTC

This package is auto-updated.

Last update: 2024-05-06 21:38:48 UTC


README

This package makes it easy to send sms via Karix.io with Laravel 6.

Installation

You can install the package via composer:

composer require karix/karix-notification

Setting up the Karix id and token

Login to Karix.io and get your ID and Token, put that on your .env file and add your Karix Id and Token to your config/services.php:

// config/karix.php
<?php
    return [
        'id'            => env('KARIX_ID'),
        'token'         => env('KARIX_TOKEN'),
        'sms_from'      => env('KARIX_FROM'),
        'whatsapp_from' => env('KARIX_WHATSAPP')
    ];

Usage

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

use KarixTech\Karix\Broadcasting\KarixMessage;
use KarixTech\Karix\Broadcasting\KarixSMSChannel;
use KarixTech\Karix\Broadcasting\KarixWhatsappChannel;


class YourNotification extends Notification
{
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [KarixSMSChannel::class, KarixWhatsappChannel::class];
    }


    public function toSmSKarix($notifiable)
    {
        return KarixMessage::create()
            ->content(['text' => 'Your message comes here']);
    }

    public function toWhatsappKarix($notifiable)
    {
        return KarixMessage::create()
            ->content([
                'text' => 'Your message comes here',
                'media' => 'url-to-media',
                'location' => [
                    'latitude' => 'the latitude here',
                    'longitude' => 'the longitude here'
                ]
            ]);
    }
}

In order to let your Notification know that there is a new channel called KarixSmsChannel, add the routeNotificationForKarix method to your Notifiable model (probably your user.php file).

This method needs to return email of the user (if it's a private board) and the list ID of the Trello list to add the card to.

Caveat : Make sure you have a 'phone' field in your table along with country code like +91xxxxxxxxxx for which you are using this.

public function routeNotificationForKarix()
{
    return $this->phone;
}

Security

If you discover any security related issues, please email sarthak@bitfumes.com 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.