Laravel Flock Notification Channel
, (*1)
This package makes it easy to send notifications using Flock with Laravel 5.3+., (*2)
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:, (*3)
composer require vrajroham/laravel-flock-notification
Register the ServiceProvider in your config/app.php (If you are using Laravel < 5.5):, (*4)
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., (*5)
For more information see the flock documentation to create incoming webhook., (*6)
Usage
You can now send messages in Flock Group by creating a FlockMessage:, (*7)
- Add
routeNotificationForFlock() to App\User model
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, (*8)
Examples
Text as contents
, (*11)
public function toFlock($notifiable)
{
return FlockMessage::create()
->content('This is text notification.');
}
Change sender name and image
, (*12)
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
, (*13)
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
, (*14)
public function toFlock($notifiable)
{
return FlockMessage::create()
->notification('You have important message')
->content('This is text notification.');
}
, (*15)
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);
});
});
}
, (*16)
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
, (*17)
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
, (*18)
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., (*19)
Testing
bash
$ composer test, (*20)
Security
If you discover any security related issues, please email vaibhavraj.developer@gmail.com instead of using the issue tracker., (*21)
Contributing
Please see CONTRIBUTING for more information about contributors., (*22)
Credits
License
The MIT License (MIT). Please see License File for more information., (*23)