fuyuan9 / laravel-chatwork-notification-channel
A Laravel notification channel for Chatwork using Chatwork API.
Requires
- php: >=8.0
- illuminate/notifications: ^9.0|^10.0|^11.0
- polidog/php-chatwork-api: ^3.2
Requires (Dev)
- orchestra/testbench: ^7.0
This package is auto-updated.
Last update: 2025-05-14 12:54:16 UTC
README
A Laravel notification channel to send messages to the Japanese chat service Chatwork using the Chatwork API.
Installation
You can install the package via Composer:
composer require fuyuan9/laravel-chatwork-notification-channel
Requirements
- PHP >= 8.0
- Laravel >= 9.0
- Chatwork API token (provided by Chatwork)
Configuration
- Add your Chatwork API token to the
.env
file:
CHATWORK_API_TOKEN=your-api-token-here
- The package will automatically register the
ChatworkServiceProvider
to inject the Chatwork API client.
Usage
To send a notification using this package, you need to:
- Define a
toChatwork
method in yourNotification
class. - Specify the Chatwork room ID in your notifiable entity using
routeNotificationFor('chatwork')
.
Example Notification
Here’s an example of how to define a notification:
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use Fuyuan9\ChatworkMessage; class TaskCompletedNotification extends Notification { use Queueable; public function via($notifiable) { return ['chatwork']; } public function toChatwork($notifiable) { return ChatworkMessage::create("Task #1234 has been completed!"); } }
Example Notifiable Model
Here’s how you can define a notifiable model with the routeNotificationFor
method:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Notifications\Notifiable; class User extends Model { use Notifiable; public function routeNotificationForChatwork() { return 1234; // Replace with the Chatwork room ID } }
Sending the Notification
To send the notification, use the notify
method:
$user = User::find(1); $user->notify(new TaskCompletedNotification());
Testing
This package includes unit tests to verify its functionality.
Run the tests using PHPUnit:
vendor/bin/phpunit
Customization
If you want to customize how the Chatwork API client is created, you can modify the ChatworkServiceProvider
or extend the package with your own logic.
Contributing
Contributions are welcome! Please submit a pull request or open an issue for any feature requests or bugs.
License
This package is open-source and licensed under the MIT License.