Building production WhatsApp agents with PHP: webhooks, personas, intent routing, TTS/STT.
HMAC-SHA256 signature verification, the 20-second response requirement, deduplication by wa_msg_id, and webhook verification challβ¦
Resolving a phone number to user+role, persona classes (Lawyer/Client/Staff/Unknown) with role-aware system prompt context, and faβ¦
Two-layer classification: Layer 1 keyword matching for common intents, Layer 2 LLM classification for ambiguous messages, confidenβ¦
Downloading voice notes from Meta's media endpoint, local Whisper transcription via HTTP microservice, language hint injection, anβ¦
The WAV-not-MP3 trap, the UTF-8 /u flag corruption bug in prepareText(), audio type classification, and keeping the model warm witβ¦
TTS β WAV β OGG/OPUS via FFmpeg β Meta upload β send media_id β monitor delivery status. The silent failure trap: API returns 200 β¦
Per-user session schema, storing last N turns, context injection into LLM prompts, session expiry, and multi-device handling.
Script-based language detection (Devanagari/Gurmukhi Unicode blocks), storing preferred_lang per contact, language-specific error β¦
Storing wa_message_id + transcript on created workspace items, WebhookContext globals for cross-cutting request state, and the medβ¦
Client asks the WhatsApp AI agent β bot forwards to lawyer β lawyer replies via WhatsApp β bot forwards to client. Relay detectionβ¦
Complete guide to AI Munshi β a production WhatsApp legal agent built in PHP with persona routing, STT, TTS, and intent classification.
Running Kokoro TTS, Whisper STT, Ollama LLM, and ChromaDB on a Raspberry Pi 5 β architecture, permissions, and production hardening.
Weekly digest of the best new articles, videos, and tutorials. No spam, unsubscribe anytime.
β Check your inbox to confirm!