/ Cases / Bakery / AI agent
The customer fills a basket from WhatsApp's native catalog and pays; the bank transfer confirms itself. The owner manages orders, inventory, cash and expenses from the same chat.
1–2 s
catalog sync
6
admin modules over chat
/ The problem
Orders came in on WhatsApp as free text and were copied over by hand. Confirming every transfer took time and caused errors.
/ What we built
/ How it works
/ Real code
const cutoff = new Date(Date.now() - 48 * 3600 * 1000).toISOString();
const { data: raw, error } = await supabase
.from("orders")
// …
.eq("payment_method", "transfer")
.neq("payment_status", "paid")
.gte("created_at", cutoff)
.order("created_at", { ascending: false });
// …
// Filter by amount within 1 cent tolerance
const candidates = (raw || []).filter((o) =>
Math.abs(Number(o.total) - amount) < 0.01
);
// …
if (candidates.length === 1) {
await markOrderPaid(candidates[0].id, recRef, "transfer_bank");
// …
}
// Multiple candidates with same amount — try fuzzy name match.
// …
if (candidateNames.some((cn) => hasNameOverlap(cn, senderName))) {
nameMatches.push(c);
}
// …
if (nameMatches.length === 1) {
await markOrderPaid(nameMatches[0].id, recRef, "transfer_bank");
// …
}
■ A transfer with no reference reconciles itself when the amount matches a single order; on a tie it uses the sender name, and otherwise it does not guess.
/ Stack