The problem
A chat bot on a business number can do real damage: reply twice to one message, keep messaging someone who opted out, run up an LLM bill overnight, or argue with a person who asked for a human.
I built the pipeline so each of those has a named stage that runs before any model call.
Constraints
- WhatsApp may deliver the same message more than once.
- Opt-out must win over everything else.
- Model spend has a hard daily ceiling.
- The bot never quotes a firm price.
Architecture
Deduplication is a database constraint on processed message ids, so a redelivered webhook is a no-op rather than a second reply.
What shipped
- Fastify webhook, Postgres-backed queue and a separate worker process.
- Consent, cost cap, rate limit, handoff and a three-question qualifying state machine.
- Grounded follow-up answers from an inlined knowledge base; a deploy runbook.
Evidence and receipts
Owned
Private repository: src/webhook, src/pipeline, src/queue and 15 test files.
What I would do differently
- Deploy behind a staging number first and record a week of real traffic before tuning prompts.
- Move CI to a self-hosted runner.
Honest limitations
01 Input
Next step
Bring an AI feature or workflow that has to keep working. We scope the first verifiable step on a 15-minute call, and I give an honest answer on fit either way.
Book a 15-minute call Not sure what you need? Answer 3 questions