Send the reminder as a custom utility template with two quick-reply buttons, Confirm and Reschedule, and put the booking ID in each button’s payload. Set message_send_ttl_seconds on the template so Meta drops a reminder it can’t deliver in time. A tap reaches your webhook as a type: "button" message, and you update the booking row from its payload.
This is the generic loop for any bookings table and scheduler. Cal.com webhooks to WhatsApp reminders applies it to Cal.com and Cal.diy. Instagram and Messenger DM bookings applies it to bookings that start in a DM. The loop also runs from Calendly and class timetables, a WhatsApp waitlist can fill freed slots, and Meta’s booking appointment template has its own guide.
The loop from booking to updated row
The WhatsApp Cloud API has no scheduler, so the timing lives in your own job. Everything else runs through Meta’s send endpoint and one webhook.
- Save the booking with a phone number in E.164 and a WhatsApp opt-in captured on the booking form.
- Run a job every minute that sends
reminder_24ha day ahead andreminder_2htwo hours ahead. - The customer taps Confirm or Reschedule, and Meta posts a
buttonmessage to your webhook. - Match the tap to the booking, update its status and answer inside the 24-hour window that the tap opened.
- Watch status webhooks: no
deliveredstatus before the TTL ends means Meta dropped the reminder.
Capture consent when the booking is made, in words that name WhatsApp and the purpose. How to collect WhatsApp opt-in covers the wording and the record to keep.
Use a custom utility template for the reminder
Meta offers a dedicated booking appointment template, but it can’t carry the buttons this loop needs. Its only button is booking_status, shown as “View details”. A template takes one, and it “cannot be combined with other button types” (booking appointment templates, accessed 2026-11-25).
A custom template with QUICK_REPLY buttons does the job. “Templates are limited to 10 quick reply buttons”, and each label has a “25 characters maximum”. Quick replies sit in their own group, apart from URL or phone buttons (template components, accessed 2026-11-25). Two short labels fit with room to spare.
Where the booking appointment template still fits
Use it for the confirmation right after booking. It puts date, time, location and management links in one message, and “View details” opens a bottom sheet. You create it with category utility, parameter_format named, a text header of up to 60 characters and a body of up to 1,024. At send time, a booking_status button component carries start_datetime, which is required, plus optional keys such as end_datetime, location, booking_url and booking_management_url.
Datetimes are ISO 8601 with an offset, such as -07:00. The page also says: “You must provide at least one of location, booking_url, or phone_number at send time.” The page names the notes parameter param_name in one section and parameter_name in its full example, so copy Meta’s JSON and test both. The page documents no webhook for a “View details” tap.
The Template Library has no ready-made reminder either. Its industries are E_COMMERCE and FINANCIAL_SERVICES, with no appointment use case to clone (Template Library, accessed 2026-11-25).
Why the reminder passes as utility
Meta’s categorization page asks a utility template to be “non-promotional” and “specific to or requested by the user”. Its examples are messages “clearly related to their order, account, services, or transactions” (template categorization, accessed 2026-11-25). A reminder for an appointment the customer booked meets both tests. The page has no appointment example. Its nearest one is a payment reminder for a service the user already has.
A promotion inside the reminder turns it into marketing. A line about a seasonal offer under the appointment time is enough. Meta’s penalties escalate: a warning, then immediate recategorization, then utility rate limiting for at least 7 days. Next comes a utility restriction of 7 days, or 30 for repeat violations, during which all your utility templates go out as marketing. The last step is a 30-day portfolio restriction.
For clinics and other health services, keep the body to the time, the place and the professional’s name. Leave out treatment details and anything clinical. The category rules are in more depth in WhatsApp template categories.
Create one template per lead time
The TTL belongs to the template, not to each send. The field is message_send_ttl_seconds, set when you create or update the template. For utility templates, the range is 30 seconds to 12 hours, the default is 30 days, and -1 also means 30 days (time-to-live, accessed 2026-11-25). Meta “drops messages that cannot be delivered within the default or customized TTL.” Utility TTL works on the Cloud API only.
Because the TTL is per template, a 24-hour reminder and a 2-hour reminder need two templates. Pick a TTL that ends well before the appointment. Sent at T-24h with a TTL of 43,200 seconds, the reminder is dropped at T-12h if the phone never came online.
curl "https://graph.facebook.com/v26.0/$WABA_ID/message_templates" \
-H "Authorization: Bearer $WA_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "reminder_24h",
"language": "en_US",
"category": "UTILITY",
"parameter_format": "NAMED",
"message_send_ttl_seconds": 43200,
"components": [
{
"type": "BODY",
"text": "Hi {{customer_name}}, this is a reminder of your appointment on {{date}} at {{time}} with {{professional}}. Please confirm or pick a new time.",
"example": {
"body_text_named_params": [
{ "param_name": "customer_name", "example": "Marina" },
{ "param_name": "date", "example": "Friday, November 27" },
{ "param_name": "time", "example": "2:30 PM" },
{ "param_name": "professional", "example": "Jordan Lee" }
]
}
},
{
"type": "BUTTONS",
"buttons": [
{ "type": "QUICK_REPLY", "text": "Confirm" },
{ "type": "QUICK_REPLY", "text": "Reschedule" }
]
}
]
}'
Run it again with "name": "reminder_2h" and "message_send_ttl_seconds": 3600. The body starts with “Hi” because a variable may not open or close the text. If Meta recategorizes a template, it clears the custom TTL to null, so read message_send_ttl_seconds back after any category change. Status handling around TTL is in delivery reports from status webhooks.
What a tap looks like in your webhook
A quick-reply tap on a template arrives as an inbound message with type: "button". This is Meta’s sample from the button webhook reference, unchanged except for line breaks (button webhook reference, accessed 2026-11-25):
{
"object": "whatsapp_business_account",
"entry": [
{
"id": "102290129340398",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "15550783881",
"phone_number_id": "106540352242922"
},
"contacts": [
{
"profile": { "name": "Sheena Nelson" },
"wa_id": "16505551234",
"user_id": "US.13491208655302741918"
}
],
"messages": [
{
"context": {
"from": "15550783881",
"id": "wamid.HBgLMTQxMjU1NTA4MjkVAgASGBQzQUNCNjk5RDUwNUZGMUZEM0VBRAA="
},
"from": "16505551234",
"from_user_id": "US.13491208655302741918",
"id": "wamid.HBgLMTY1MDM4Nzk0MzkVAgASGBQzQUFERjg0NDEzNDdFODU3MUMxMAA=",
"timestamp": "1750091045",
"type": "button",
"button": {
"payload": "Unsubscribe",
"text": "Unsubscribe"
}
}
]
},
"field": "messages"
}
]
}
]
}
context.id is the wamid of the template message the customer tapped. Meta’s sample sets payload and text to the same label, and the reference describes both as the label. Meta’s Node SDK docs describe payload as a “developer-defined payload that is returned when the button is clicked in addition to the display text” (button parameter object, accessed 2026-11-25). So parse button.payload first. If it isn’t in your format, match context.id against the wamid you stored at send time. Never match by phone number alone: a customer can hold two appointments, and the payload bk|<id>|confirm names one booking.
Identify the customer by from_user_id as well as from. Meta omits wa_id and from when a user has a username and no available phone. Migrating a contact database to BSUID covers the change.
The reminder service
This file runs as pasted on Node 18 or later with Express 4. It holds bookings in memory so you can try it, and each table maps to a database table you’d keep. It verifies X-Hub-Signature-256, sends both reminders, handles taps and list picks, and tracks delivery against the TTL.
// reminders.js: WhatsApp appointment reminders with Confirm and Reschedule.
// Node 18+ and Express 4. Run: npm install express && node reminders.js
const crypto = require("crypto");
const express = require("express");
for (const name of ["WA_TOKEN", "PHONE_NUMBER_ID", "APP_SECRET", "VERIFY_TOKEN", "INTERNAL_TOKEN"]) {
if (!process.env[name]) throw new Error(`Missing environment variable ${name}`);
}
const { WA_TOKEN, PHONE_NUMBER_ID, APP_SECRET, VERIFY_TOKEN, INTERNAL_TOKEN } = process.env;
const BOOKING_URL = process.env.BOOKING_URL || "https://example.com/book";
const PORT = Number(process.env.PORT || 3000);
const GRAPH_URL = `https://graph.facebook.com/v26.0/${PHONE_NUMBER_ID}/messages`;
const MINUTE = 60 * 1000;
const HOUR = 60 * MINUTE;
const TTL_BUFFER = 5 * MINUTE;
// One template per lead time, because the TTL lives on the template.
// ttlMs must match message_send_ttl_seconds on the approved template.
const REMINDERS = [
{ template: "reminder_24h", leadMs: 24 * HOUR, ttlMs: 12 * HOUR },
{ template: "reminder_2h", leadMs: 2 * HOUR, ttlMs: 1 * HOUR },
];
// In-memory tables so the file runs as is. Use your database in production.
const bookings = new Map(); // booking id -> booking
const sends = new Map(); // reminder wamid -> { bookingId, template, sentAt, ttlMs, state }
const seenInbound = new Set(); // inbound wamids already handled
function formatWhen(iso, timeZone) {
const d = new Date(iso);
return {
date: d.toLocaleDateString("en-US", { timeZone, weekday: "long", month: "long", day: "numeric" }),
time: d.toLocaleTimeString("en-US", { timeZone, hour: "numeric", minute: "2-digit" }),
short: d.toLocaleString("en-US", {
timeZone, weekday: "short", month: "short", day: "numeric", hour: "numeric", minute: "2-digit",
}),
};
}
async function sendWhatsApp(message, attempt = 1) {
let status = 0;
let data = {};
try {
const res = await fetch(GRAPH_URL, {
method: "POST",
headers: { Authorization: `Bearer ${WA_TOKEN}`, "Content-Type": "application/json" },
body: JSON.stringify({ messaging_product: "whatsapp", recipient_type: "individual", ...message }),
});
status = res.status;
data = await res.json().catch(() => ({}));
if (res.ok) return data.messages[0].id;
} catch (err) {
data = { error: String(err) }; // network error or unexpected body
}
const retryable = status === 0 || status === 429 || status >= 500;
if (retryable && attempt < 4) {
await new Promise((resolve) => setTimeout(resolve, 2 ** attempt * 1000));
return sendWhatsApp(message, attempt + 1);
}
throw new Error(`Send failed with HTTP ${status}: ${JSON.stringify(data)}`);
}
const sendText = (to, body) => sendWhatsApp({ to, type: "text", text: { body } });
async function sendReminder(booking, reminder) {
const when = formatWhen(booking.startTime, booking.timeZone);
const buttons = ["confirm", "reschedule"].map((action, index) => ({
type: "button",
sub_type: "quick_reply",
index: String(index),
parameters: [{ type: "payload", payload: `bk|${booking.id}|${action}` }],
}));
const wamid = await sendWhatsApp({
to: booking.phone,
type: "template",
template: {
name: reminder.template,
language: { code: "en_US" },
components: [
{
type: "body",
parameters: [
{ type: "text", parameter_name: "customer_name", text: booking.name },
{ type: "text", parameter_name: "date", text: when.date },
{ type: "text", parameter_name: "time", text: when.time },
{ type: "text", parameter_name: "professional", text: booking.professional },
],
},
...buttons,
],
},
});
sends.set(wamid, {
bookingId: booking.id, template: reminder.template, sentAt: Date.now(), ttlMs: reminder.ttlMs, state: "sent",
});
return wamid;
}
async function runReminders() {
const now = Date.now();
for (const booking of bookings.values()) {
if (!booking.optIn || booking.status === "cancelled") continue;
const start = Date.parse(booking.startTime);
for (const reminder of REMINDERS) {
if (booking.reminders[reminder.template]) continue; // sending, sent, skipped or failed
const due = start - reminder.leadMs;
if (now < due) continue;
const tooLate = now >= due + reminder.ttlMs || now >= start; // past the window this lead time was meant for
const notNeeded = reminder.template === "reminder_2h" && booking.status === "confirmed";
if (tooLate || notNeeded) {
booking.reminders[reminder.template] = "skipped";
continue;
}
booking.reminders[reminder.template] = "sending"; // claimed before the await
try {
booking.reminders[reminder.template] = await sendReminder(booking, reminder); // stores the wamid
} catch (err) {
booking.reminders[reminder.template] = "failed";
console.error("reminder failed", booking.id, reminder.template, err.message);
}
}
}
for (const [wamid, send] of sends) {
if (send.state === "sent" && now > send.sentAt + send.ttlMs + TTL_BUFFER) {
send.state = "dropped"; // no delivered status before the TTL ended
const booking = bookings.get(send.bookingId);
if (booking && booking.reminders[send.template] === wamid) booking.reminders[send.template] = "dropped";
console.warn("reminder dropped after TTL", send.bookingId, send.template);
}
}
}
function writeBack(booking, change) {
// Replace with an UPDATE on your bookings table or a call to your calendar API.
Object.assign(booking, change, { updatedAt: new Date().toISOString() });
console.log("booking updated", booking.id, change);
}
function freeSlots(booking) {
// Stub: replace with a query on your calendar. Returns ISO start times.
const start = Date.parse(booking.startTime);
return [1, 2, 3].map((days) => new Date(start + days * 24 * HOUR).toISOString());
}
async function onTap(booking, action) {
const when = formatWhen(booking.startTime, booking.timeZone);
if (Date.parse(booking.startTime) <= Date.now()) {
return sendText(booking.phone, "This appointment has already passed. Reply here if you would like a new one.");
}
if (booking.status === "cancelled") {
return sendText(booking.phone, "This appointment was cancelled. Reply here if you would like a new one.");
}
if (action === "confirm") {
if (booking.status === "confirmed") return; // a second tap changes nothing
writeBack(booking, { status: "confirmed" });
return sendText(booking.phone, `Thanks, ${booking.name}. You are confirmed for ${when.date} at ${when.time}.`);
}
if (action === "reschedule") {
if (booking.status === "reschedule_requested") return;
writeBack(booking, { status: "reschedule_requested" });
const rows = freeSlots(booking).slice(0, 10).map((iso) => ({
id: `slot|${booking.id}|${iso}`,
title: formatWhen(iso, booking.timeZone).short.slice(0, 24),
}));
if (rows.length === 0) {
return sendWhatsApp({
to: booking.phone,
type: "interactive",
interactive: {
type: "cta_url",
body: { text: "No open times fit right now. Pick a new time on our booking page." },
action: { name: "cta_url", parameters: { display_text: "Choose a time", url: BOOKING_URL } },
},
});
}
return sendWhatsApp({
to: booking.phone,
type: "interactive",
interactive: {
type: "list",
body: { text: "Which of these times works for you?" },
action: { button: "See times", sections: [{ title: "Open times", rows }] },
},
});
}
}
async function onSlot(booking, iso) {
if (booking.status !== "reschedule_requested" || Number.isNaN(Date.parse(iso))) return;
// Check here that the slot is still free in your calendar before you write.
writeBack(booking, { startTime: iso, status: "confirmed", reminders: {} });
const when = formatWhen(iso, booking.timeZone);
return sendText(booking.phone, `Done. Your new time is ${when.date} at ${when.time}.`);
}
async function handleMessage(msg) {
if (msg.type === "button") {
const tapped = sends.get(msg.context?.id);
if (tapped && tapped.state === "sent") tapped.state = "delivered"; // a tap proves delivery
let [prefix, bookingId, action] = String(msg.button?.payload || "").split("|");
if (prefix !== "bk") {
// Payload not in our format: find the reminder this tap belongs to.
bookingId = sends.get(msg.context?.id)?.bookingId;
action = { Confirm: "confirm", Reschedule: "reschedule" }[msg.button?.text];
}
const booking = bookings.get(bookingId);
if (booking && action) return onTap(booking, action);
return console.warn("unmatched button tap", msg.id);
}
if (msg.type === "interactive" && msg.interactive?.type === "list_reply") {
const [prefix, bookingId, iso] = String(msg.interactive.list_reply?.id || "").split("|");
const booking = bookings.get(bookingId);
if (prefix === "slot" && booking) return onSlot(booking, iso);
return;
}
if (msg.type === "text" && msg.from && /^\s*stop\s*$/i.test(msg.text?.body || "")) {
for (const booking of bookings.values()) {
if (booking.phone === msg.from) booking.optIn = false;
}
return sendText(msg.from, "You will not get appointment reminders here anymore.");
}
}
async function handleWebhook(body) {
for (const entry of body.entry || []) {
for (const change of entry.changes || []) {
if (change.field !== "messages") continue;
const value = change.value || {};
for (const status of value.statuses || []) {
const send = sends.get(status.id);
if (!send || send.state !== "sent") continue;
if (status.status === "delivered" || status.status === "read") send.state = "delivered";
if (status.status === "failed") {
send.state = "failed";
console.warn("reminder failed", send.bookingId, JSON.stringify(status.errors));
}
}
for (const msg of value.messages || []) {
if (seenInbound.has(msg.id)) continue; // Meta retried this webhook
seenInbound.add(msg.id);
await handleMessage(msg).catch((err) => console.error("handler error", msg.id, err.message));
}
}
}
}
const app = express();
// Your booking system calls this when a booking is saved.
app.post("/bookings", express.json(), (req, res) => {
if (req.get("Authorization") !== `Bearer ${INTERNAL_TOKEN}`) return res.sendStatus(401);
const { id, phone, name, professional, startTime, timeZone = "UTC", optIn } = req.body || {};
const valid = /^[\w-]{1,64}$/.test(String(id)) && /^[1-9]\d{7,14}$/.test(String(phone))
&& !Number.isNaN(Date.parse(startTime));
if (!valid) {
return res.status(400).json({ error: "Need id, phone as E.164 digits without +, and an ISO startTime" });
}
const booking = {
id: String(id), phone: String(phone), name, professional, startTime, timeZone,
optIn: optIn === true, status: "pending", reminders: {},
};
bookings.set(booking.id, booking);
res.status(201).json(booking);
});
app.get("/webhook", (req, res) => {
const ok = req.query["hub.mode"] === "subscribe" && req.query["hub.verify_token"] === VERIFY_TOKEN;
return ok ? res.send(String(req.query["hub.challenge"])) : res.sendStatus(403);
});
app.post("/webhook", express.raw({ type: "application/json" }), (req, res) => {
if (!Buffer.isBuffer(req.body)) return res.sendStatus(400);
const received = Buffer.from(req.get("X-Hub-Signature-256") || "");
const expected = Buffer.from("sha256=" + crypto.createHmac("sha256", APP_SECRET).update(req.body).digest("hex"));
if (received.length !== expected.length || !crypto.timingSafeEqual(received, expected)) {
return res.sendStatus(401);
}
res.sendStatus(200); // answer first, work after
let body;
try {
body = JSON.parse(req.body.toString("utf8"));
} catch {
return;
}
handleWebhook(body).catch((err) => console.error("webhook error", err.message));
});
setInterval(() => runReminders().catch((err) => console.error("scheduler error", err.message)), MINUTE);
app.listen(PORT, () => console.log(`listening on ${PORT}`));
Create a booking that starts about 20 hours from now, and the next tick sends reminder_24h at once. Set startTime in this request to such a time before you run it.
curl -X POST http://localhost:3000/bookings \
-H "Authorization: Bearer $INTERNAL_TOKEN" \
-H "Content-Type: application/json" \
-d '{"id":"bk-1042","phone":"16505551234","name":"Marina","professional":"Jordan Lee","startTime":"2026-11-27T14:30:00-05:00","timeZone":"America/New_York","optIn":true}'
The booking states are pending, confirmed, reschedule_requested and cancelled. Each reminder slot holds sending, a wamid, skipped, failed or dropped. That second field is what stops the scheduler from sending the same reminder twice, so keep it in the database row, not in memory.
Answer Confirm and Reschedule inside the window
A tap is an inbound message, so it opens a 24-hour customer service window. Inside it you can answer without a template. For Confirm, the service sends a plain acknowledgment. For Reschedule, it sends an interactive list of open times, each row ID carrying the booking ID and the slot. If no slot fits, it falls back to a CTA URL button that opens your booking page.
Row titles are capped at 24 characters and a list holds 10 rows across all sections. The service trims titles to fit. Interactive buttons and list messages has the full limits table.
These free-form replies count as service messages. Since 2026-10-01, Meta gives each number 1,000 free service messages a month and charges after that, as explained in Meta’s service message charges from October 2026.
When the loop breaks
The reminder was never delivered
Meta sends no error code when the TTL drops a message, so the missing delivered status is the only sign. The service waits for the TTL plus a five-minute buffer, then marks the reminder dropped. That’s the point to hand the booking to a person for a phone call, or to try another channel the customer agreed to.
The customer never answers
A delivered reminder with no tap tells you nothing about attendance. The service leaves the booking pending and still sends the 2-hour reminder. Stop there. A third template for the same appointment adds cost and gives the customer a reason to block the number.
The same tap arrives twice
Meta retries webhooks it thinks failed, so a tap can reach you more than once. The service dedupes on the inbound message id first. The state machine then catches a second, separate tap, because a booking that is already confirmed ignores another Confirm. For dedupe that survives a restart, store each inbound wamid in a column with a unique index.
Late reminders and late taps
The TTL drops undelivered reminders, but a reminder that is delivered late still lands. The scheduler checks that the appointment is still in the future before it sends, and skips a lead time whose TTL window has already passed. A tap that arrives after the start time gets a short reply saying the appointment has passed.
The customer opts out
A reply of STOP turns off reminders for every booking on that number. Record the opt-out where your booking form reads consent, so the next booking doesn’t switch it back on.
Meta rejects or times out the send
The service retries network errors, 429 and 5xx responses three times with backoff, and gives up on other 4xx errors. Log those bodies, because they usually mean a template name, language or parameter mismatch. One risk remains: a timeout after Meta accepted the request can produce a second reminder on retry. If that matters more than a missed reminder, lower the attempt count.
Where Z-API Omni fits
Omni’s custom template docs include an “Appointment reminder” model with Confirm and Reschedule quick replies, like reminder_24h. Its body opens with a variable, which the same page says Meta rejects, so add a word such as “Hi” first. You create it with POST /whatsapp/businesses/{wabaId}/templates, which accepts message_send_ttl_seconds, and send it with POST /v1/channels/{channelId}/messages. Templates work on Meta Cloud API channels only. The docs don’t yet show the inbound JSON of a template button tap, so test that mapping before you port the handler.
The scheduler stays yours. A send to a disconnected channel returns 422 with CHANNEL_DISCONNECTED, and the message “is not kept to go out later”. Pricing is US$29 per number per month for 1 to 10 numbers, US$26 for 11 to 50, US$23 for 51 to 100 and US$20 above 100. Meta’s fees are passed through on the official connection.
curl -X POST "https://api.omni.z-api.io/v1/channels/$CHANNEL_ID/messages" \
-H "Authorization: Bearer $OMNI_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"recipient": { "identifier": "16505551234" },
"content": {
"type": "TEMPLATE",
"attachments": [
{
"template": {
"name": "appointment_reminder",
"language": { "policy": "deterministic", "code": "en_US" },
"components": [
{
"type": "body",
"parameters": [
{ "type": "text", "text": "Marina" },
{ "type": "text", "text": "2:30pm" },
{ "type": "text", "text": "Jordan Lee" }
]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": 0,
"parameters": [{ "type": "payload", "payload": "bk|bk-1042|confirm" }]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": 1,
"parameters": [{ "type": "payload", "payload": "bk|bk-1042|reschedule" }]
}
]
}
}
]
}
}'
Z-API Omni team