Building a Rules Engine for WhatsApp Automation: Keywords, Working Hours, Priorities and Loops
说明与用途
为 WhatsApp 构建了一个轻量级规则引擎,解决了关键字误匹配、时区错误、重复回复和属性更新循环等问题,并通过单元测试验证正确性。
问题
Keyword matching, time zone handling, duplicate replies, and infinite loops caused bugs in a WhatsApp automation rules engine.
结果
The refined engine eliminates keyword false positives, respects shop local hours, avoids duplicate replies, and prevents infinite attribute loops, with tests ensuring reliability.
工作流
- 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
证据
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.
- 记录日期: 2026-11-02T00:13:59.523Z