Building a Rules Engine for WhatsApp Automation: Keywords, Working Hours, Priorities and Loops
Description and use
A lightweight rules engine for WhatsApp was built to fix keyword false positives, respect shop local hours, avoid duplicate replies, and prevent infinite attribute loops, with unit tests ensuring correctness.
Problem
Keyword matching, time zone handling, duplicate replies, and infinite loops caused bugs in a WhatsApp automation rules engine.
Outcome
The refined engine eliminates keyword false positives, respects shop local hours, avoids duplicate replies, and prevents infinite attribute loops, with tests ensuring reliability.
Workflow
- Define rule structure: trigger, filter (AND/OR groups), action
- Implement keyword filter using whole‑word regex to avoid false positives
- Implement working‑hours filter using Intl.DateTimeFormat with shop time zone
- Add duplicate webhook detection to avoid double replies
- Add loop detection for attribute updates
- Write unit tests for each bug scenario
Evidence
Keyword matching catches "priceless" when you meant "price".
A working-hours check runs in the server's time zone instead of the shop's.
Three rules all reply to the same message.
A redelivered webhook sends the welcome message twice.
Two rules that update each other's attributes loop forever.
- Record date: 2026-11-02T00:13:59.523Z