/ Cases / Restaurants / AI agent
It answers WhatsApp, Instagram, web and TikTok around the clock: books tables, sells from the online store, charges with a payment link and hands the conversation to a person when needed.
≈52
named tools
≈79 %
conversations with no handoff to a person
24 h
coverage
/ The problem
Five locations and six concepts got messages on four channels. Replies were typed by hand, late, and night messages waited until the next day, when the customer had already booked somewhere else.
/ What we built
/ How it works
/ By the numbers
■ Real production data · counts per month, no amounts or personal data · November through the 27th. Excludes the API channel (internal tests).
/ Real code
export const HUMANO_ATENDIENDO_MS = 24 * 60 * 60 * 1000;
/**
* ¿Este mensaje lo escribió una PERSONA del equipo hablándole al cliente?
*
* `message_type === 1` (outgoing) + `sender.type === 'user'`. El bot postea
* siempre con el token del agent bot (client.ts postMessage) → sale como
* `agent_bot`. Las notas privadas NO cuentan: una nota interna no es atender.
*/
export function esMensajeDeHumano(m: MensajeCrudo): boolean {
return !m.private && m.message_type === 1 && m.sender?.type === 'user';
}
// …
export function humanoAtendiendo(input: {
lastHumanAgentAt: number | null;
botRetomaAt?: number | null;
/** Marcador de `/humano` (epoch ms): cuenta como un mensaje de persona. */
humanoTomaAt?: number | null;
now?: number;
}): boolean {
const lastHumanAgentAt = Math.max(input.lastHumanAgentAt ?? 0, input.humanoTomaAt ?? 0) || null;
if (!lastHumanAgentAt) return false;
const now = input.now ?? Date.now();
if (now - lastHumanAgentAt >= HUMANO_ATENDIENDO_MS) return false;
const retoma = input.botRetomaAt ?? 0;
return !(retoma > lastHumanAgentAt);
}
■ The bot stays quiet for 24 h once a team member writes to the customer; the signal is the human message, not the assignment, and /bot hands it back early.
/ Stack