Conditions
Understanding how channel conditions work in Echobell
Channel Conditions
Channel conditions are powerful expressions that determine when notifications should be sent. By setting conditions on your channel, you can filter notifications based on the content of variables or HTTP headers, ensuring subscribers only receive relevant alerts.
Understanding Conditions
Conditions are expressions that evaluate to either true
or false
. When a channel is triggered:
- If conditions are not set (empty), notifications are sent to all subscribers.
- If conditions are set, notifications are only sent when the expression evaluates to
true
.
Writing Conditions
Conditions are written as expressions without the {{}}
wrappers that are used in templates. For example:
This condition will only allow notifications to be sent when the status
variable equals "active".
Common Use Cases
Here are some practical examples of how you might use conditions:
Basic Variable Checks
Only notify when the "amount" variable is greater than 100.
Only notify when the "message" variable is not empty.
Only notify when the "isUrgent" variable is true.
Checking HTTP Headers
You can access HTTP headers using the special header
variable:
Only notify when the request comes from a Mozilla browser.
Only notify when the content type is JSON.
Only notify when a custom priority header is set to "high".
Complex Conditions
You can combine multiple conditions using logical operators:
Only notify when either temperature exceeds 30 or pressure exceeds 100, and the status is "monitoring".
Only notify for critical or high-level errors in the production environment.
Supported Operators
The following operators are supported in condition expressions:
| Operator | Description | Example |
| -------- | ------------------------ | ---------------------- | ---------- | -------- | --- | ---------- |
| ==
| Equal to | status == "active"
|
| !=
| Not equal to | status != "inactive"
|
| !
| Logical NOT | !isCompleted
|
| <
| Less than | count < 10
|
| >
| Greater than | price > 99.99
|
| <=
| Less than or equal to | battery <= 20
|
| >=
| Greater than or equal to | confidence >= 0.95
|
| &&
| Logical AND | isAdmin && isActive
|
| | |
| Logical OR | isError | | isWarning
|
Condition Variables
When a channel is triggered via webhook, you can access:
- Query parameters from the URL
- JSON body from POST requests
- HTTP headers via the
header
object
For email triggers, you can access:
from
: The email sender addressto
: The recipient addresssubject
: The email subject linetext
: The plain text body contenthtml
: The HTML body content
Best Practices
- Start simple - Begin with basic conditions and add complexity as needed
- Test thoroughly - Test your conditions with various inputs to ensure they work as expected
- Document your conditions - Add comments in your channel's note field to explain complex conditions
- Consider edge cases - Account for missing variables or unexpected values
Examples
Alert only for specific errors
Notify only during business hours
Filter by user type
Check request origin
Monitor threshold violations
By using conditions effectively, you can reduce notification noise and ensure that subscribers only receive alerts that are relevant and actionable for them.