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