2017 © Pedro Peláez
 

library notifier

Send notification via Rule and other providers

image

rulecom/notifier

Send notification via Rule and other providers

  • Friday, September 16, 2016
  • by rule
  • Repository
  • 3 Watchers
  • 0 Stars
  • 958 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 124 % Grown

The README.md

Rule notifier

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

Send notifications via Rule (email/text message) and Slack. Inspired by Laravels notification system and can be used with the Laravel framework or completely indipendent., (*2)

Install

Via Composer, (*3)

``` bash $ composer require rulecom/notifier, (*4)


## Usage To send notification you need to create notification objects. These objects are responsible for telling the Notifier via which channels the notification message should be sent through and what each corresponding channel message should contain. ```php use RuleCom\Notifier\Channels\Email; use RuleCom\Notifier\Channels\Slack; class UserHasRegistered { /** * Here we specify through which channels we want to * send our notification. */ public function via() { return ['email', 'slack']; } /** * Each via method needs a correspondng "to" method. */ public function toEmail() { // Specify what the email message should contain. } /** * Each via method needs a correspondng "to" method. */ public function toSlack() { // Specify what the Slack message should contain. } } // To send the notification to all specified channels: $notifier = new RuleCom\Notifier\Notifier(); $notifier->send(new UserHasRegistered());

Channels

Currently this package supports the following channel providers:, (*5)

  • Rule for sending email and text messages.
  • Slack for sending messages to Slack.

Email via (Rule):

``` php public function toEmail() { return (new RuleCom\Notifier\Channels\Email(new GuzzleHttp\Client())) ->apikey('YOUR-RULE-API-KEY') // If using Laravel you can set this in config/rule-notifier.php ->subject('Hello, world!') ->from([ 'name' => 'John Doe', 'email' => 'john@doe.com' ]) ->to([ 'name' => 'Jane Doe', 'email' => 'jane@doe.com' ]) ->content([ 'html' => ', (*6)

Notification sent via Rule!

', 'html' => 'Notification sent via Rule!' ]); }

#### Slack: ``` php public function toSlack() { return (new RuleCom\Notifier\Channels\Slack(new GuzzleHttp\Client())) ->endpoint('YOUR-SLACK-INCOMING-WEBHOOK') // If using Laravel you can set this in config/rule-notifier.php ->channel('#notification') // Here you can override the channel specified in Slack, or send DM by passing @username ->message('Hello, world!'); }

Usage with Laravel

This package can be easily integrated with laravel, with the following benefits., (*7)

  • No need to pass in channel dependecies on your own.
  • Ability to specify configurations such as, api key for Rule and webhook for Slack.
  1. In your config/app.php add the following service provider ``` php RuleCom\Notifier\LaravelServiceProvider::class

2. Publish the config: ``` bash php artisan vendor:publish

``` php // Without Laravel you will have to pass the channel dependency on your own: (new RuleCom\Notifier\Channels\Slack(new GuzzleHttp\Client())), (*8)

// With Laravel you can resolve the channels with dependencies through the ioc container: app(RuleCom\Notifier\Channels\Slack::class), (*9)


### Debugging If you need to debug a channel you may set it to debug mode. When a channel is in debug mode it will log the notification instead of dispatching the it to given channel. To enable debug: 1. Inject `Monolog\Logger` into the channel. 2. Call the `debug` method and pass in a path to your logfile. ```php return (new RuleCom\Notifier\Channels\Slack(new GuzzleHttp\Client(), new Monolog\Logger('Notification logger'))) ->debug('path/to/file.log') // If using Laravel you can set both debug mode and log path in config/rule-notifier.php ->endpoint('YOUR-SLACK-INCOMING-WEBHOOK') // If using Laravel you can set this in config/rule-notifier.php ->channel('#notification') // Here you can override the channel specified in Slack, or send DM by passing @username ->message('Hello, world!');

Change log

Please see CHANGELOG for more information what has changed recently., (*10)

Testing

bash $ composer test, (*11)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*12)

Security

If you discover any security related issues, please email matthis.stenius@rule.se instead of using the issue tracker., (*13)

Credits

License

The MIT License (MIT). Please see License File for more information., (*14)

The Versions

16/09 2016

dev-debug-mode

dev-debug-mode https://github.com/rulecom/notifier

Send notification via Rule and other providers

  Sources   Download

MIT

The Requires

 

The Development Requires

notifier rulecom

16/09 2016
16/09 2016
14/09 2016

1.1.0

1.1.0.0 https://github.com/rulecom/notifier

Send notification via Rule and other providers

  Sources   Download

MIT

The Requires

 

The Development Requires

notifier rulecom

06/09 2016

1.0.2

1.0.2.0 https://github.com/rulecom/notifier

Send notification via Rule and other providers

  Sources   Download

MIT

The Requires

 

The Development Requires

notifier rulecom

31/08 2016

1.0.1

1.0.1.0 https://github.com/rulecom/notifier

Send notification via Rule and other providers

  Sources   Download

MIT

The Requires

 

The Development Requires

notifier rulecom

31/08 2016

1.0.0

1.0.0.0 https://github.com/rulecom/notifier

Send notification via Rule and other providers

  Sources   Download

MIT

The Requires

 

The Development Requires

notifier rulecom