Create a Decision
In this tutorial, you will create a Decision in PubNub Illuminate, connect it to the "Game engagement experiment" Business Object, add two Send Message actions with variables, configure two rules with conditions, and activate the Decision.
What you will build
By the end of this tutorial, you will have an active Decision called "Send discount code". It evaluates the Message sum metric from the "Game engagement experiment" Business Object and publishes a discount message to a guild's channel whenever that guild sends 100 or more messages within 30 minutes.
The completed Decision will have:
- Two Send Message actions: one for Rockin Guild targeting channel
rockin, and one for Hurrah targeting channelhurrah - A shared message body that injects three variables:
${message},${discountCode}, and${purchasedItem} - Two rules, one per guild, each checking that Sum of Messages is at least
100, matching a specific guild name, and running only that guild's action - Hit policy set to
Multipleso both rules can fire in the same evaluation cycle - Evaluation frequency set to
30 minutes
Before you start
To follow this tutorial, confirm you have:
- The active "Game engagement experiment" Business Object from Create a Business Object, including the Message sum metric.
- Access to Illuminate in the Admin Portal.
For a full explanation of Decision structure, condition operators, action types, and rule configuration, see Decisions.
Create the Decision
- In the Admin Portal, go to Illuminate > Decisions.
- Click Create Decision. The Create new Decision modal opens.
- Enter
Send discount codein the Decision name field. Add an optional description. - Click Select Business Object and choose
Game engagement experimentfrom the list. - Select
an aggregation, then chooseMessage sumfrom the metric list.
After you select the metric, the Conditions section auto-populates from the metric's data fields: Sum of Messages and Guild Name. An empty Decision table preview appears with these as columns. Leave the modal open and add two actions before finalizing.
Action 1: Rockin Guild
- Click + Add action.
- Enter
Send discount code - Rockin Guildin the Name field. Add an optional description. - Click Configure.
- Select Send Message as the action type.
- Select the publish and subscribe keys for your keyset.
- Enter
rockinin the Channel ID field. - Enter
"${message}. Use ${discountCode} to buy ${purchasedItem}."in the Body field. - Click Save.
After saving, the variables ${message}, ${discountCode}, and ${purchasedItem} appear as new columns in the Decision table preview.
Each row in this table is one rule. The left-hand columns are conditions that determine when the rule fires. The right-hand columns show one column for each action and one for each variable.
Action 2: Hurrah
- Click + Add action.
- Enter
Send discount code - Hurrahin the Name field. Add an optional description. - Click Configure.
- Select Send Message as the action type.
- Select the publish and subscribe keys for your keyset.
- Enter
hurrahin the Channel ID field. - Enter
"${message}. Use ${discountCode} to buy ${purchasedItem}."in the Body field. - Click Save.
Both actions now appear in the modal. Click Create to finalize the Decision and open the rules view.
Configure rules
After creation, a link to configure rules appears. Click it, or open the Decision and click Edit Rules.
Each row you add is one rule. The table has two sections:
- Conditions (Sum of Messages, Guild Name) set when the rule fires.
- Actions has one column per action and one per variable. In each action column,
Yesmeans the rule runs that action when it fires, andNomeans it doesn't. The variable columns (message,discountCode,purchasedItem) set the values injected into the message body.
New rules run every action
A new rule has every action set to Yes. If you leave it that way, the Rockin Guild rule also publishes to channel hurrah, and the Hurrah rule also publishes to channel rockin. Set the other guild's action to No in each rule.
At the top of the rule editing view, set Hit Policy to Multiple and Evaluation frequency to 30 minutes. Hit policy Multiple means Illuminate fires all matching rules in one evaluation cycle, not only the first.
Rule 1: Rockin Guild
- Click + Add rule. A new row appears in the Decision table.
- In the Sum of Messages column, set the operator to
Greater than or equaland the value to100. - In the Guild Name column, enter
Rockin Guild. - In the Send discount code - Rockin Guild column, leave
Yes. - In the Send discount code - Hurrah column, select
No. - In the message column, enter
You really rock, Rockin Guild!. - In the discountCode column, enter
FORTFREE. - In the purchasedItem column, enter
Wood Fort.
This rule runs only Send discount code - Rockin Guild when Rockin Guild's message count reaches 100 in the evaluation window.
Rule 2: Hurrah
- Click + Add rule. A second row appears in the Decision table.
- In the Sum of Messages column, set the operator to
Greater than or equaland the value to100. - In the Guild Name column, enter
Hurrah. - In the Send discount code - Rockin Guild column, select
No. - In the Send discount code - Hurrah column, leave
Yes. - In the message column, enter
Hip, Hip, Hurrah!. - In the discountCode column, enter
FORTX. - In the purchasedItem column, enter
Metal Fort.
This rule runs only Send discount code - Hurrah when Hurrah's message count reaches 100 in the evaluation window.
Click Save to save both rules.
Activate
To activate the Decision, at least one rule and one action must be present and the Business Object must be active. All three conditions are met.
- Click Activate.
- Select Activate until manually deactivated.
Illuminate begins evaluating the Message sum metric every 30 minutes. When a guild's message count reaches 100 or more, the matching rule fires and Illuminate publishes the discount message to that guild's channel.
What you built
You created "Send discount code", a Decision connected to the "Game engagement experiment" Business Object. You added two Send Message actions: one targeting channel rockin for Rockin Guild and one targeting channel hurrah for Hurrah. Each action body uses three variables. You configured two rules, each running only its own guild's action: Rule 1 fires when Rockin Guild reaches 100 messages and sends a discount for a Wood Fort to channel rockin, Rule 2 fires when Hurrah reaches 100 messages and sends a discount for a Metal Fort to channel hurrah. You set hit policy to Multiple and evaluation frequency to 30 minutes, then activated the Decision. Illuminate now evaluates the metric every 30 minutes and fires the matching action when conditions are met. Add this Decision to a Dashboard to monitor triggered actions alongside the metric data.