I designed and built a self-hosted Django CRM middleware integrated directly with the official Meta Cloud API (v19.0) and OpenAI:
1. Real-Time Webhook Engine: Built a Django endpoint to capture incoming messages, process delivery status pings (Sent, Delivered, Read), and log them securely.
2. Guard-Railed Conversational AI: Integrated GPT-3.5 with strict prompt constraints. I implemented a hybrid routing layer: static keywords (like PRICE, START, TEST) trigger instantaneous rule-based templates, while conversational queries fall back to the AI. The LLM is restricted to a local pricing schema, answers in a Roman Urdu/English blend, and respects a strict 2-line length limit.
3. Media Proxy & Caching System: Meta's media links expire after 24 hours. I built a local proxy that fetches and caches audio, documents, and images on our server, served via a custom HTML5 audio playback script for voice notes.
4. Human-in-the-Loop Mechanism: Created a live-toggle state per contact. If a customer asks a query beyond the bot's data, it outputs a specialized flag (UNKNOWN_QUERY), records it, pauses the bot for that user, and alerts the operator.
5. Optimized UI: Designed a responsive dashboard using Bootstrap 5 and vanilla JavaScript with a 3-second polling state manager, avoiding heavy SPA framework overhead while maintaining a snappy user experience.