Urgent.News

What's breaking now, across hundreds of outlets.

AI

Building a WhatsApp AI assistant for Moroccan businesses (Darija) with Next.js, Supabase and Claude

Most small businesses in Morocco take orders on WhatsApp. The owner reads every message, types the menu again and again, and misses messages at night. I wanted to see how far a small, cheap AI assistant could go for them, so I built one that answers in Moroccan Darija, French or Arabic. The problem Customers write in Darija (often in Latin letters), French, or a mix of both. Answers must come…

In Morocco, the majority of small businesses handle customer orders through WhatsApp. The owner must read every message, repeat the menu, and risk missing messages outside of regular business hours. To address this issue, the reporter built an AI assistant that answers customer inquiries in Moroccan Darija, French, or Arabic.

The assistant is designed to only provide information from the business's actual menu, prices, and hours, without inventing any dishes. The owner is notified when a customer has placed an order or requires a human's assistance. The entire system uses a single codebase for multiple merchants, ensuring that no data is mixed.

The architecture of the assistant relies on routing by phone_number_id. WhatsApp Cloud API sends every message to a single webhook, which identifies the merchant (tenant) based on the phone number ID of the receiving number. Isolation is achieved using Supabase Postgres with Row Level Security, ensuring that merchants can only access their own data.

Token security is maintained by encrypting each merchant's WhatsApp token using AES-256-GCM in a table with no public policy. The webhook undergoes strict safety measures, including an HMAC signature check, immediate 200 response, background processing, and a table to handle duplicate message IDs. Monthly conversation limits are set per plan, and if the limit is reached, the customer receives a fixed message without any LLM calls, capping the cost.

Claude Haiku is used as the LLM, with a system prompt built from the merchant's catalog, hours, and information. Special tags in the reply trigger order or human-handoff alerts to the owner. One surprising discovery was the 24-hour rule, where WhatsApp only delivers free-form messages within 24 hours of the customer's last message. Outside this window, an approved template is required for alerts.

The assistant also addresses the token expiry issue, as Meta's test token lasts approximately 24 hours. Detection of expired tokens is implemented to inform merchants of the necessary steps. Delivery is asynchronous, meaning the API can accept a message and handle the response later, with the webhook statuses events providing the actual reason for the delay.

Structured editing is preferred over free text, as merchants do not want to write prompts. The dashboard takes product rows, opening hours, and delivery information and converts them into text that the model can understand, without losing any critical details. However, the story does not cover subscription payments, Meta's Embedded Signup for easy onboarding, voice-message transcription, or approved message templates for out-of-window alerts.

The reporter has packaged the entire project (Next.js 15, TypeScript, Supabase, Tailwind v4, tests, and installation/.env/usage guides) as a paid source-code product, targeting developers and agencies who wish to offer this solution to their clients: https://hajarlmz.gumroad.com/l/nlgxr. The dashboard and guides are currently in French, and the reporter welcomes questions and feedback in the comments.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in AI

Human-in-the-Loop AI Agents: Who Approves What

"Human in the loop" is easy to say and easy to get wrong. Put the person on every step and the AI saves nobody any time. Put the person nowhere and the first wrong refund lands on your bank statement.

  • AI handles product facts, policies, troubleshooting, and order lookups
  • Humans approve money-related decisions, reshipments, returns, and policy breaches
  • Approval loop ensures quick decision-making and human oversight

How AI Can Turn Hundreds of PDF Documents Into Structured Product Data

Many companies work with large amounts of product-related information every day. Technical datasheets, safety documents, certificates, bills of materials and other files often contain important…

  • AI can extract structured product data from hundreds of PDF documents
  • Manual document review becomes difficult with increasing products and documents
  • AI systems organize extracted data into categories for databases or systems

What are the best Databricks alternatives for LLM training?

If you use Databricks mainly to run LLM training and fine-tuning jobs, the cheapest alternative at list price is Nodus: Databricks AI Runtime lists the NVIDIA H100 at $7.00 per GPU-hour, Nodus lists…

  • Nodus offers $2.60 per GPU-hour, cheaper than Databricks' $7.00 per GPU-hour.
  • Nodus provides prepaid credits, monthly billing, and no storage limits.
  • Databricks allows longer-running jobs than Nodus, requiring checkpointing.

How an AI Support Agent Learns From Agent Edits

Every time a support agent edits an AI draft before sending it, they show the system how the company actually handles that case. In the 30 days to 19 November 2026, agents in the deployment from our case study edited 19,339 AI drafts. That is the most valuable training material the system has, and it is easy to lose.

  • Agents edit AI drafts 19,339 times in 30 days
  • System stores AI draft and final version separately
  • Distilled rules guide consistent AI response generation

More from Sunday 22 November →