📄
Part 1 article
WhatsApp Business API — Webhook Architecture in PHP

HMAC-SHA256 signature verification, the 20-second response requirement, deduplication by wa_msg_id, and webhook verification challenge handling.

📄
Part 2 article
Multi-Persona Routing

Resolving a phone number to user+role, persona classes (Lawyer/Client/Staff/Unknown) with role-aware system prompt context, and fallback for unregistered caller…

📄
Part 3 article
Intent Classification for Legal Queries

Two-layer classification: Layer 1 keyword matching for common intents, Layer 2 LLM classification for ambiguous messages, confidence thresholds, and routing to …

📄
Part 4 article
Speech-to-Text Pipeline with Whisper

Downloading voice notes from Meta's media endpoint, local Whisper transcription via HTTP microservice, language hint injection, and graceful failure handling.

📄
Part 5 article
Text-to-Speech with Kokoro TTS

The WAV-not-MP3 trap, the UTF-8 /u flag corruption bug in prepareText(), audio type classification, and keeping the model warm with a health-check cron.

📄
Part 6 article
WhatsApp Audio Delivery — The Full Pipeline

TTS → WAV → OGG/OPUS via FFmpeg → Meta upload → send media_id → monitor delivery status. The silent failure trap: API returns 200 but delivery may still fail.

📄
Part 7 article
Session Management and Conversation Context

Per-user session schema, storing last N turns, context injection into LLM prompts, session expiry, and multi-device handling.

📄
Part 8 article
Multilingual Responses — Hindi, Punjabi, English

Script-based language detection (Devanagari/Gurmukhi Unicode blocks), storing preferred_lang per contact, language-specific error messages in all three language…

📄
Part 9 article
Voice Note Traceability — Linking Audio to Records

Storing wa_message_id + transcript on created workspace items, WebhookContext globals for cross-cutting request state, and the media URL expiry trap.

📄
Part 10 article
WhatsApp Relay Pattern

Client asks the WhatsApp AI agent → bot forwards to lawyer → lawyer replies via WhatsApp → bot forwards to client. Relay detection, forwarding, expiry, and the …

← All Series