Laravel Notification driver for Chatwork.
With Composer:
composer require yokuru/laravel-chatwork
After installing the package, please publish the configuration file.
php artisan vendor:publish --provider="Yokuru\Chatwork\ServiceProvider"
Open .env
and set your Chatwork API Token like as below.
CHATWORK_API_TOKEN=XXXXXXXXXXXXXXXXXX
Create a notification class like as below.
class SampleNotification extends ChatworkNotification
{
function toChatwork($notifiable): ChatworkMessage
{
return (new ChatworkMessage())
->text('This is sample notification');
}
}
Here are some examples of notification methods.
Please refer to the following page if you want to know more about Laravel Notification.
https://laravel.com/docs/notifications
Notification::route('chatwork', '{ROOM_ID}')
->notify(new SampleNotification());
Add the method routeNotificationForChatwork
to your model using Notifiable.
class User extends Authenticatable
{
use Notifiable;
public function routeNotificationForChatwork()
{
return '{ROOM_ID}';
}
}
Next, just notify when you want.
$user->notify(new SampleNotification());
You can create a chat message as below.
$message = new SampleNotification();
$message->to('999999')
->info("Please confirm this.\nhttp://example.com/", 'New Order #7489393')
->toAll()
->text('FYI');
$message->to('999999');
$message->toAll();
$message->text('This is simple text message.');
$message->info('This is information.');
$message->info('This is information.', 'Information title');
MIT