Small business owners in many regions are drowning in manual WhatsApp order processing, typing out menus repeatedly and missing late-night inquiries. A new open-source implementation details how to build a multilingual AI assistant using Next.js, Supabase, and Anthropic’s Claude Haiku to automate this workflow. The solution prioritizes strict data isolation and cost control, ensuring that the AI answers only from the merchant’s actual catalog without hallucinating inventory or breaking the bank.
Architecture and Data Isolation
The system routes incoming messages via the WhatsApp Cloud API webhook, identifying the specific merchant tenant by the receiving phone_number_id. To prevent data leakage between businesses, the backend utilizes Supabase Postgres with Row Level Security (RLS), ensuring merchants can only read their own rows. Sensitive credentials, such as each merchant’s WhatsApp token, are encrypted using AES-256-GCM in a table with no public access policy, while write operations are handled exclusively by server-side code using the service role.
LLM Integration and Cost Control
The core intelligence is powered by Claude Haiku, configured with a system prompt dynamically constructed from the merchant’s specific catalog, hours, and business info. The model is instructed to answer in the same language and script the customer uses, handling mixed dialects and Latin characters. To manage expenses, the system enforces monthly conversation quotas per plan; if a merchant exceeds their limit, the customer receives a static message, and no LLM call is made, effectively capping costs. Special tags in the AI’s response trigger alerts to the owner for orders or human handoff requests.
Operational Realities and Edge Cases
The developer highlighted several critical operational constraints discovered during implementation. WhatsApp’s 24-hour rule restricts free-form messages to a window after the customer’s last interaction, requiring approved templates for alerts sent outside this period. Token management is also fragile; Meta’s test tokens expire in roughly 24 hours, necessitating a System User for permanent tokens and error handling for expired credentials (error 190). Furthermore, message delivery is asynchronous, meaning the API may accept a request but fail later, requiring logs of webhook status events for true reliability.
Key Takeaways
- Dynamic system prompts built from structured database rows allow Claude Haiku to answer accurately without hallucinating menu items.
- Row Level Security in Supabase is essential for multi-tenant SaaS architectures to prevent cross-merchant data leaks.
- Hard-coded quotas that bypass the LLM entirely are necessary to prevent runaway API costs in high-volume environments.
- Handling WhatsApp’s 24-hour messaging window and token expiry requires proactive error detection in the backend.
The Bottom Line
This implementation proves that small businesses can leverage Claude Haiku for complex, multilingual customer service without needing enterprise-grade infrastructure, provided they rigorously engineer around WhatsApp’s restrictive messaging policies and implement hard cost caps.