Your first rule

This page is for version 1.0. Read the current version.

For arlanix/notification 1.0.1

Your first rule

Every notification needs three things. Each one answers a question:

Answers In this example
Topic What is it about? Orders
Subscription Who gets it, and how? The sales team, by email
Rule When is it sent? A new order of $100 or more

A rule sends a message to a topic. The topic passes the message to each of its subscriptions. For example, when a customer places an order of $117:

  1. The order starts the New order event.
  2. The rule Big orders to the sales team matches the event and sends a message to the topic Orders.
  3. The topic passes the message to its subscription Sales team.
  4. The module sends the message to the subscription's email address.

A topic can have any number of subscriptions, and each subscription has its own address and delivery method. Any number of rules can send to the same topic.

On this page, you make one topic, one subscription and one rule, and then see an order message arrive. It takes about ten minutes.

1. Make the topic

  1. Open Arlanix > Notifications > Topics.

    The Arlanix menu with Topics under Notifications

  2. Click Add topic.

    The Topics grid with the Add topic button

  3. In Name, enter Orders.

  4. In Description, describe what is sent to this topic. This helps people who subscribe later.

  5. Leave Delivers on.

    The topic form filled in: Orders, a description, Delivers on

  6. Click Save. The topic's page stays open, and now shows a Subscriptions section.

    The topic's page after the save: Topic "Orders" saved., and Subscriptions with Add subscription

2. Subscribe the sales team

  1. Under Subscriptions, click Add subscription. The subscription form opens in a panel. The topic is already filled in.

  2. In Name, enter who gets the messages: Sales team.

  3. Leave Gets on Everything.

  4. Under Delivery, leave Delivered by on Email.

  5. In Email, enter one email address, such as [email protected]. Use your own address for now.

    The panel filled in: Sales team, Orders, Everything, Email, sales@example.com

  6. Click Save in the panel. The panel closes, and the topic's page lists the subscription. Its Last delivery shows Nothing sent yet.

    The topic's page after the save: Subscription "Sales team" saved., and the subscription in the list

  7. In the subscription's row, click Select, then click Send test message.

    The Sales team row's Select open, with Send test message

    Above the list, the page shows Test message sent. Check that it arrived. The row's Last delivery shows that the message was sent.

    Above the list: Test message sent. Check that it arrived., and the Sales team row

  8. Check your inbox. The test email arrives. This means that messages sent to Orders reach this address.

    The test email: [INFO] Test notification from the store

3. Make the rule

  1. Open Arlanix > Notifications > Rules.

    The Arlanix menu with Rules under Notifications

  2. Click Add rule.

    The Rules grid with the Add rule button

  3. In Name, enter Big orders to the sales team. The Rules grid and the Message Log show this name.

  4. In Event, choose New order.

  5. In Topic, choose Orders. This is where the message goes.

    The rule form: Big orders to the sales team, the event New order, the topic Orders

  6. Under Conditions, click Add condition and choose Grand total, equals or greater than, 100. Without a condition, the rule sends a message for every order.

    The condition: Grand total equals or greater than 100

  7. Under Message, in Subject, enter Big order #{order.increment_id}: {order.grand_total_formatted}. The names in braces are the order's fields. The module replaces them with the order's values. If you leave Subject empty, the module uses the event's own subject.

  8. Click the arrow beside Save, then click Save & Close. The Rules grid lists the rule.

    The Rules grid after the save: Rule "Big orders to the sales team" saved.

4. Check that it works

  1. Place an order of $100 or more in the store. The email usually arrives within a minute.

    The email the rule sent for an order of $117

    To test the rule without placing an order, open the rule and click Publish test message. The module sends the message to Orders with sample values, and marks it [Test].

  2. Open the Message Log. It lists the message, the rule that sent it and who got it.

    The Message Log: a Big order message, with the rule that sent it

What to do next

You can now:

  • Subscribe more people to Orders. Each person can get messages in a different way: an email address, a Telegram chat, or a Slack or Discord channel. A subscription that should only get problems can take only warnings and errors. See Subscriptions.
  • Add rules for other events, to this topic or to a new one. For example, get a message about the store's health. See Rules.
  • Get a message when a product feed fails or delivers again. Arlanix Product Feed adds its own events. Get told when a feed fails has rules that you can copy.