e2kaneko / laravel-chatwork-notifications
Laravel 的 Chatwork 通知频道。
1.0.0
2017-01-04 11:51 UTC
Requires
- php: >=5.6.4
- guzzlehttp/guzzle: ~6.0
- illuminate/notifications: ^5.3
- illuminate/support: ^5.1|^5.2|^5.3
Requires (Dev)
- mockery/mockery: ^0.9.5
- orchestra/database: 3.3.x-dev
- orchestra/testbench: 3.3.x-dev
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-09-26 19:47:31 UTC
README
本包使得使用 Laravel 5.3 和 Chatwork API 发送 Chatwork 消息变得简单。
内容
安装
您可以通过 composer 安装此包。
composer require e2kaneko/laravel-chatwork-notifications
您必须安装服务提供者。
// config/app.php 'providers' => [ ... NotificationChannels\Chatwork\ChatworkServiceProvider::class, ],
配置
配置您的凭证。
// config/services.php ... 'chatwork' => [ 'api_token' => env('CHATWORK_API_TOKEN'), ], ...
用法
现在您可以在 Notification 类的 via()
方法中使用该频道。
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use NotificationChannels\Chatwork\ChatworkMessage; use NotificationChannels\Chatwork\ChatworkChannel; class ChatworkPosted extends Notification { use Queueable; public function __construct() { } public function via($notifiable) { return [ChatworkChannel::class]; } public function toChatwork($notifiable) { return (new ChatworkMessage()) ->message('message'); } }
或者
<?php namespace App\Notifications; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Notification; use NotificationChannels\Chatwork\ChatworkInformation; use NotificationChannels\Chatwork\ChatworkChannel; class ChatworkPosted extends Notification { use Queueable; public function __construct() { } public function via($notifiable) { return [ChatworkChannel::class]; } public function toChatwork($notifiable) { return (new ChatworkInformation()) ->informationTitle('InformationTitle') ->informationMessage('InformationMessage'); } }
消息路由
您可以通过提供接收者的 room_id 给 roomId($roomId) 方法,如上述示例所示,或者添加 routeNotificationForChatwork() 方法到您的 notifiable 模型中来发送通知。
... /** * Route notifications for the Chatwork channel. * * @return int */ public function routeNotificationForChatwork() { return '99999999'; // Chatwork Room ID } ...
可用的消息方法
消息(ChatworkMessage)
roomId('roomId')
: (integer|string) Chatwork 房间 ID。to('accountId')
: (integer|string) .message('message')
: (string) Chat 消息。
信息(ChatworkInformation)
roomId('roomId')
: (integer|string) Chatwork 房间 ID。informationTitle('title')
: (string) 信息框标题。informationMessage('message')
: (string) 信息框消息。
变更日志
有关最近更改的更多信息,请参阅 变更日志。
测试
$ composer test
安全
如果您发现任何与安全相关的问题,请通过电子邮件 kaneko@e2info.com 而不是使用问题跟踪器来联系。
贡献
有关详细信息,请参阅 贡献指南。
致谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。