1. Go to this page and download the library: Download rulecom/notifier library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rulecom / notifier example snippets
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());
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!');
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' => '[email protected]'
])
->to([
'name' => 'Jane Doe',
'email' => '[email protected]'
])
->content([
'html' => '<h1>Notification sent via Rule!</h1>',
'html' => 'Notification sent via Rule!'
]);
}
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!');
}