- Go
- Product
WhatsApp from the restaurant’s own number: linked devices, consent and the review loop
A bill on WhatsApp from “Fravolo” is spam. The same bill from the restaurant’s own number is a conversation: the guest recognises it, can reply, and the owner sees the reply. So instead of sending from a shared business account, Fravolo links each outlet’s own number as a device, the same way WhatsApp Web does. That one decision drives most of the design in this post.
Linking the outlet’s phone as a device
The owner opens Business settings and scans a QR code with the outlet’s WhatsApp — or, because a phone cannot scan its own screen, asks for a short pairing code and types it into WhatsApp instead. The API holds a multi-device session for that number using an open-source Go implementation of the WhatsApp protocol. From then on Fravolo can send from the number and receive what guests send to it.
Two rules are enforced at the moment of pairing:
- The number must be the outlet’s. The phone that scanned is compared with the business phone in the outlet’s settings, normalised with the market’s dialling code. Any other number is logged out and its device deleted on the spot. Nobody can link a personal phone to send a restaurant’s bills.
- One number per outlet. Within a restaurant, a number already linked to another outlet is refused — checked before pairing starts, and again when it completes.
func (s *Service) Paired(ctx context.Context, k Key, got string) error {
want, err := s.expected(ctx, k.Outlet) // Business settings phone, normalised
if err != nil {
return err
}
if got != want {
return ErrWrongPhone // the session layer logs this device out
}
if used, err := s.r.phoneUsed(ctx, k.Tenant, got, k.Outlet); err != nil {
return err
} else if used {
return ErrPhoneInUse
}
// ... record the link as connected ...
return s.r.saveLink(ctx, link)
}Exactly one process owns the sessions
A linked device is a set of keys. If two processes connect with the same keys, WhatsApp tells each that it has been replaced, they reconnect, replace each other again, and before long the number gets flagged. So the session store — a small SQLite file, using a pure-Go driver because our API image has no C toolchain — is opened only by the instance that runs background jobs. If that process is ever told it has been replaced, it drops the session and steps aside instead of fighting. The API runs as a single instance today, and that instance owns every session.
On boot, the manager clears pairings a restart interrupted and restores every active link. The reconnects are spread out randomly over a short window, so a deploy does not log every restaurant’s number in from one address in the same second.
An inbox, not a firehose
A restaurant’s phone receives a lot that is not about the restaurant. Incoming messages pass through a reducer that drops groups, status updates, channels, reactions, edits and notes-to-self, and keeps one-to-one conversations with a phone number. When a number is linked, the last week of direct chats is pulled in so the inbox does not start empty. Threads and messages are stored as the restaurant’s business data — scoped like everything else — and each new message is published on the live bus, so the inbox refreshes and the owner’s phone gets a push.
Replies from the inbox go out from the same number. The guest sees one continuous conversation with the restaurant, which is the whole point.
Consent and quiet hours, in code
Being on the restaurant’s own number raises the bar: a guest who is annoyed blocks the restaurant, not us. Every message has a purpose, and the purpose decides what is allowed.
| Purpose | Consent needed | Quiet hours |
|---|---|---|
| A bill the guest just paid | No — it is their receipt | Never held |
| The owner replying in the inbox | No — it is a conversation | Not held |
| A thank-you or rating request after the visit | Sent unless the guest said no | Deferred to morning |
| A birthday greeting | Sent unless the guest said no | Deferred to morning |
| A broadcast | Customers who opted in (a WhatsApp yes, or consent recorded by staff), or a list the restaurant pastes — never a guest who said no | Deferred to morning |
A follow-up asks whether the guest would like to hear from the restaurant, and asks again after a couple of months until they answer. Short replies to that question are read as answers, in English, Hindi and Hinglish — “yes”, “haan”, “theek”, “ok”, “no”, “nahi”, “stop”. A no stops everything except bills and the owner’s own replies (until the guest says yes to a later ask), and it is checked twice: when a message is planned and again at the moment it is sent.
// SendTo: a guest's NO stops everything but their bill and the owner's replies.
if purpose != PurposeBill && purpose != PurposeReply && th.Consent == "no" {
return ErrOptedOut
}
// Where follow-ups, birthdays and broadcasts are planned:
due = DeferForQuiet(due, quiet.From, quiet.To, loc) // the restaurant's clockQuiet hours run on the restaurant’s own clock — Delhi, Dubai, London or Amsterdam — and handle windows that cross midnight. Consent itself is explicit: every customer starts opted out of marketing, the staff form’s consent box starts unticked, and a yes or no on WhatsApp records when it was given and where. A guest gets at most one follow-up a month from a restaurant, and none if one is already waiting to go. Automatic sends are spaced out with a human-like gap rather than fired as fast as the protocol allows.
Jobs, not inline sends
Bills, the day-end report and the owner’s replies go out inline. Follow-ups, rating replies, birthday messages and broadcasts are rows in a job table with a due time. A runner claims due jobs oldest-first with an atomic update, sends, and records the outcome; a failure is retried a few times with growing back-off, unless the number has been unlinked. A broadcast is planned first — how many guests, who was skipped and why, when the first and last messages will go — and only then written as one job per guest, spread over time and pushed past quiet hours. Until the last job goes, it can be cancelled.
The review loop
After a visit, the thank-you message can ask for a rating from one to five. Guests answer in every way you can imagine, so the parser accepts “4”, “5/5”, “4 stars”, a row of star emoji, and Devanagari digits. A rating only counts if it arrives within a couple of days of the question.
- Four or five: a thank-you with a link to the restaurant’s Google review page.
- One to three: an apology that asks what went wrong, an alert to the owner’s phone with the bill number, and the guest’s next message saved as their comment. The owner can often fix it while the guest is still nearby.
Every rating is kept, and the owner’s dashboard shows the average, the spread, the unhappy count and how many guests were asked — so a restaurant can see whether a bad week was one table or a pattern.
When the number is not linked
Not every restaurant links its number on day one. The bill sender prefers the linked number when an outlet has one, and otherwise falls back to an approved template through the official WhatsApp Business platform, or to a one-tap share link the cashier sends by hand. The guest gets their bill either way; only the linked number turns it into a conversation.
Trade-offs
- We depend on a protocol we do not control. A linked device is how WhatsApp Web works, but WhatsApp can still restrict a number that behaves like a bulk sender. That is why sends are paced, consent is enforced in code and broadcasts are capped. We tell restaurants this plainly before they link.
- One process is a single point of failure for messaging. If the instance holding the sessions is down, nothing goes out from the linked numbers: cashiers can still share a bill by hand, and follow-ups wait in the queue. A failed send from a linked number does not fall back to the template route either. Splitting sessions across workers needs a sharded store and a lease per number; it is the first thing we would build when one process is no longer enough.
- Consent words are a list. English, Hindi and Hinglish today. Dutch guests answering “nee” or “ja” are not understood yet, and that is a gap we are closing for the Netherlands.