PHPackages                             winter/wn-notify-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. winter/wn-notify-plugin

ActiveWinter-plugin[Utility &amp; Helpers](/categories/utility)

winter/wn-notify-plugin
=======================

Notify plugin for Winter CMS

v2.1.0(10mo ago)33.4k↑150%41MITPHPPHP &gt;=7.2

Since Mar 20Pushed 9mo ago4 watchersCompare

[ Source](https://github.com/wintercms/wn-notify-plugin)[ Packagist](https://packagist.org/packages/winter/wn-notify-plugin)[ Docs](https://github.com/wintercms/wn-pages-plugin)[ GitHub Sponsors](https://github.com/wintercms)[ Fund](https://opencollective.com/wintercms)[ RSS](/packages/winter-wn-notify-plugin/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (1)

Notification Engine Plugin
==========================

[](#notification-engine-plugin)

[![MIT License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/wintercms/wn-notify-plugin/blob/main/LICENSE)

> **NOTE:** Plugin is currently in Beta status. Proceed with caution.

Adds support for sending notifications across a variety of different channels, including mail, SMS and Slack.

Notifications are managed in the backend area by navigating to *Settings &gt; Notification rules*.

Installation
------------

[](#installation)

This plugin is available for installation via [Composer](http://getcomposer.org/).

```
composer require winter/wn-notify-plugin
```

After installing the plugin you will need to run the migrations and (if you are using a [public folder](https://wintercms.com/docs/develop/docs/setup/configuration#using-a-public-folder)) [republish your public directory](https://wintercms.com/docs/develop/docs/console/setup-maintenance#mirror-public-files).

```
php artisan migrate
```

Notification workflow
---------------------

[](#notification-workflow)

When a notification fires, it uses the following workflow:

1. Plugin registers associated actions, conditions and events using `registerNotificationRules`
2. A notification class is bound to a system event using `Notifier::bindEvent`
3. A system event is fired `Event::fire`
4. The parameters of the event are captured, along with any global context parameters
5. A command is pushed on the queue to process the notification `Queue::push`
6. The command finds all notification rules using the notification class and triggers them
7. The notification conditions are checked and only proceed if met
8. The notification actions are triggered

Here is an example of a plugin registering notification rules. The `groups` definition will create containers that are used to better organise events. The `presets` definition specifies notification rules defined by the system.

```
public function registerNotificationRules()
{
    return [
        'events' => [
            \Winter\User\NotifyRules\UserActivatedEvent::class,
        ],
        'actions' => [
            \Winter\User\NotifyRules\SaveToDatabaseAction::class,
        ],
        'conditions' => [
            \Winter\User\NotifyRules\UserAttributeCondition::class
        ],
        'groups' => [
            'user' => [
                'label' => 'User',
                'icon' => 'icon-user'
            ],
        ],
        'presets' => '$/winter/user/config/notify_presets.yaml',
    ];
}
```

Here is an example of triggering a notification. The system event `winter.user.activate` is bound to the `UserActivatedEvent` class.

```
// Bind to a system event
\Winter\Notify\Classes\Notifier::bindEvents([
    'winter.user.activate' => \Winter\User\NotifyRules\UserActivatedEvent::class
]);

// Fire the system event
Event::fire('winter.user.activate', [$this]);
```

Here is an example of registering context parameters, which are available globally to all notifications.

```
\Winter\Notify\Classes\Notifier::instance()->registerCallback(function($manager) {
    $manager->registerGlobalParams([
        'user' => Auth::getUser()
    ]);
});
```

Here is an example of an event preset:

```
# ===================================
#  Event Presets
# ===================================

welcome_email:
    name: Send welcome email to user
    event: Winter\User\NotifyRules\UserRegisteredEvent
    items:
        - action: Winter\Notify\NotifyRules\SendMailTemplateAction
          mail_template: winter.user::mail.welcome
          send_to_mode: user
    conditions:
        - condition: Winter\Notify\NotifyRules\ExecutionContextCondition
          subcondition: environment
          operator: is
          value: dev
          condition_text: Application environment is dev
```

Creating Event classes
----------------------

[](#creating-event-classes)

An event class is responsible for preparing the parameters passed to the conditions and actions. The static method `makeParamsFromEvent` will take the arguments provided by the system event and convert them in to parameters.

```
class UserActivatedEvent extends \Winter\Notify\Classes\EventBase
{
    /**
     * @var array Local conditions supported by this event.
        */
    public $conditions = [
        \Winter\User\NotifyRules\UserAttributeCondition::class
    ];

    /**
     * Returns information about this event, including name and description.
     */
    public function eventDetails()
    {
        return [
            'name'        => 'Activated',
            'description' => 'A user is activated',
            'group'       => 'user'
        ];
    }

    /**
     * Defines the usable parameters provided by this class.
     */
    public function defineParams()
    {
        return [
            'name' => [
                'title' => 'Name',
                'label' => 'Name of the user',
            ],
            // ...
        ];
    }

    public static function makeParamsFromEvent(array $args, $eventName = null)
    {
        return [
            'user' => array_get($args, 0)
        ];
    }
}
```

Creating Action classes
-----------------------

[](#creating-action-classes)

Action classes define the final step in a notification and subsequently perform the notification itself. Some examples might be sending and email or writing to the database.

```
class SendMailTemplateAction extends \Winter\Notify\Classes\ActionBase
{
    /**
     * Returns information about this event, including name and description.
     */
    public function actionDetails()
    {
        return [
            'name'        => 'Compose a mail message',
            'description' => 'Send a message to a recipient',
            'icon'        => 'icon-envelope'
        ];
    }

    /**
     * Field configuration for the action.
     */
    public function defineFormFields()
    {
        return 'fields.yaml';
    }

    public function getText()
    {
        $template = $this->host->template_name;

        return 'Send a message using '.$template;
    }

    /**
     * Triggers this action.
     * @param array $params
        * @return void
        */
    public function triggerAction($params)
    {
        $email = 'test@email.tld';
        $template = $this->host->template_name;

        Mail::sendTo($email, $template, $params);
    }
}
```

A form fields definition file is used to provide form fields when the action is established. These values are accessed from condition using the host model via the `$this->host` property.

```
# ===================================
#  Field Definitions
# ===================================

fields:

    template_name:
        label: Template name
        type: text
```

An action may choose to provide no form fields by simply returning false from the `defineFormFields` method.

```
public function defineFormFields()
{
    return false;
}
```

Creating Condition classes
--------------------------

[](#creating-condition-classes)

A condition class should specify how it should appear in the user interface, providing a name, title and summary text. It also must declare an `isTrue` method for evaluating whether the condition is true or not.

```
class MyCondition extends \Winter\Notify\Classes\ConditionBase
{
    /**
     * Return either ConditionBase::TYPE_ANY or ConditionBase::TYPE_LOCAL
     */
    public function getConditionType()
    {
        // If the condition should appear for all events
        return ConditionBase::TYPE_ANY;

        // If the condition should appear only for some events
        return ConditionBase::TYPE_LOCAL;
    }

    /**
     * Field configuration for the condition.
     */
    public function defineFormFields()
    {
        return 'fields.yaml';
    }

    public function getName()
    {
        return 'My condition is checked';
    }

    public function getTitle()
    {
        return 'My condition';
    }

    public function getText()
    {
        $value = $this->host->mycondition;

        return 'My condition is '.$value;
    }

    /**
     * Checks whether the condition is TRUE for specified parameters
     * @param array $params
        * @return bool
        */
    public function isTrue(&$params)
    {
        return true;
    }
}
```

A form fields definition file is used to provide form fields when the condition is established. These values are accessed from condition using the host model via the `$this->host` property.

```
# ===================================
#  Field Definitions
# ===================================

fields:

    mycondition:
        label: My condition
        type: dropdown
        options:
            true: True
            false: False
```

Model attribute condition classes
---------------------------------

[](#model-attribute-condition-classes)

Model attribute conditions are designed specially for applying conditions to sets of model attributes.

```
class UserAttributeCondition extends \Winter\Notify\Classes\ModelAttributesConditionBase
{
    protected $modelClass = \Winter\User\Models\User::class;

    public function getGroupingTitle()
    {
        return 'User attribute';
    }

    public function getTitle()
    {
        return 'User attribute';
    }

    /**
     * Checks whether the condition is TRUE for specified parameters
     * @param array $params Specifies a list of parameters as an associative array.
        * @return bool
        */
    public function isTrue(&$params)
    {
        $hostObj = $this->host;

        $attribute = $hostObj->subcondition;

        if (!$user = array_get($params, 'user')) {
            throw new ApplicationException('Error evaluating the user attribute condition: the user object is not found in the condition parameters.');
        }

        return parent::evalIsTrue($user);
    }
}
```

An attributes definition file is used to specify which attributes should be included in the condition.

```
# ===================================
#  Condition Attribute Definitions
# ===================================

attributes:

    name:
        label: Name

    email:
        label: Email address

    country:
        label: Country
        type: relation
        relation:
            model: Winter\Location\Models\Country
            label: Name
            nameFrom: name
            keyFrom: id
```

Save to database action
-----------------------

[](#save-to-database-action)

There is a dedicated table in the database for storing events and their parameters. This table is accessed using the `Winter\Notify\Models\Notification` model and can be referenced as a relation from your own models. In this example the `MyProject` model contains its own notification channel called `notifications`.

```
class MyProject extends Model
{
    // ...

    public $morphMany = [
        'my_notifications' => [
            \Winter\Notify\Models\Notification::class,
            'name' => 'notifiable'
        ]
    ];
}
```

This channel should be registered with the `Winter\Notify\NotifyRules\SaveDatabaseAction` so it appears as a related object when selecting the action.

```
SaveDatabaseAction::extend(function ($action) {
    $action->addTableDefinition([
        'label'    => 'Project activity',
        'class'    => MyProject::class,
        'relation' => 'my_notifications',
        'param'    => 'project'
    ]);
});
```

The **label** is shown as the related object, the **class** references the model class, the **relation** refers to the relation name. The **param** defines the parameter name, passed to the triggering event.

So essentially if you pass a `project` to the event parameters, or if `project` is a global parameter, a notification model is created with the parameters stored in the `data` attribute. Equivalent to the following code:

```
$myproject->my_notifications()->create([
    // ...
    'data' => $params
]);
```

Dynamically adding conditions to events
---------------------------------------

[](#dynamically-adding-conditions-to-events)

Events can be extended to include new local conditions. Simply add the condition class to the event `$conditions` array property.

```
UserActivatedEvent::extend(function($event) {
    $event->conditions[] = \Winter\UserPlus\NotifyRules\UserLocationAttributeCondition::class;
});
```

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance55

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~647 days

Total

4

Last Release

306d ago

Major Versions

v1.0.3 → v2.0.02021-04-22

PHP version history (2 changes)v1.0.3PHP &gt;=5.5.9

v2.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7253840?v=4)[Luke Towers](/maintainers/LukeTowers)[@LukeTowers](https://github.com/LukeTowers)

---

Top Contributors

[![mjauvin](https://avatars.githubusercontent.com/u/2013630?v=4)](https://github.com/mjauvin "mjauvin (24 commits)")[![daftspunk](https://avatars.githubusercontent.com/u/1392869?v=4)](https://github.com/daftspunk "daftspunk (16 commits)")[![LukeTowers](https://avatars.githubusercontent.com/u/7253840?v=4)](https://github.com/LukeTowers "LukeTowers (11 commits)")[![bennothommo](https://avatars.githubusercontent.com/u/15900351?v=4)](https://github.com/bennothommo "bennothommo (3 commits)")[![RomainMazB](https://avatars.githubusercontent.com/u/53976837?v=4)](https://github.com/RomainMazB "RomainMazB (2 commits)")[![webmaxx](https://avatars.githubusercontent.com/u/590390?v=4)](https://github.com/webmaxx "webmaxx (2 commits)")[![BlazOrazem](https://avatars.githubusercontent.com/u/5699173?v=4)](https://github.com/BlazOrazem "BlazOrazem (1 commits)")[![petehalverson](https://avatars.githubusercontent.com/u/911099?v=4)](https://github.com/petehalverson "petehalverson (1 commits)")[![LeoCantThinkOfAName](https://avatars.githubusercontent.com/u/21163791?v=4)](https://github.com/LeoCantThinkOfAName "LeoCantThinkOfAName (1 commits)")[![sikhub](https://avatars.githubusercontent.com/u/4103737?v=4)](https://github.com/sikhub "sikhub (1 commits)")[![prhost](https://avatars.githubusercontent.com/u/3984760?v=4)](https://github.com/prhost "prhost (1 commits)")[![mahony0](https://avatars.githubusercontent.com/u/2674488?v=4)](https://github.com/mahony0 "mahony0 (1 commits)")

---

Tags

hacktoberfestcmspageswintercms

### Embed Badge

![Health badge](/badges/winter-wn-notify-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/winter-wn-notify-plugin/health.svg)](https://phpackages.com/packages/winter-wn-notify-plugin)
```

###  Alternatives

[winter/wn-seo-plugin

Winter CMS plugin for managing SEO tags

106.3k](/packages/winter-wn-seo-plugin)[winter/wn-tailwindui-plugin

Provides a TailwindUI-based skin for the Winter CMS backend.

1812.8k](/packages/winter-wn-tailwindui-plugin)[professional-wiki/network

MediaWiki extension for adding interactive network visualizations to your wiki pages

3211.9k](/packages/professional-wiki-network)[winter/wn-sitemap-plugin

Sitemap plugin for Winter CMS

1042.6k1](/packages/winter-wn-sitemap-plugin)[responsiv/currency-plugin

Currency plugin for October CMS

171.3k1](/packages/responsiv-currency-plugin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
