vrajroham / laravel-flock-notification
Laravel Flock 通知通道
v2.0.0
2021-11-27 09:11 UTC
Requires
- php: >=7.4 || >=8.0 || >=8.1
- illuminate/notifications: >=7
- illuminate/support: >=7
Requires (Dev)
- mockery/mockery: dev-master
- phpunit/phpunit: >=7
This package is auto-updated.
Last update: 2024-09-12 11:43:14 UTC
README
此包简化了使用 Flock(https://flock.com/)与 Laravel 5.3+ 发送通知的过程。
return FlockMessage::create() ->content('Laravel Flock Notification Channel') ->attachment(function ($attachment) { $attachment->title('Button Widget') ->description('Description') ->color('#fff000'); });
内容
安装
使用 Composer 安装此包
composer require vrajroham/laravel-flock-notification
在您的 config/app.php 中注册 ServiceProvider(如果您使用的是 Laravel < 5.5)
Vrajroham\LaravelFlockNotification\FlockServiceProvider::class,
设置 flock 服务
通过访问 https://admin/flock.com 或在 Flock 桌面应用程序中选择“管理您的团队”来创建一个传入的 webhook。
有关更多信息,请参阅 flock 文档 以创建传入 webhook。
使用方法
您现在可以通过创建一个 FlockMessage 在 Flock 群组中发送消息。
- 将
routeNotificationForFlock()
添加到App\User
模型中
public function routeNotificationForFlock() { return $this->flock_webhook_url; }
<?php use Vrajroham\LaravelFlockNotification\FlockChannel; use Vrajroham\LaravelFlockNotification\FlockMessage; use Illuminate\Notifications\Notification; class OderCreated extends Notification { public function via($notifiable) { return [FlockChannel::class]; } public function toFlock($notifiable) { return FlockMessage::create() ->content('Order created') ->attachments(function ($attachment) { $attachment->title('View order') ->description('Order description') ->color('#fff000'); }); } }
可用的消息方法
完整消息和附件的架构可以在 Flock 消息对象 和 Flock 附件对象 中找到。
- content(
$string
) - flockml(
$string
) //FlockML 作为附件 - notification(
$string
) - sendAs(
$senderName
,$profileImageUrl
) - attachments(
callback
)-
title(
$string
) -
description(
$string
) -
color(
$string
) -
url(
$url
) -
id(
$string
) -
forward(
$boolean
) -
views(
callback
)- widget(
$source
,$height
,$width
) - html(
$inlineHtmlString
,$height
,$width
) - flockml(
$flockMLString
) - image(
callback
)- original(
$url
,$height
,$width
) - thumbnail(
$url
,$height
,$width
) - filename(
$filename
)
- original(
- widget(
-
downloads(
array
)// Only 'src' field is mandatory. [ [ 'src' => 'https://vrajroham.me/dl/vrajroham_cv.pdf', 'mime' => 'application/pdf', 'filename' => 'CV.pdf', 'size' => 2000 //bytes ], ... ]
- buttons(
array
)[ [ 'name' => 'Button Name', 'icon' => 'https://avatars1.githubusercontent.com/u/12662173?s=460&v=4', 'action' => [ 'type' => 'openBrowser', 'url' => 'https://laravel.net.cn', 'desktopType' => 'sidebar', ], 'id' => 'btn1' ], ... ]
-
示例
作为内容的文本
public function toFlock($notifiable) { return FlockMessage::create() ->content('This is text notification.'); }
更改发送者名称和图像
public function toFlock($notifiable) { return FlockMessage::create() ->content('This is text notification.') ->sendAs("Vaibhavraj", 'https://avatars1.githubusercontent.com/u/12662173?s=460&v=4'); }
更改消息颜色
public function toFlock($notifiable) { return FlockMessage::create() ->attachments(function ($attachment){ $attachment->title('This is error message.') ->color('#FF0000'); //Red }); }
更改移动应用程序的通知文本
public function toFlock($notifiable) { return FlockMessage::create() ->notification('You have important message') ->content('This is text notification.'); }
作为小部件的网站
public function toFlock($notifiable) { return FlockMessage::create() ->attachments(function ($attachment){ $attachment->title('Website as widget') ->views(function ($view){ $view->widget('https://vrajroham.me', 400, 400); }); }); }
按钮
public function toFlock($notifiable) { return FlockMessage::create() ->attachments(function ($attachment){ $attachment->title('This are the buttons') ->buttons([ [ 'name' => 'Button 1', 'icon' => 'https://avatars1.githubusercontent.com/u/12662173?s=460&v=4', 'action' => [ 'type' => 'openBrowser', 'url' => 'https://github.com/vrajroham', ], 'id' => 'btn1' ], [ 'name' => 'Button 2', 'icon' => 'https://laravel.net.cn/favicon.png', 'action' => [ 'type' => 'openBrowser', 'url' => 'https://laravel.net.cn', ], 'id' => 'btn2' ] ]); }); }
作为附件的图像
public function toFlock($notifiable) { return FlockMessage::create() ->attachments(function ($attachment) { $attachment->title('Image as attachment') ->views(function ($view) { $view->image(function ($image) { $image->original('https://avatars1.githubusercontent.com/u/12662173?s=460&v=4',400,400) ->thumbnail('https://avatars1.githubusercontent.com/u/12662173?s=460&v=4',100,100) ->filename('vaibhavraj.png'); }); }); }); }
下载链接
public function toFlock($notifiable) { return FlockMessage::create() ->attachments(function ($attachment) { $attachment->title('Download link') ->downloads([ [ 'src' => 'https://vrajroham.me/dl/vrajroham_cv.pdf', 'mime' => 'application/pdf', 'filename' => 'file-1.pdf', 'size' => 1500 ], ]); }); }
变更日志
请参阅 CHANGELOG 了解最近更改了什么。
测试
$ composer test
安全性
如果您发现任何与安全性相关的问题,请通过电子邮件 vaibhavraj.developer@gmail.com 而不是使用问题跟踪器来报告。
贡献
请参阅 CONTRIBUTING 了解有关贡献者的更多信息。
致谢
许可证
MIT 许可证(MIT)。有关更多信息,请参阅 许可证文件。