vrajroham/laravel-flock-notification
Composer 安装命令:
composer require vrajroham/laravel-flock-notification
包简介
Laravel Flock Notification Channel
README 文档
README
This package makes it easy to send notifications using Flock with Laravel 5.3+.
return FlockMessage::create() ->content('Laravel Flock Notification Channel') ->attachment(function ($attachment) { $attachment->title('Button Widget') ->description('Description') ->color('#fff000'); });
Contents
Installation
Install this package with Composer:
composer require vrajroham/laravel-flock-notification
Register the ServiceProvider in your config/app.php (If you are using Laravel < 5.5):
Vrajroham\LaravelFlockNotification\FlockServiceProvider::class,
Setting up the flock service
Create incoming webhook by going to https://admin/flock.com or by choosing Manage your team in Flock desktop app.
For more information see the flock documentation to create incoming webhook.
Usage
You can now send messages in Flock Group by creating a FlockMessage:
- Add
routeNotificationForFlock()toApp\Usermodel
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'); }); } }
Available Message methods
Complete message and attachment schema can be found at Flock Message Object and Flock Attachment Object
- content(
$string) - flockml(
$string) //FlockML as attachment - 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.com', 'desktopType' => 'sidebar', ], 'id' => 'btn1' ], ... ]
-
Examples
Text as contents
public function toFlock($notifiable) { return FlockMessage::create() ->content('This is text notification.'); }
Change sender name and image
public function toFlock($notifiable) { return FlockMessage::create() ->content('This is text notification.') ->sendAs("Vaibhavraj", 'https://avatars1.githubusercontent.com/u/12662173?s=460&v=4'); }
Change message color
public function toFlock($notifiable) { return FlockMessage::create() ->attachments(function ($attachment){ $attachment->title('This is error message.') ->color('#FF0000'); //Red }); }
Change notification text for mobile application
public function toFlock($notifiable) { return FlockMessage::create() ->notification('You have important message') ->content('This is text notification.'); }
Website as widget
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); }); }); }
Buttons
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.com/favicon.png', 'action' => [ 'type' => 'openBrowser', 'url' => 'https://laravel.com', ], 'id' => 'btn2' ] ]); }); }
Image as attachment
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'); }); }); }); }
Download Link
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
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Security
If you discover any security related issues, please email vaibhavraj.developer@gmail.com instead of using the issue tracker.
Contributing
Please see CONTRIBUTING for more information about contributors.
Credits
License
The MIT License (MIT). Please see License File for more information.
vrajroham/laravel-flock-notification 适用场景与选型建议
vrajroham/laravel-flock-notification 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.65k 次下载、GitHub Stars 达 17, 最近一次更新时间为 2018 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 vrajroham/laravel-flock-notification 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vrajroham/laravel-flock-notification 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 7.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-28