All Projects → nikolaposa → notifier

nikolaposa / notifier

Licence: MIT license
📟 Extensible library for building notifications and sending them via different delivery channels

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to notifier

Django Notifs
Modular Notifications (InApp, Email, SMS, CustomBackend etc) for Django
Stars: ✭ 105 (+337.5%)
Mutual labels:  notifications, sms
Potato Library
Easy to use Utility library for Android
Stars: ✭ 45 (+87.5%)
Mutual labels:  notifications, sms
slack-texts
SMS notifications for Slack groups
Stars: ✭ 19 (-20.83%)
Mutual labels:  notifications, sms
Django Herald
A Django messaging library
Stars: ✭ 159 (+562.5%)
Mutual labels:  notifications, sms
mainsms api
Official MainSMS client
Stars: ✭ 25 (+4.17%)
Mutual labels:  sms
sms-bot
an SMS bot built with Google sheets and Twilio
Stars: ✭ 61 (+154.17%)
Mutual labels:  sms
dayu rs
Alibaba's Dayu SMS SDK for Rust.
Stars: ✭ 17 (-29.17%)
Mutual labels:  sms
cmd-sms
Yeni nesil sms guard bot
Stars: ✭ 2 (-91.67%)
Mutual labels:  sms
botkit-sms
Twilio Programmable SMS implementation for Botkit.
Stars: ✭ 18 (-25%)
Mutual labels:  sms
notify
Send emails and text messages to your users if you work in Australian government
Stars: ✭ 15 (-37.5%)
Mutual labels:  sms
ucp-cli
command-line interface for sending and receiving SMS via UCP protocol
Stars: ✭ 15 (-37.5%)
Mutual labels:  sms
smscenter
Класс для работы с сервисом smsc.ru (SMS-Центр)
Stars: ✭ 42 (+75%)
Mutual labels:  sms
usim800
usim800 is a Python driver module for SIM800 GSM/GPRS .
Stars: ✭ 36 (+50%)
Mutual labels:  sms
ChristmasSpiritBreaker-andNewYearsToo
Python script which automatically sends Christmas/New Year's messages from a custom messages list on Whatsapp, Facebook Messenger or via SMS in a given time range, to a custom contacts list. Time to work smart, not hard.
Stars: ✭ 81 (+237.5%)
Mutual labels:  sms
Offline-Browser-Android-App
SMS Based Browser for Android Devices for Retrieving Web Contents without WiFi/Internet.
Stars: ✭ 20 (-16.67%)
Mutual labels:  sms
sms-spring-boot-project
短信服务Spring Boot Starter ,目前支持腾讯、阿里、赛邮和云之讯短信服务,腾讯、阿里、赛邮和云之讯短信均已验证,期待各位小伙伴合作完善这个项目
Stars: ✭ 79 (+229.17%)
Mutual labels:  sms
notifire
The open-source notification infrastructure for developers
Stars: ✭ 12,436 (+51716.67%)
Mutual labels:  sms
text-sdk-php
PHP SDK to send messages with CM.com
Stars: ✭ 18 (-25%)
Mutual labels:  sms
laravel-sms
Laravel 贴合实际需求同时满足多种通道的短信发送组件
Stars: ✭ 67 (+179.17%)
Mutual labels:  sms
sms bomber
sms bomber.
Stars: ✭ 49 (+104.17%)
Mutual labels:  sms

Notifier

Build Status Code Quality Code Coverage Latest Version PDS Skeleton

Extensible library for building notifications and sending them via different delivery channels.

Installation

The preferred method of installation is via Composer. Run the following command to install the latest version of a package and add it to your project's composer.json:

composer require nikolaposa/notifier

Theory of operation

Notifications are informative messages that are sent through different channels (i.e. email, SMS, mobile push) to notify users about certain events in the application. Notification is a higher-level abstraction, a concept that encapsulates a subject to be notified to the recipient, regardless of delivery channels through which that information can be communicated. From an architectural standpoint, notification is a domain concern.

In order to minimize the coupling of your domain with the infrastructure for sending notifications, Notifier library was based on on unobtrusive interfaces that should be implemented by your objects in order to plug them into the workflow of the library. Those are:

  1. Notification - marks the object as a notification that can be used with the Notifier library,
  2. Recipient - represents the recipient of the notification which provides contact (i.e. email address, phone number) for a certain channel; typically implemented by a User domain object.

For each channel through which Notification is supposed to be sent, Notification class should implement channel-specific interface, making the Notification suitable for sending via a specific channel. These interfaces declare message building methods, for example EmailNotification::toEmailMessage(), that convert the notification to a message sent by that particular channel. Channel-specific Notification interfaces extend the Notification interface itself, so you do not need to implement it explicitly.

Channel component captures implementation details of how a Notification is sent via certain delivery channels. Specific channel implementation typically consists of:

  1. channel-specific Notification interface,
  2. Message class - transport-level message to which Notification gets converted,
  3. Channel implementation responsible for the very act of sending the Notification.

Out of the box, this library features facilities for sending notifications via email and SMS. The highly extensible design allows for implementing custom delivery channels.

Finally, Notifier service is a facade that manages the entire process of sending a Notification to a list of Recipients via supported channels. It is the only service of this library that the calling code is supposed to interact with directly.

Usage

Creating Notifications

namespace App\Model;

use Notifier\Channel\Email\EmailMessage;
use Notifier\Channel\Sms\SmsMessage;
use Notifier\Channel\Email\EmailNotification;
use Notifier\Channel\Sms\SmsNotification;
use Notifier\Recipient\Recipient;

class TodoExpiredNotification implements EmailNotification, SmsNotification
{
    /** @var Todo */
    protected $todo;

    public function __construct(Todo $todo)
    {
        $this->todo = $todo;
    }

    public function toEmailMessage(Recipient $recipient): EmailMessage
    {
        return (new EmailMessage())
            ->from('[email protected]')
            ->subject('Todo expired')
            ->htmlBody(
                'Dear ' . $recipient->getRecipientName() . ','
                . '<br><br>'
                . 'Your todo: <b>' . $this->todo->getText() . '</b> has expired.'
            );
    }

    public function toSmsMessage(Recipient $recipient): SmsMessage
    {
        return (new SmsMessage())
            ->text('Todo: ' . $this->todo->getText() . ' has expired');
    }
}

Implementing Recipient

namespace App\Model;

use Notifier\Recipient\Recipient;

class User implements Recipient
{
    /** @var string */
    protected $name;

    /** @var array */
    protected $contacts;

    public function __construct(string $name, array $contacts)
    {
        $this->name = $name;
        $this->contacts = $contacts;
    }
    
    public function getName(): string
    {
        return $this->name;
    }

    public function getRecipientContact(string $channel, Notification $notification): ?string
    {
        return $this->contacts[$channel] ?? null;
    }
    
    public function getRecipientName(): string
    {
        return $this->name;
    }
}

Sending Notifications

use Notifier\Channel\Channels;
use Notifier\Channel\Email\EmailChannel;
use Notifier\Channel\Email\SimpleMailer;
use Notifier\Channel\Sms\SmsChannel;
use Notifier\Channel\Sms\TwilioTexter;
use Notifier\Notifier;
use Notifier\Recipient\Recipients;

$notifier = new Notifier(new Channels(
    new EmailChannel(new SimpleMailer()),
    new SmsChannel(new TwilioTexter('auth_id', 'auth_token'))
));

$notifier->send(
    new TodoExpiredNotification($todo), 
    new Recipients($user1, $user2, $user3)
);

Credits

License

Released under MIT License - see the License File for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].