---
repo: "mohan-n-swamy/freshchat-bot-public"
title: "Omnichannel & WhatsApp AI Customer Support Bot"
license: "MIT"
keywords: [whatsapp-bot, customer-support, ai-chatbot, webhook, redis, llm-agents, typescript, conversational-ai, eval-harness, helpdesk]
capabilities:
  - "Multi-channel webhook adapters (`src/channels/adapters.py`) normalizing **Freshchat**, **Chatwoot**, and **WhatsApp Cloud API** events."
  - "HMAC SHA-256 webhook signature verification (`src/webhook/hmac_verify.py`) and Redis `SETNX` `conv_lock` burst deduplication."
  - "Zero-LLM-cost noise & echo filter (`src/domain/noise_filter.py`) dropping stray acknowledgments, CSAT ratings, and bot echoes."
  - "Five deterministic policy guards (`src/domain/guards/`): `NEVER_INTERRUPT_HUMAN`, `AUTH_GATE`, `PARTNER_ORDER`, `REPORT_SUPPRESSION`, and `READ_ONLY`."
  - "Pluggable async `CRMClient`, `OMSClient`, and `CatalogClient` (`src/domain/enrichment/`) plus voice-note STT support (`src/domain/media/`)."
  - "Zero-credential CLI simulation (`bin/bot-demo.py`), golden-set eval harness (`bin/eval-harness.py`), and 161 passing pytest cases."
when_to_use:
  - "A production-hardened FastAPI omnichannel customer support bot for Freshchat, self-hosted Chatwoot, and WhatsApp Cloud API featuring HMAC-verified webhooks, atomic Redis `SETNX` conversation locks, zero-cost noise filtering, caller-phone PII authentication gates, pluggable CRM/Order/Catalog adapters, and 161 automated tests."
  - "Tutorial chatbots wire an LLM directly to a webhook and fail on day one of production traffic: webhook retries trigger triple replies, stray 'Thank you!' messages burn tokens and reopen resolved tickets, bots talk over live human agents, and unverified order lookups leak customer PII. `freshchat-bot-public` packages the complete 7-layer deterministic-first pipeline used in high-volume omnichannel support."
inputs_required:
  - "CHANNEL_PROVIDER: Active helpdesk channel (`chatwoot`, `freshchat`, or `whatsapp_cloud`)"
  - "WEBHOOK_HMAC_SECRET: Shared HMAC secret for inbound webhook verification"
  - "CHATWOOT_BASE_URL: Base URL of your Chatwoot instance (`chatwoot-public` compatible)"
  - "REDIS_URL: Redis connection URL for `conv_lock` deduplication and catalog cache"
  - "CRM_API_BASE: Your customer CRM lookup endpoint"
  - "OMS_API_BASE: Your Order Management System status endpoint"
  - "ANTHROPIC_API_KEY: API key for structured LLM comprehension & reply synthesis"
quickstart:
  - "python3 bin/bot-demo.py                 # run 3-channel offline routing & dedup simulation"
  - "python3 bin/eval-harness.py             # run golden-set policy evaluation"
  - "pytest -q tests/                        # run all 161 unit & integration tests"
  - "uvicorn src.webhook.app:app --port 8000 # start FastAPI webhook server"
---

# Omnichannel & WhatsApp AI Customer Support Bot — Machine-Readable Agent Guide

A production-hardened FastAPI omnichannel customer support bot for Freshchat, self-hosted Chatwoot, and WhatsApp Cloud API featuring HMAC-verified webhooks, atomic Redis `SETNX` conversation locks, zero-cost noise filtering, caller-phone PII authentication gates, pluggable CRM/Order/Catalog adapters, and 161 automated tests.

<problem_patterns>
Tutorial chatbots wire an LLM directly to a webhook and fail on day one of production traffic: webhook retries trigger triple replies, stray 'Thank you!' messages burn tokens and reopen resolved tickets, bots talk over live human agents, and unverified order lookups leak customer PII. `freshchat-bot-public` packages the complete 7-layer deterministic-first pipeline used in high-volume omnichannel support.
</problem_patterns>

<architecture_map>
Key modules and entry points in this repository:
  - `src/webhook/app.py & handler.py`: FastAPI application, health probe, HMAC verification, and background task dispatch
  - `src/channels/adapters.py`: Webhook normalizers for Freshchat, Chatwoot, WhatsApp Cloud API, and `InMemoryDemoAdapter`
  - `src/domain/pipeline.py`: 7-layer orchestrator with emergency fallback handoff guarantee
  - `src/domain/guards/`: Deterministic `auth_gate`, `partner_order`, `report_suppress`, and human-assignment guards
  - `src/domain/enrichment/`: `CRMClient`, `OMSClient`, `CatalogClient`, and local `KnowledgeBase`
  - `src/domain/llm/`: Prompt builder, provider chain, and post-LLM output validator
  - `bin/bot-demo.py & bin/eval-harness.py`: Zero-credential local simulation and golden-set regression runner
  - `tests/`: 161-test suite covering guards, HMAC, phone normalization, escalation routing, and pipeline recovery
</architecture_map>

<inputs_and_configuration>
Every organization-specific value enters through `.env` (copied from `.env.example`) or external adapter files. No source edit is needed to change organization names, endpoints, database URLs, webhook secrets, or thresholds.
</inputs_and_configuration>

<adaptation_playbook>
When a human asks an AI coding agent to deploy or adapt `freshchat-bot-public` into their stack:
  1. Run `python3 bin/bot-demo.py` and `pytest -q tests/` locally to verify the pipeline without external keys.
  2. Edit `src/domain/enrichment/oms_client.py` and `catalog_client.py` (or point `OMS_API_BASE` / `CATALOG_API_BASE` in `.env`) to map your order status codes and SKU catalog.
  3. Adjust your intent taxonomy in `src/domain/intents/taxonomy.py` and team escalation map in `src/domain/escalation/routing.py`.
  4. Add 20-50 representative transcripts from your domain to `data/golden_eval_cases.json` and gate CI with `python3 bin/eval-harness.py`.
</adaptation_playbook>

<reference_docs>
- Product Requirements: `docs/PRD.md`
- Working-Backwards PR-FAQ: `docs/PR-FAQ.md`
- High-Level Architecture: `docs/HLD.md`
- Low-Level Interfaces & Runbook: `docs/LLD.md`
- Coding Agent Rules: `AGENTS.md`
</reference_docs>
