Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

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".

Source

A working-hours check runs in the server's time zone instead of the shop's.

Source

Three rules all reply to the same message.

Source

A redelivered webhook sends the welcome message twice.

Source

Two rules that update each other's attributes loop forever.

Source

  • Record date: 2026-11-02T00:13:59.523Z