blood72 / laravel-jandi
Jandi notification for Laravel
Requires
- php: ^7.2
- guzzlehttp/guzzle: ^6.0|^7.0
- illuminate/notifications: ^5.8|^6.0|^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- orchestra/testbench: ^3.8|^4.0|^5.0
- phpunit/phpunit: ^8.0
README
JANDI is business collaboration messenger tool made by Toss Lab, Inc.
This package is non-official and only provides a notification channel for JANDI incoming webhook connection.
Index
Requirement
- PHP >= 7.2
- Laravel 5.8+, 6.* or 7.*
Installation
Install using the composer.
composer require blood72/laravel-jandi
Additional work required if Auto-Discovery is disabled.
add the service provider to the providers
array in config/app.php
.
'providers' => [ // ... Blood72\Jandi\JandiServiceProvider::class, ],
also add this to the aliases
array to use JANDI notifier.
'aliases' => [ // ... 'Jandi' => \Blood72\Jandi\JandiFacade::class, ],
if you don't want to use JANDI notifier, follow the instructions below.
- add disable auto-discovery code in
composer.json
{ "extra": { "laravel": { "dont-discover": [ "blood72/laravel-jandi" ] } } }
- add this code in register() method in your service provider.
use Blood72\Jandi\Notifications\Channels\JandiWebhookChannel; use GuzzleHttp\Client as HttpClient; use Illuminate\Notifications\ChannelManager; use Illuminate\Support\Facades\Notification; // ... Notification::resolved(function (ChannelManager $service) { $service->extend('jandi', function ($app) { return new JandiWebhookChannel(new HttpClient); }); });
Configuration
By default, this package supports only one webhook url.
JANDI_WEBHOOK_URL=https://wh.jandi.com/connect-api/webhook/{team_id}/{payload_token}
you can publish a configuration file.
php artisan vendor:publish --provider="Blood72\Jandi\JandiServiceProvider"
and you can customize like this. in this case, a request will be sent to each URL.
'jandi_webhook_url' => [ env('JANDI_WEBHOOK_URL_1'), env('JANDI_WEBHOOK_URL_2'), // ... and so all ],
Usage
-
Message
-
to(): set a email for the Jandi team message (optional).
$message = (new JandiMessage)->to('test@example.org');
-
content(): set the content of the Jandi message.
$message = (new JandiMessage)->content('hello test');
create new object with content; __construct(), create()
$message = new JandiMessage('hello test'); $message = JandiMessage::create('hello test');
-
color(): set the color of the attachment section.
$message->color('#000000'); $message->color('#30fe2a');
it supports bootstrap 4 color scheme.
$message->primary(); $message->secondary(); $message->success(); $message->danger(); $message->warning(); $message->info(); $message->light(); $message->dark();
-
attachment(): define an attachment for the message. you can add multiple.
$message->attachment(function ($attachment) { $attachment->title('attachment-title'); $attachment->description('attachment-description'); $attachment->image('attachment-image-url'); }); $message->attachment(function ($attachment) { $attachment->title('attachment-title'); $attachment->description('attachment-description'); $attachment->image('attachment-image-url'); })->attachment(function ($attachment) { $attachment->title('attachment-another-title'); $attachment->description('attachment-another-description'); $attachment->image('attachment-another-image-url'); });
-
-
Notification
- notification override
you can use an abstract class defined. it requires definition of toJandi() method.use Blood72\Jandi\Notifications\JandiNotification; class JandiExampleNotification extends JandiNotification { public function toJandi($notifiable/* = null*/): JandiMessage { return (new JandiMessage)->to('test@example.org')->content('hello test'); } }
- send notification
- by anonymous notifiable
use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\Notification; Notification::send(new AnonymousNotifiable, new JandiExampleNotification
- by notifiable model
to use this,routeNotificationForJandi()
must be defined.use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; class ExampleNotifiableModel extends Model { use Notifiable; public function routeNotificationForJandi() { return 'hello routeNotificationForJandi() test'; } }
$notifiable = new ExampleNotifiableModel; $notification->send($notifiable, new JandiExampleNotification);
- by anonymous notifiable
- notification override
-
Facade
It supports the JandiNotifier class as a 'Jandi' facade.
-
send(): you can send message simply.
- it is sent based on the default route settings.
use Blood72\Jandi\Notifications\Messages\JandiMessage; $message = JandiMessage::create('hello test'); // or $message = new JandiMessage('hello test'); Jandi::send($message);
- of course, it can be done in a simple string form.
Jandi::send('hello test');
- you can set other notification class if you don't want to use default one.
Jandi::send('hello test', YourOtherNotification::class);
- it is sent based on the default route settings.
-
to(): you can specify the recipient URL(s).
- by string
Jandi::to('jandi-webhook-url')->send('hello test');
- by multiple params
Jandi::to('jandi-webhook-url-1', 'jandi-webhook-url-2')->send('hello test');
- by array
Jandi::to([ 'jandi-webhook-url-1', 'email-1' => 'jandi-webhook-url-2', 'email-2' => [ 'jandi-webhook-url-3', 'jandi-webhook-url-4', ], ]);
you can set email when sending 1:1 chat for team chat webhook URL (paid team only). email does not validate in jandi, and to send together, it must be string. - by object
to use this,routeNotificationForJandi()
orjandi_webhook_url
must be defined. it can be definedjandi_webhook_url
asgetJandiWebhookUrlAttribute()
.use App\User; public function routeNotificationForJandi() { return 'url'; } // in example, $user is User model instance. Jandi::to($user)->send('hello test');
if you want to set email,jandi_email
(orgetJandiEmailAttribute()
) is required.
- by string
-
Reference
- JANDI incoming webhook guide and for team one
- Laravel official Slack notification channel
- Guilherme Pressutto's laravel-slack
... and based on a code written by @kwonmory
License
This package is open-sourced software licensed under the MIT license.