Skip to content

gdpa/chabok

Repository files navigation

Chabok notifications channel for Laravel 5.3+

Latest Version on Packagist Software License Build Status StyleCI Scrutinizer Code Quality Code Coverage Total Downloads

This package makes it easy to sent Chabok Notifications with Laravel 5.3+.

Contents

Installation

You can install the package via composer:

composer require gdpa/chabok

Install for laravel 7:

composer require gdpa/chabok:^3.1

Install for laravel 6:

composer require gdpa/chabok:^2.0

Install for laravel < 5.8:

composer require gdpa/chabok:^1.0

Setting up the Chabok service

Add your Chabok REST API Key to your config/services.php:

// config/services.php
...
'chabok' => [
    'app_id' => env('CHABOK_APP_ID'), 
    'key' => env('CHABOK_API_KEY'),
],
...

You can add additional configuration for adding to request from config:

// config/services.php
...
'chabok' => [
    'app_id' => env('CHABOK_APP_ID'), 
    'key' => env('CHABOK_API_KEY'),
    'additional' => [
        'timeout' => 5,
        'request_timeout' => 10
    ]
],
...

Note: If you want to test chabok set app_id to sandbox.

Usage

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

use NotificationChannels\Chabok\ChabokChannel;
use NotificationChannels\Chabok\ChabokMessage;
use Illuminate\Notifications\Notification;

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

    public function toChabok($notifiable)
    {
        return ChabokMessage::create()
            ->content("This is the Chabok notification description")
            ->data(['id' => 1, 'title' => 'This is notification data']);
    }
}

In order to let your Notification know which Chabok user you are targeting, add the routeNotificationForChabok method to your Notifiable model.

This method needs to return an uuid containing the your registered token on chabok.

public function routeNotificationForChabok()
{
    return [
        'uuid' => 'user-uuid-which-set-on-chabok-by-client',
    ];
}

Available methods

  • content(''): Accepts a string value for the Chabok notification content.
  • trackId(''): Accepts a string value for the Chabok notification trackId.
  • inApp(): Call this if you want to set the Chabok notification inApp to true.
  • live(): Call this if you want to set the Chabok notification live to true.
  • alert('''): Call this with no parameters if you want to set the Chabok notification useAsAlert to true. If you provide some string, it will set as alert text.
  • ttl(''): Accepts a integer value for the Chabok notification ttl.
  • data([]): Accepts a array for the Chabok notification data.
  • fallback([]): Accepts a array for the Chabok notification fallback.
  • clientId(''): Accepts a string value for the Chabok notification clientId.
  • notification([]): Accepts a array for the Chabok notification notification.
  • idr(): Call this if you want to set the Chabok notification idr to true.
  • silent(): Call this if you want to set the Chabok notification silent to true.
  • binary(''): Accepts a string value for the Chabok notification contentBinary.
  • type(''): Accepts a string value for the Chabok notification contentType.
  • id(''): Accepts a number value for the Chabok notification id.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email morteza.poussaneh@gmail.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.