laravel-notification-channels / bearychat
BearyChat notifications channel for Laravel.
Installs: 7 411
Dependents: 1
Suggesters: 2
Security: 0
Stars: 22
Watchers: 6
Forks: 3
Open Issues: 0
Requires
- php: >=5.6.4
- elfsundae/laravel-bearychat: ~1.4
- illuminate/notifications: ~5.3|~6.0|~7.0|~8.0
Requires (Dev)
- mockery/mockery: ~1.0
- phpunit/phpunit: ~5.7|~6.0|~7.0|~8.0
README
This package makes it easy to send notifications using BearyChat with Laravel.
Channel Deprecated
BearyChat was discontinued. As such, this channel will no longer receive updates and is being deprecated.
Contents
Installation
You can install the package via Composer:
$ composer require laravel-notification-channels/bearychat
Once the package is installed, you need to register the service provider by adding the following to the providers
array in config/app.php
:
ElfSundae\BearyChat\Laravel\ServiceProvider::class,
This package is based on laravel-bearychat, you may publish the config file if you have not done yet:
$ php artisan vendor:publish --tag=bearychat
Setting up the BearyChat service
You may create an Incoming Robot in your BearyChat team account, and read the payload format.
Usage
Basic Usage
You can now use the channel in the via()
method inside the Notification class.
<?php namespace App\Notifications; use Illuminate\Notifications\Notification; use NotificationChannels\BearyChat\BearyChatChannel; use ElfSundae\BearyChat\Message; class InvoicePaid extends Notification { public function via($notifiable) { return [BearyChatChannel::class]; } public function toBearyChat($notifiable) { return (new Message) ->text('foo') ->add('bar'); } }
You can also use a BearyChat Client
to create the message for notification, and the client's message defaults will be used for creating this new Message
instance.
public function toBearyChat($notifiable) { return bearychat('admin')->text('New VIP has been paid!'); }
- For more details about BearyChat
Client
andMessage
, please read the documentation of the BearyChat PHP package.- For more details about
BearyChat
facade orbearychat()
helper function, please read the documentation of the original Laravel package.
Routing Notifications
To route BearyChat notifications to the proper Robot, define a routeNotificationForBearyChat
method on your notifiable entity.
class User extends Authenticatable { use Notifiable; public function routeNotificationForBearyChat() { return 'https://hook.bearychat.com/...'; } }
You can also route the user, channel or configured client in the routeNotificationForBearyChat
method.
'@Elf'
will route the notification to user "Elf".'#iOS-Dev'
will route the notification to channel "iOS-Dev".'http://webhook/url'
will route the notification to an Incoming Robot.'Server'
will route the notification via a client which named "Server" in your config fileconfig/bearychat.php
, and the message defaults of this client will be applied to the outgoing notification message.
Available Message Methods
text()
: (string) Message content.notification()
: (string) Message notification.markdown(true)
: (boolean) Indicates the message should be parsed as markdown syntax.add()
: (mixed) Add an attachment to the message. The parameter can be an payload array that contains all of attachment's fields. The parameters can also be attachment's fields that in order of "text", "title", "images" and "color".addImage()
:($image, $desc = null, $title = null)
Add an image attachment to the message.content()
:($text, $markdown, $notification)
or($text, $attachment_text, $attachment_title, $attachment_images, $attachment_color)
.remove()
: (mixed) Remove attachment(s), you can pass an integer of attachment index, or an array of indices.channel()
: (string) The channel that the message should be sent to.user()
: (string) The user that the message should be sent to.to()
: (string) The target (user or channel) that the message should be sent to. The target may be started with "@" for sending to an user, and the channel's starter mark "#" is optional.
$message = (new Message) ->text('message content') ->notification('notification for this message') ->add('attachment content', 'attachment title', 'http://path/to/image', '#FF0000') ->to('@Boss');
A notification uses the above Message instance will be sent with the following payload:
{ "text": "message content", "notification": "notification for this message", "user": "Boss", "attachments": [ { "text": "attachment content", "title": "attachment title", "images": [ { "url": "http://path/to/image" } ], "color": "#FF0000" } ] }
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Security
If you discover any security related issues, please email elf.sundae@gmail.com instead of using the issue tracker.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.