Ipadala ang reminder bilang custom utility template na may dalawang quick-reply button, Confirm (kumpirmahin) at Reschedule (i-reschedule), at ilagay ang booking ID sa payload ng bawat button. I-set ang message_send_ttl_seconds sa template para i-drop ng Meta ang reminder na hindi nito maihatid sa oras. Dumarating ang tap sa webhook mo bilang type: "button" message, at ina-update mo ang booking row mula sa payload nito.
Ito ang generic na loop para sa kahit anong bookings table at scheduler. Inilalapat ito ng Cal.com webhooks papuntang WhatsApp reminders sa Cal.com at Cal.diy. Inilalapat ito ng Instagram at Messenger DM bookings sa mga booking na nagsisimula sa DM. Tumatakbo rin ang loop mula sa Calendly at sa mga class timetable, kayang punan ng isang WhatsApp waitlist ang mga nabakanteng slot, at may sariling guide ang booking appointment template ng Meta.
Ang loop mula booking hanggang na-update na row
Walang scheduler ang WhatsApp Cloud API, kaya nasa sarili mong job ang timing. Ang lahat ng iba pa ay dumadaan sa send endpoint ng Meta at sa iisang webhook.
- I-save ang booking na may phone number sa E.164 at WhatsApp opt-in na kinuha sa booking form.
- Magpatakbo ng job bawat minuto na nagpapadala ng
reminder_24hisang araw bago at ngreminder_2hdalawang oras bago. - Tina-tap ng customer ang Confirm o Reschedule, at nagpo-post ang Meta ng
buttonmessage sa webhook mo. - I-match ang tap sa booking, i-update ang status nito at sumagot sa loob ng 24-hour window na binuksan ng tap.
- Bantayan ang status webhooks: kapag walang
deliveredstatus bago matapos ang TTL, ibig sabihin ay dinrop ng Meta ang reminder.
Kunin ang consent kapag ginawa ang booking, sa mga salitang nagpapangalan sa WhatsApp at sa layunin. Saklaw ng paano mangolekta ng WhatsApp opt-in ang wording at ang record na dapat itago.
Gumamit ng custom utility template para sa reminder
May nakalaang booking appointment template ang Meta, pero hindi nito kayang dalhin ang mga button na kailangan ng loop na ito. booking_status lang ang button nito, na lumalabas bilang “View details” (tingnan ang detalye). Isa lang ang tinatanggap ng template, at “hindi ito maisasama sa ibang uri ng button” (booking appointment templates, na-access noong 2026-11-25).
Gumagana ang custom template na may mga QUICK_REPLY button. “Limitado sa 10 quick reply button ang mga template”, at may “maximum na 25 character” ang bawat label. Nasa sariling grupo ang mga quick reply, hiwalay sa mga URL o phone button (template components, na-access noong 2026-11-25). Maluwag na kasya ang dalawang maikling label.
Kung saan bagay pa rin ang booking appointment template
Gamitin ito para sa confirmation pagkatapos mismo ng booking. Inilalagay nito sa iisang mensahe ang petsa, oras, lokasyon at mga management link, at nagbubukas ng bottom sheet ang “View details”. Ginagawa mo ito na naka-set sa utility ang category, named ang parameter_format, text header na hanggang 60 character at body na hanggang 1,024. Sa oras ng send, dala ng booking_status button component ang start_datetime, na required, kasama ang mga optional na key gaya ng end_datetime, location, booking_url at booking_management_url.
ISO 8601 na may offset ang mga datetime, gaya ng -07:00. Sinasabi rin ng page: “Dapat kang magbigay ng kahit isa sa location, booking_url o phone_number sa oras ng send.” Tinatawag ng page na param_name ang notes parameter sa isang seksiyon at parameter_name sa buong halimbawa nito, kaya kopyahin ang JSON ng Meta at subukan ang dalawa. Walang dinodokumentong webhook ang page para sa tap sa “View details”.
Wala ring handang reminder ang Template Library. E_COMMERCE at FINANCIAL_SERVICES ang mga industriya nito, at walang appointment use case na makokopya (Template Library, na-access noong 2026-11-25).
Kung bakit pumapasa bilang utility ang reminder
Hinihiling ng categorization page ng Meta na ang utility template ay “hindi promotional” at “partikular sa user o hiniling ng user”. Ang mga halimbawa nito ay mga mensaheng “malinaw na kaugnay ng kanilang order, account, serbisyo o transaksiyon” (template categorization, na-access noong 2026-11-25). Pasado sa dalawang test ang reminder para sa appointment na binook ng customer. Walang halimbawa ng appointment ang page. Ang pinakamalapit ay payment reminder para sa serbisyong mayroon na ang user.
Nagiging marketing ang reminder kapag may promosyon sa loob nito. Sapat na ang isang linya tungkol sa seasonal offer sa ilalim ng oras ng appointment. Pataas ang mga parusa ng Meta: babala, saka agarang recategorization, saka utility rate limiting nang hindi bababa sa 7 araw. Kasunod ang utility restriction na 7 araw, o 30 para sa paulit-ulit na paglabag, kung saan lalabas bilang marketing ang lahat ng utility template mo. Ang huling hakbang ay 30-araw na portfolio restriction.
Para sa mga clinic at iba pang health service, panatilihing oras, lugar at pangalan ng propesyonal lang ang body. Huwag isama ang mga detalye ng treatment at anumang klinikal. Mas malalim na tinalakay ang mga patakaran sa category sa WhatsApp template categories.
Gumawa ng isang template bawat lead time
Sa template nakakabit ang TTL, hindi sa bawat send. Ang field ay message_send_ttl_seconds, na sine-set kapag ginawa o in-update mo ang template. Para sa mga utility template, 30 segundo hanggang 12 oras ang saklaw, 30 araw ang default, at 30 araw din ang ibig sabihin ng -1 (time-to-live, na-access noong 2026-11-25). Ang Meta ay “nagda-drop ng mga mensaheng hindi maihatid sa loob ng default o customized na TTL.” Sa Cloud API lang gumagana ang utility TTL.
Dahil bawat template ang TTL, kailangan ng dalawang template ang 24-hour reminder at 2-hour reminder. Pumili ng TTL na natatapos nang mas maaga sa appointment. Kapag ipinadala sa T-24h na may TTL na 43,200 segundo, dina-drop ang reminder sa T-12h kung hindi kailanman nag-online ang phone.
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" }
]
}
]
}'
Patakbuhin ulit ito na may "name": "reminder_2h" at "message_send_ttl_seconds": 3600. Nagsisimula sa “Hi” ang body dahil hindi puwedeng magbukas o magsara ng text ang isang variable. Kapag ni-recategorize ng Meta ang template, ginagawa nitong null ang custom TTL, kaya basahin ulit ang message_send_ttl_seconds pagkatapos ng anumang pagbabago ng category. Nasa delivery reports mula sa status webhooks ang paghawak sa status kaugnay ng TTL.
Ang hitsura ng tap sa webhook mo
Dumarating ang tap sa quick reply ng template bilang inbound message na may type: "button". Ito ang sample ng Meta mula sa button webhook reference, walang binago maliban sa mga line break (button webhook reference, na-access noong 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"
}
]
}
]
}
Ang context.id ay ang wamid ng template message na tina-tap ng customer. Parehong label ang itinatakda ng sample ng Meta sa payload at text, at inilalarawan ng reference ang dalawa bilang label. Inilalarawan ng Node SDK docs ng Meta ang payload bilang “payload na itinakda ng developer na ibinabalik kapag na-click ang button, bukod sa display text” (button parameter object, na-access noong 2026-11-25). Kaya i-parse muna ang button.payload. Kung wala ito sa format mo, i-match ang context.id sa wamid na itinago mo sa oras ng send. Huwag kailanman mag-match batay sa phone number lang: puwedeng may dalawang appointment ang customer, at isang booking lang ang pinapangalanan ng payload na bk|<id>|confirm.
Tukuyin ang customer gamit ang from_user_id pati ang from. Inaalis ng Meta ang wa_id at from kapag may username ang user at walang available na phone. Saklaw ng paglipat ng contact database sa BSUID ang pagbabagong ito.
Ang reminder service
Tumatakbo ang file na ito nang as-is sa Node 18 o mas bago na may Express 4. Nasa memory ang mga booking para masubukan mo, at bawat table ay katumbas ng database table na itatago mo. Bine-verify nito ang X-Hub-Signature-256, ipinapadala ang dalawang reminder, hinahawakan ang mga tap at pinili sa list, at sinusubaybayan ang delivery laban sa 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}`));
Gumawa ng booking na magsisimula mga 20 oras mula ngayon, at ipapadala agad ng susunod na tick ang reminder_24h. I-set ang startTime sa request na ito sa ganoong oras bago mo ito patakbuhin.
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}'
Ang mga state ng booking ay pending, confirmed, reschedule_requested at cancelled. Hawak ng bawat reminder slot ang sending, isang wamid, skipped, failed o dropped. Ang pangalawang field na iyon ang pumipigil sa scheduler na ipadala nang dalawang beses ang parehong reminder, kaya itago ito sa database row, hindi sa memory.
Sagutin ang Confirm at Reschedule sa loob ng window
Inbound message ang tap, kaya nagbubukas ito ng 24-hour customer service window. Sa loob nito, puwede kang sumagot nang walang template. Para sa Confirm, nagpapadala ang service ng simpleng acknowledgment. Para sa Reschedule, nagpapadala ito ng interactive list ng mga bakanteng oras, at dala ng ID ng bawat row ang booking ID at ang slot. Kung walang bagay na slot, bumabalik ito sa CTA URL button na nagbubukas ng booking page mo.
Hanggang 24 character ang mga row title at 10 row ang kasya sa isang list sa lahat ng seksiyon. Pinuputol ng service ang mga title para magkasya. Nasa interactive buttons at list messages ang buong table ng mga limit.
Bilang service message ang mga free-form reply na ito. Simula 2026-10-01, binibigyan ng Meta ang bawat numero ng 1,000 libreng service message bawat buwan at naniningil pagkatapos noon, gaya ng ipinaliwanag sa mga singil ng Meta sa service message simula Oktubre 2026.
Kapag nasira ang loop
Hindi kailanman naihatid ang reminder
Walang error code na ipinapadala ang Meta kapag dinrop ng TTL ang isang mensahe, kaya ang nawawalang delivered status ang tanging palatandaan. Naghihintay ang service sa TTL kasama ang limang minutong buffer, saka minamarkahang dropped ang reminder. Iyon ang sandali para ipasa ang booking sa isang tao para tumawag, o subukan ang ibang channel na pinayagan ng customer.
Hindi kailanman sumagot ang customer
Walang sinasabi tungkol sa pagdalo ang naihatid na reminder na walang tap. Iniiwan ng service na pending ang booking at ipinapadala pa rin ang 2-hour reminder. Huminto roon. Dagdag na gastos ang pangatlong template para sa parehong appointment at binibigyan nito ang customer ng dahilan para i-block ang numero.
Dalawang beses dumating ang parehong tap
Nire-retry ng Meta ang mga webhook na inaakala nitong pumalya, kaya puwedeng umabot sa iyo ang tap nang higit sa isang beses. Nagde-dedupe muna ang service ayon sa id ng inbound message. Pagkatapos, nahuhuli ng state machine ang pangalawang hiwalay na tap, dahil hindi pinapansin ng booking na confirmed na ang isa pang Confirm. Para sa dedupe na tatagal kahit mag-restart, itago ang bawat inbound wamid sa column na may unique index.
Huling reminder at huling tap
Dina-drop ng TTL ang mga hindi naihatid na reminder, pero dumarating pa rin ang reminder na naihatid nang huli. Tinitingnan ng scheduler na nasa hinaharap pa ang appointment bago ito magpadala, at nilalaktawan ang lead time na lumipas na ang TTL window. Ang tap na dumating pagkatapos ng oras ng simula ay makakatanggap ng maikling reply na lumipas na ang appointment.
Nag-opt out ang customer
Pinapatay ng reply na STOP ang mga reminder para sa bawat booking sa numerong iyon. Itala ang opt-out kung saan binabasa ng booking form mo ang consent, para hindi ito i-on ulit ng susunod na booking.
Tinanggihan o nag-time out ang send sa Meta
Nire-retry ng service nang tatlong beses na may backoff ang mga network error at ang mga 429 at 5xx response, at sumusuko sa iba pang 4xx error. I-log ang mga body na iyon, dahil kadalasang ibig sabihin ng mga ito ay hindi tugma ang template name, language o parameter. May isang panganib na natitira: ang timeout pagkatapos tanggapin ng Meta ang request ay puwedeng magresulta sa pangalawang reminder sa retry. Kung mas mahalaga iyon kaysa sa hindi naipadalang reminder, babaan ang bilang ng pagsubok.
Saan papasok ang Z-API Omni
May “Appointment reminder” model ang custom template docs ng Omni na may Confirm at Reschedule quick replies, gaya ng reminder_24h. Nagsisimula sa variable ang body nito, na ayon sa parehong page ay tinatanggihan ng Meta, kaya magdagdag muna ng salitang gaya ng “Hi”. Ginagawa mo ito gamit ang POST /whatsapp/businesses/{wabaId}/templates, na tumatanggap ng message_send_ttl_seconds, at ipinapadala gamit ang POST /v1/channels/{channelId}/messages. Sa mga Meta Cloud API channel lang gumagana ang mga template. Hindi pa ipinapakita ng docs ang inbound JSON ng tap sa button ng template, kaya subukan muna ang mapping na iyon bago mo ilipat ang handler.
Sa iyo pa rin ang scheduler. Nagbabalik ng 422 na may CHANNEL_DISCONNECTED ang send sa disconnected na channel, at ang mensahe ay “hindi itinatago para ipadala mamaya”. US$29 bawat numero kada buwan ang presyo para sa 1 hanggang 10 numero, US$26 para sa 11 hanggang 50, US$23 para sa 51 hanggang 100 at US$20 kapag lampas sa 100. Ipinapasa ang fees ng Meta sa opisyal na 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" }]
}
]
}
}
]
}
}'
Ang Z-API Omni team