Rules Engine Documentation
Create IF/THEN rules to automate responses, route conversations, and customize your chat behavior.
How Rules Work
Rules give you full control over what happens when a visitor sends a message. Each rule is evaluated on every incoming visitor message, before the AI auto-reply has a chance to respond.
- Each rule has conditions (IF) and actions (THEN).
- Match mode determines how conditions combine: ALL conditions must match (AND logic) or ANY condition can match (OR logic).
- Rules run in priority order — lower number means higher priority (runs first).
- Stop on match — when enabled, no further rules are checked after this rule fires.
- A rule can suppress AI auto-reply (e.g.,
REPLY_TEXThandles the response instead).
Conditions Reference
Conditions define when a rule should fire. You can combine multiple conditions using ALL (AND) or ANY (OR) match mode.
MESSAGE_CONTAINS
Checks if the visitor's message contains a specific word or phrase.
| Parameter | Description |
|---|---|
value | Text to search for in the message |
caseSensitive | true / false — whether matching is case-sensitive |
Example: "Message contains pricing" matches "What's your pricing?"
MESSAGE_MATCHES_REGEX
Matches the visitor's message against a regular expression.
| Parameter | Description |
|---|---|
pattern | Regex including delimiters, e.g. /order\s*#?\d+/i |
Example: /\b(refund|return|cancel)\b/i matches any refund-related message
Tip: Use regex101.com to test your patterns before adding them.
VISITOR_LANGUAGE
Checks the detected language of the visitor.
| Parameter | Description |
|---|---|
operator | equals, not_equals, or in |
value | Language code such as en, pl, de |
Example: Visitor language equals pl → route to Polish operator
OPERATOR_ONLINE
Checks whether any operator in your team is currently online.
| Parameter | Description |
|---|---|
value | true = at least one operator online, false = all operators offline |
Example: Operator online = false → send "We're currently offline" message
SESSION_VARIABLE
Checks a custom variable stored on the conversation (set by a previous rule).
| Parameter | Description |
|---|---|
key | Variable name to check |
operator | equals, not_equals, exists, or not_exists |
value | Expected value (not needed for exists / not_exists) |
Example: Session variable lead_type equals demo → assign to sales team
Actions Reference
Actions define what happens when a rule's conditions are met. A single rule can have multiple actions.
REPLY_TEXT
Sends an automated text reply to the visitor.
| Parameter | Description |
|---|---|
text | The message to send to the visitor |
Note: Suppresses AI auto-reply — the rule handles the response.
Example: "Our team is offline. We'll get back to you during business hours."
REPLY_AI
Explicitly tells the system to use AI auto-reply for this message.
Note: Use in combination with other actions — e.g., set a variable AND let AI respond.
SET_VARIABLE
Stores a key-value pair on the conversation for later use by other rules.
| Parameter | Description |
|---|---|
key | Variable name |
value | Variable value |
Note: Does NOT suppress AI — AI can still respond after the variable is set.
Example: Set interest = enterprise for follow-up
ASSIGN_TO_OPERATOR
Assigns the conversation to a specific operator from your team.
| Parameter | Description |
|---|---|
operatorId | Select from your team members |
Note: Implicitly suppresses AI — assigned conversations do not get AI replies.
Example: Route VIP customers to your senior support agent
NOTIFY_OPERATORS
Sends a real-time alert to all online operators with a sound notification.
| Parameter | Description |
|---|---|
message | Alert message shown to operators |
Note: Does NOT suppress AI — both the alert and AI response happen.
Example: "Urgent: visitor needs immediate help!"
SEND_EMAIL
Sends an email with conversation context. Useful for escalation or CRM integration.
| Parameter | Description |
|---|---|
to | Recipient email address |
subject | Email subject line |
body | Email body (optional — conversation context is appended automatically) |
Note: Does NOT suppress AI.
CALL_API
Calls an external API endpoint and stores the response in session variables. Requires an API Connection to be configured first.
| Parameter | Description |
|---|---|
endpointId | Select from your configured API endpoints |
Note: Does NOT suppress AI — combine with REPLY_AI so AI uses the fetched data. See API Connections docs for full setup guide.
Example: Call order tracking API → store status in session → AI responds with real order data
Practical Examples
Ready-to-use rule recipes you can adapt for your own setup.
1. Auto-answer pricing questions
Save AI tokens by answering common questions with a static reply.
IF (ANY match): MESSAGE_CONTAINS price, MESSAGE_CONTAINS cost, MESSAGE_CONTAINS pricing
THEN: REPLY_TEXT: "Our plans start at €19/month. See full pricing at enuchat.com/pricing"
Match mode: ANY · Stop on match: Yes
2. Route visitors by language
Send Polish visitors directly to your Polish-speaking operator.
IF (ALL match): VISITOR_LANGUAGE equals pl
THEN: ASSIGN_TO_OPERATOR → Polish Operator
Match mode: ALL · Stop on match: Yes
3. After-hours greeting
Set expectations when no one is online.
IF (ALL match): OPERATOR_ONLINE = false
THEN: REPLY_TEXT: "Thanks for reaching out! Our team is currently offline. AI will try to help, but we'll follow up during business hours."
Match mode: ALL · Stop on match: No (let AI respond too)
4. Tag and route demo requests
Two rules working together with session variables.
Rule 1 — IF (ALL match): MESSAGE_CONTAINS demo
Rule 1 — THEN: SET_VARIABLE lead_type = demo_request. Stop on match: No (AI responds to the first message)
Rule 2 — IF (ALL match): SESSION_VARIABLE lead_type equals demo_request
Rule 2 — THEN: ASSIGN_TO_OPERATOR → Sales. Stop on match: Yes
First message sets the tag and AI responds. The second message from the same visitor routes to sales.
5. Detect order numbers with regex
Route order-related queries to support automatically.
IF (ALL match): MESSAGE_MATCHES_REGEX /\b(order|tracking)\s*#?\s*\d{'{'}4,}/i
THEN: ASSIGN_TO_OPERATOR → Support Agent, REPLY_TEXT: "I see you have an order question. Let me connect you with our support team."
Match mode: ALL · Stop on match: Yes
6. Combine conditions (AND logic)
Only trigger for very specific scenarios where multiple conditions must all be true.
IF (ALL match): VISITOR_LANGUAGE equals en, MESSAGE_CONTAINS urgent
THEN: ASSIGN_TO_OPERATOR → Senior Agent
Match mode: ALL (both must match) · Stop on match: Yes
Tips & Best Practices
- Order matters: rules with lower priority numbers run first. Put your most important rules at the top.
- Use "Stop on match" to prevent multiple rules from firing on the same message.
- Test before going live using the Test panel in the dashboard.
- Keep REPLY_TEXT messages concise — visitors expect chat, not essays.
- Use SESSION_VARIABLE to build multi-step flows — tag a conversation on the first message, then act on it later.
- Regex tips: always use the case-insensitive flag
/iand test your patterns at regex101.com. - Less is more: 10–15 well-crafted rules are better than 50 overlapping ones.
- Rules run before AI — if a rule handles the message, AI won't respond (saving you tokens).
Ready to automate your chat?
Set up your first rule in minutes and let automation handle the repetitive work.
Get Started Free