yokuru / laravel-chatwork
Laravel 通知驱动程序用于 Chatwork。
v0.0.1
2019-06-29 10:45 UTC
Requires
- php: ^7.1
- guzzlehttp/guzzle: ^6.3
- illuminate/notifications: ^5.8
Requires (Dev)
- mockery/mockery: ^1.2
- orchestra/testbench: ^3.8
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^7.5 || ^8.2
This package is auto-updated.
Last update: 2024-09-18 01:01:14 UTC
README
Laravel 通知驱动程序用于 Chatwork。
安装
使用 Composer
composer require yokuru/laravel-chatwork
安装包后,请发布配置文件。
php artisan vendor:publish --provider="Yokuru\Chatwork\ServiceProvider"
用法
1. 设置 Chatwork API 令牌
打开 .env
并设置您的 Chatwork API 令牌,如下所示。
CHATWORK_API_TOKEN=XXXXXXXXXXXXXXXXXX
2. 创建通知类
创建一个如下所示的通知类。
class SampleNotification extends ChatworkNotification
{
function toChatwork($notifiable): ChatworkMessage
{
return (new ChatworkMessage())
->text('This is sample notification');
}
}
3. 发送通知
以下是一些通知方法的示例。
如果您想了解更多关于 Laravel 通知的信息,请参考以下页面。
https://laravel.net.cn/docs/notifications
按需通知示例
Notification::route('chatwork', '{ROOM_ID}')
->notify(new SampleNotification());
使用 Notifiable 特性的示例
使用 Notifiable 向您的模型添加 routeNotificationForChatwork
方法。
class User extends Authenticatable
{
use Notifiable;
public function routeNotificationForChatwork()
{
return '{ROOM_ID}';
}
}
接下来,只需在需要时进行通知。
$user->notify(new SampleNotification());
构建消息
您可以创建如下所示的聊天消息。
$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