WhatsApp Business API for pending booking confirmation
The scenario sends the client a personalised WhatsApp template when a booking awaits confirmation.
Use case overview
The scenario sends the client a personalised WhatsApp template when a booking awaits confirmation. Two quick-reply buttons let the client confirm or cancel the booking; the webhook routes the choice to your scheduling system.
Template example
Hello, {{1}}! Please confirm your {{2}} booking on {{3}} at {{4}}:
[Confirm booking]
Quick-reply button labels are fixed in the Meta template — only body variables are sent via the API.
Variables and purpose
{{1}}— customer name{{2}}— service or appointment type{{3}}— booking date{{4}}— booking time
Filled-in example
Hello, Maria! Please confirm your haircut booking on June 18, 2026 at 2:00 PM:
[Confirm booking]
When to use it
- online booking widgets
- salons and clinics
- integrators
Business value
- Scheduling system creates or updates a booking that awaits client confirmation
- System captures the pending booking event and recipient phone
- Personalised template message is prepared with four body variables and two quick-reply buttons
- Client receives the WhatsApp message and taps confirm or cancel
- Webhook delivers the structured response so the booking is confirmed or released
Workflow
- The scheduling system creates a pending booking and fires a confirmation request event.
- The system resolves the client phone number and booking fields.
- A personalised template message is built with four body variables and two quick-reply buttons.
- The client receives the WhatsApp message and taps confirm or cancel.
- The webhook confirms or releases the booking slot.
- Delivery progress is reported asynchronously — typically
sent, thendelivered(or failed/undelivered). - Your system receives status via webhook (
hooks[]) or pollsGET …/hookInfo?messageId=<id>and handles failures if needed.
Technical implementation
Prerequisites
- A 1MSG account with WhatsApp Business API connected and an approved message template with two quick-reply buttons.
- Customer phone number in international format (without
+and spaces). - Pending booking data: customer name, service, date, and time.
- HTTPS webhook endpoint to receive quick-reply button events.
Code examples
Node.js
#!/usr/bin/env node
// === Configuration (replace "___" placeholders) ===
const API_BASE_URL = "https://api.1msg.io"; // production 1MSG API base URL
const CHANNEL_ID = "___"; // channel ID from 1MSG dashboard
const API_TOKEN = "___"; // channel JWT token (Bearer)
const TEMPLATE_NAME = "___"; // approved template name
const TEMPLATE_NAMESPACE = "___"; // template namespace (422 without it)
const TEMPLATE_LANGUAGE = "___"; // template language code, e.g. "en"
// === Test data ===
const TEST_PHONE = "___"; // client phone in international format
const TEST_CUSTOMERNAME = "___"; // {{1}} customer name
const TEST_SERVICE = "___"; // {{2}} service name
const TEST_BOOKINGDATE = "___"; // {{3}} booking date
const TEST_BOOKINGTIME = "___"; // {{4}} booking time
function normalizePhone(phone) {
return String(phone).replace(/\D/g, "");
}
function assertConfigured(values) {
for (const [key, value] of Object.entries(values)) {
if (value === "___" || value === "" || value === undefined || value === null) {
throw new Error(`Missing configuration value: ${key}`);
}
}
}
async function sendTemplateMessage({ phone, customerName, service, bookingDate, bookingTime }) {
assertConfigured({
CHANNEL_ID,
API_TOKEN,
TEMPLATE_NAME,
TEMPLATE_NAMESPACE,
TEMPLATE_LANGUAGE,
phone,
customerName,
service,
bookingDate,
bookingTime,
});
const url = `${API_BASE_URL}/${CHANNEL_ID}/sendTemplate`;
// params carries body and button blocks (dynamic buttons).
const requestBody = {
phone: normalizePhone(phone),
template: TEMPLATE_NAME,
namespace: TEMPLATE_NAMESPACE,
language: {
policy: "deterministic",
code: TEMPLATE_LANGUAGE,
},
params: [
{
type: "body",
parameters: [
{ type: "text", text: String(customerName) }, // {{1}} customer name
{ type: "text", text: String(service) }, // {{2}} service name
{ type: "text", text: String(bookingDate) }, // {{3}} booking date
{ type: "text", text: String(bookingTime) }, // {{4}} booking time
],
},
],
};
const res = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${API_TOKEN}`,
},
body: JSON.stringify(requestBody),
});
const raw = await res.text();
let data;
try {
data = JSON.parse(raw);
} catch {
data = null;
}
if (!res.ok || !data || data.sent !== true) {
console.error("Send failed. API response:");
console.error(raw);
process.exit(1);
}
console.log("Message sent to client.");
console.log("API response:", raw);
return data;
}
function handleIncomingMessage(message) {
const text = (message && (message.text || message.body || "")).trim();
// Meta quick_reply label (from template.txt) → route key (code_contract.ref) "confirm_booking"
if (text === "Подтвердить запись") {
console.log("Reply received: confirm_booking");
return { status: "confirm_booking" };
}
// Meta quick_reply label (from template.txt) → route key (code_contract.ref) "cancel_booking"
if (text === "Отменить запись") {
console.log("Reply received: cancel_booking");
return { status: "cancel_booking" };
}
console.log("Free-text reply — handle separately.");
return { status: "other" };
}
if (require.main === module) {
sendTemplateMessage({
phone: TEST_PHONE,
customerName: TEST_CUSTOMERNAME,
service: TEST_SERVICE,
bookingDate: TEST_BOOKINGDATE,
bookingTime: TEST_BOOKINGTIME,
}).catch((err) => {
console.error("Execution failed:", err.message);
process.exit(1);
});
}
module.exports = { sendTemplateMessage, handleIncomingMessage };
Immediate API response (synchronous)
- HTTP 2xx and JSON
"sent": truemean 1MSG accepted the message for sending — not that it already reached the customer's phone. - Save the `id` field from the response (value looks like
wamid.…). Use it to correlate delivery callbacks or polling. - The response may also include
messageanddescription— informational only.
Delivery status (asynchronous)
- Register a webhook (
POST …/webhook) so 1MSG POSTs delivery updates to your HTTPS endpoint in a separate `hooks[]` payload (sent,delivered,read, or failed/undelivered when applicable). - Optionally poll:
GET {base}/{channel}/hookInfo?messageId=<id from sendTemplate>. - In practice, delivery often completes within a few seconds — but that is not guaranteed by the API contract.
Common errors
- Invalid or non-normalized phone number
- Unapproved or missing template name / namespace
- No customer opt-in for WhatsApp business messages
- Template variable count mismatch (422 from API)
- Delivery failure — check status webhook and retry policy
FAQ
- Do I need an approved template? Yes — cold-start WhatsApp messages require a Meta-approved template.
- Can I customize the message text? Body variables are dynamic; fixed text and button labels are set in the Meta template.
- How do I check delivery?
sent: trueonly confirms acceptance. Track delivery via webhookhooks[]orGET …/hookInfo?messageId=<id>. - What if the message is not delivered? Log the failed/undelivered hook, verify opt-in and template status, then retry or fall back to another channel.
- Can I connect this to my CRM or backend? Yes — trigger the API call from your platform webhook or event handler.
CTA
Ready to use pending booking confirmation? Connect your 1MSG channel and run the code examples above.
Related
Build WhatsApp automation in minutes
Use 1MSG to automate this workflow and try it with our free demo.
