A booking appointment template is a Meta utility template type that confirms an appointment in one message. Its fixed “View details” button opens a sheet with the booking’s details. You create it with a booking_status button and send start_datetime, a location or phone, and an optional booking_management_url suffix at send time. Use it for the confirmation right after booking. It can’t carry quick replies, so a reminder that needs Confirm or Reschedule stays a custom template.
The custom reminder is in WhatsApp appointment reminders with Confirm and Reschedule. This post covers the template’s fields, Meta’s own examples and where they disagree, and a sender that closes the loop through your manage page.
What the template holds
Every rule below comes from Meta’s page (booking appointment templates, accessed 2026-11-27).
| Part | Required | Limit and rule |
|---|---|---|
| Header | Yes | “Only text format is supported”, 60 characters |
| Body | Yes | 1,024 characters, named parameters; examples “Required if body text contains named parameters” |
| Footer | No | 60 characters |
| Button | Yes (it defines the type) | One booking_status button, labeled “View details”, which “cannot be modified” |
booking_url, booking_management_url |
No | 2,000 characters each; one parameter, which “must be at the end of the URL” |
| Notes | No | 1,024 characters; “Can contain up to 3 embedded URLs” |
Parameter names must be a “Unique lowercase string with underscores”. “Only one booking status button is allowed, and it cannot be combined with other button types.” The button “opens a bottom sheet displaying the full appointment information”, and the notes are “displayed in the booking details bottom sheet.” Notes accept named parameters, bold, italics, strikethrough, code, \n, bulleted lists and links. A link may carry “a single parameterized suffix at the end”.
The template name can run to 512 characters. The access token must be a “System token” or “business token”. WhatsApp Cloud API access tokens explains how to get one.
At send time, start_datetime is required, in ISO 8601 with a time zone. end_datetime, location, phone_number and email are optional. location is the “Physical address where the appointment takes place”, up to 100 characters, and email takes up to 254. One rule applies to all of them: “You must provide at least one of location, booking_url, or phone_number at send time.”
Create the template: Meta’s examples
These are Meta’s blocks as published, in page order. The page shows v27.0 in its URLs. We changed that to v26.0, the version this blog uses, and left everything else alone. The <!-- --> comments are Meta’s, which is why the syntax blocks don’t run as pasted.
The request syntax:
curl 'https://graph.facebook.com/<API_VERSION>/<WHATSAPP_BUSINESS_ACCOUNT_ID>/message_templates' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
-d '
{
"name": "<TEMPLATE_NAME>",
"language": "<TEMPLATE_LANGUAGE>",
"category": "utility",
"parameter_format": "named",
"components": [
{
"type": "header",
"format": "text",
"text": "<HEADER_TEXT>"
},
{
"type": "body",
"text": "<BODY_TEXT>",
<!-- Optional. Required if BODY_TEXT contains named parameters. -->
"example": {
"body_text_named_params": [
{
"param_name": "<BODY_PARAM_NAME>",
"example": "<BODY_PARAM_EXAMPLE>"
}
]
}
},
<!-- Optional -->
{
"type": "footer",
"text": "<FOOTER_TEXT>"
},
{
"type": "buttons",
"buttons": [
{
"type": "booking_status",
<!-- Optional -->
"booking_url": {
"url": "<BOOKING_URL>",
"example": [
"<BOOKING_URL_SUFFIX_EXAMPLE>"
]
},
<!-- Optional -->
"booking_management_url": {
"url": "<BOOKING_MANAGEMENT_URL>",
"example": [
"<BOOKING_MANAGEMENT_URL_SUFFIX_EXAMPLE>"
]
},
<!-- Optional -->
"notes": {
"text": "<NOTES_TEXT>",
"example": {
"notes_named_params": [
{
"param_name": "<NOTES_PARAM_NAME>",
"example": "<NOTES_PARAM_EXAMPLE>"
}
]
}
}
}
]
}
]
}'
The simplest template Meta shows:
curl 'https://graph.facebook.com/v26.0/102290129340398/message_templates' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer EAAJB...' \
-d '
{
"name": "dentist_appointment",
"language": "en_US",
"category": "utility",
"parameter_format": "named",
"components": [
{
"type": "header",
"format": "text",
"text": "Dentist appointment"
},
{
"type": "body",
"text": "Hello! Thanks for booking your appointment."
},
{
"type": "buttons",
"buttons": [
{
"type": "booking_status"
}
]
}
]
}'
The example with every feature. Read the shell note in the next section before you paste it.
curl 'https://graph.facebook.com/v26.0/102290129340398/message_templates' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer EAAJB...' \
-d '
{
"name": "succulent_walking_tour",
"language": "en_US",
"category": "utility",
"parameter_format": "named",
"components": [
{
"type": "header",
"format": "text",
"text": "Native succulent walking tour"
},
{
"type": "body",
"text": "Hi {{guest_name}}! Your walking tour is confirmed. A deposit of ${{deposit_amount}} has been received. See you in San Diego!",
"example": {
"body_text_named_params": [
{
"param_name": "guest_name",
"example": "Alex"
},
{
"param_name": "deposit_amount",
"example": "35"
}
]
}
},
{
"type": "footer",
"text": "San Diego Succulent Tours"
},
{
"type": "buttons",
"buttons": [
{
"type": "booking_status",
"booking_url": {
"url": "https://zoom.us/j/{{1}}",
"example": [
"98432167055"
]
},
"booking_management_url": {
"url": "https://sdsucculenttours.com/manage/{{1}}",
"example": [
"tour-20260315-0412"
]
},
"notes": {
"text": "Hi {{guest_name}}! We're excited to take you through Torrey Pines and Balboa Park to explore San Diego's native succulents, including Dudleya, coastal agave, and more.\n\n*What to bring:* comfortable walking shoes, sunscreen, and a water bottle.\n\nConfirmation No.: {{confirmation_number}}\nZoom passcode for the virtual option: {{zoom_passcode}}\n\nCan't make it? Please cancel at least 48 hours in advance. [Cancellation policy](https://sdsucculenttours.com/terms/{{terms_suffix}})",
"example": {
"notes_named_params": [
{
"param_name": "guest_name",
"example": "Alex"
},
{
"param_name": "confirmation_number",
"example": "SDT-84302"
},
{
"param_name": "zoom_passcode",
"example": "547291"
},
{
"param_name": "terms_suffix",
"example": "2026-spring"
}
]
}
}
}
]
}
]
}'
The response. A new template comes back as PENDING.
{
"id": "546151681022936",
"status": "PENDING",
"category": "UTILITY"
}
Send it: Meta’s examples
The send syntax. The booking details travel in a button component with sub_type: "booking_status" and an action parameter.
curl 'https://graph.facebook.com/<API_VERSION>/<WHATSAPP_BUSINESS_PHONE_NUMBER_ID>/messages' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <ACCESS_TOKEN>' \
-d '
{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "<WHATSAPP_USER_PHONE_NUMBER>",
"type": "template",
"template": {
"name": "<TEMPLATE_NAME>",
"language": {
"policy": "deterministic",
"code": "<TEMPLATE_LANGUAGE_CODE>"
},
"components": [
{
"type": "header"
},
{
"type": "body",
<!-- Optional. Required if the template body contains named parameters. -->
"parameters": [
{
"type": "text",
"parameter_name": "<BODY_PARAM_NAME>",
"text": "<BODY_PARAM_VALUE>"
}
]
},
{
"type": "button",
"sub_type": "booking_status",
"index": 0,
"parameters": [
{
"type": "action",
"action": {
"booking_status": {
"start_datetime": "<START_DATETIME>",
<!-- Optional -->
"end_datetime": "<END_DATETIME>",
<!-- Optional. At least one of location, booking_url, or phone_number is required. -->
"location": "<LOCATION>",
<!-- Optional. At least one of location, booking_url, or phone_number is required. -->
"phone_number": "<PHONE_NUMBER>",
<!-- Optional -->
"email": "<EMAIL>",
<!-- Optional. Only include if the template was created with a booking URL. -->
"booking_url": "<BOOKING_URL_SUFFIX>",
<!-- Optional. Only include if the template was created with a booking management URL. -->
"booking_management_url": "<BOOKING_MANAGEMENT_URL_SUFFIX>",
<!-- Optional. Only include if the template was created with notes that contain named parameters. -->
"notes": {
"parameters": [
{
"param_name": "<NOTES_PARAM_NAME>",
"text": "<NOTES_PARAM_VALUE>"
}
]
}
}
}
}
]
}
]
}
}'
The simple send. Its date is in the past, as the next section explains.
curl 'https://graph.facebook.com/v26.0/106540352242922/messages' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer EAAJB...' \
-d '
{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "+16505551234",
"type": "template",
"template": {
"name": "dentist_appointment",
"language": {
"policy": "deterministic",
"code": "en_US"
},
"components": [
{
"type": "header"
},
{
"type": "body"
},
{
"type": "button",
"sub_type": "booking_status",
"index": 0,
"parameters": [
{
"type": "action",
"action": {
"booking_status": {
"start_datetime": "2025-07-10T09:30:00-04:00",
"location": "456 Elm Street, Suite 2B",
"phone_number": "+15550198765"
}
}
}
]
}
]
}
}'
The send with every feature:
curl 'https://graph.facebook.com/v26.0/106540352242922/messages' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer EAAJB...' \
-d '
{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "+16505551234",
"type": "template",
"template": {
"name": "succulent_walking_tour",
"language": {
"policy": "deterministic",
"code": "en_US"
},
"components": [
{
"type": "header"
},
{
"type": "body",
"parameters": [
{
"type": "text",
"parameter_name": "guest_name",
"text": "Pablo"
},
{
"type": "text",
"parameter_name": "deposit_amount",
"text": "35"
}
]
},
{
"type": "button",
"sub_type": "booking_status",
"index": 0,
"parameters": [
{
"type": "action",
"action": {
"booking_status": {
"start_datetime": "2026-03-15T09:00:00-07:00",
"end_datetime": "2026-03-15T11:30:00-07:00",
"location": "Torrey Pines State Natural Reserve, San Diego, CA",
"phone_number": "+15550051310",
"email": "[email protected]",
"booking_url": "98432167055",
"booking_management_url": "tour-20260315-0412",
"notes": {
"parameters": [
{
"parameter_name": "guest_name",
"text": "Pablo"
},
{
"parameter_name": "confirmation_number",
"text": "SDT-84302"
},
{
"parameter_name": "zoom_passcode",
"text": "547291"
},
{
"parameter_name": "terms_suffix",
"text": "2026-spring"
}
]
}
}
}
}
]
}
]
}
}'
The send response carries the message ID you’ll match against status webhooks and replies:
{
"messaging_product": "whatsapp",
"contacts": [
{
"input": "+16505551234",
"wa_id": "16505551234"
}
],
"messages": [
{
"id": "wamid.HBgLMTY0NjcwNDM1OTUVAgARGBI1RjQyNUE3NEYxMzAzMzQ5MkEA"
}
]
}
Where Meta’s examples disagree
Copying the blocks above as-is runs into several inconsistencies on Meta’s page.
| What | Where on Meta’s page | What to do |
|---|---|---|
Notes key at send: param_name or parameter_name |
The send syntax uses param_name; the full send example uses parameter_name |
Send parameter_name, as the full example and every body parameter do, and test. At creation, param_name is consistent |
type on notes parameters |
Body parameters carry "type": "text"; notes parameters have no type in either block |
Leave it out, as both blocks do |
{{1}} in URLs |
The template is parameter_format: "named", but URLs use positional {{1}} |
Keep {{1}} in URLs, as the page shows |
| API version | Every example uses v27.0 |
Use the version your app targets; this blog uses v26.0 |
| Casing | Lowercase "utility", "named", "header", "buttons" |
Meta’s own create response ("category": "UTILITY") uses uppercase; pick one casing and stay with it |
to format |
"+16505551234" with a plus |
Meta’s webhook examples use digits only; the sender below stores digits and sends them without a plus |
| Dates | The simple send uses 2025-07-10, the full one 2026-03-15 |
Both are in the past today; always build start_datetime from the real booking |
| Shell quoting | The full creation example’s notes contain “We’re”, “San Diego’s” and “Can’t” inside a single-quoted -d '...' |
In a POSIX shell, those apostrophes end the string early, and bash -n reports a syntax error. Save the JSON to a file and send it with -d @template.json |
The shell problem is our reading of the block, not a note on Meta’s page. The send blocks have no apostrophes and run once you replace the token and IDs.
Why it passes as utility
The template sits under Meta’s utility templates, and its create call sets "category": "utility". The content still has to pass Meta’s test: “Must be non-promotional” and “specific to or requested by the user (clearly related to their order, account, services, or transactions)” (template categorization, accessed 2026-11-27). A confirmation of a booking the customer just made meets both. A discount line in the body or the notes turns it into marketing.
The Template Library has no ready-made booking type to clone. Its industries are E_COMMERCE and FINANCIAL_SERVICES (Template Library, accessed 2026-11-25). For clinics, keep the header, body and notes to the time, the place and the professional’s name. The sheet shows whatever you put in the notes, so nothing clinical goes there either.
The loop without a tap webhook
Meta’s page documents no webhook for a “View details” tap. You can’t tell whether the customer opened the sheet. So the reply step of the loop comes from your own systems.
- Your booking system saves a booking and asks the sender to confirm it.
- The sender sends the template with a management suffix that maps to that booking.
- The customer opens “View details” and follows
booking_management_urlto your manage page. - Your manage page changes the booking and calls the sender, which sends the new time.
- Free text the customer types in the chat arrives as a normal
messageswebhook and becomes a note on the booking.
Meta’s page describes no way to edit a message already sent. A change goes out as a new message, and Meta doesn’t document what an earlier sheet shows afterward. If the manage page is Calendly, the reschedule_url ID may fit as the suffix, which Calendly webhooks to WhatsApp treats as an inference to test.
Booking template or a custom template
| Need | Booking appointment template | Custom utility template |
|---|---|---|
| Buttons | One booking_status, fixed label “View details” |
Up to 10 quick replies, plus URL and phone buttons |
| A reply your webhook can read | None documented for “View details” | A button message with your payload |
| Date and time | start_datetime and end_datetime at send |
Formatted by you into the body |
| Manage link | booking_management_url |
A URL button with one suffix |
| Fits | The confirmation right after booking | The reminder that needs Confirm, Cancel or Reschedule |
Most bookings use both. The booking template confirms, and a custom template reminds a day ahead, as in the reminder pillar and Cal.com webhooks to WhatsApp reminders. If a slot frees up, the waitlist refill post offers it to the next customer.
Your own template and the sender
This template has a text header, a body with two named parameters, a manage link and one notes parameter. Replace example.com with the host of your manage page. Named parameters and their examples are explained in WhatsApp template variables.
curl "https://graph.facebook.com/v26.0/$WABA_ID/message_templates" \
-H "Authorization: Bearer $WA_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "appointment_booked",
"language": "en_US",
"category": "utility",
"parameter_format": "named",
"components": [
{ "type": "header", "format": "text", "text": "Appointment confirmed" },
{
"type": "body",
"text": "Hi {{guest_name}}, your {{service}} is booked. Tap View details for the time, the place and a link to change it.",
"example": {
"body_text_named_params": [
{ "param_name": "guest_name", "example": "Marina" },
{ "param_name": "service", "example": "haircut" }
]
}
},
{
"type": "buttons",
"buttons": [
{
"type": "booking_status",
"booking_management_url": {
"url": "https://example.com/manage/{{1}}",
"example": ["k3J9xQ2pLwV8"]
},
"notes": {
"text": "Confirmation No.: {{confirmation_number}}\nReply to this chat if you have a question.",
"example": {
"notes_named_params": [
{ "param_name": "confirmation_number", "example": "BK-1042" }
]
}
}
}
]
}
]
}'
The sender runs on Python 3.9 or later with the standard library only. It keeps bookings in memory so you can try it. NOTES_PARAM_KEY lets you switch between parameter_name and param_name while you test Meta’s inconsistency.
# booking_template_service.py: send Meta's booking appointment template and record replies.
# Python 3.9+ standard library only. Run: python3 booking_template_service.py
import hashlib
import hmac
import json
import os
import re
import secrets
import threading
import time
import urllib.error
import urllib.parse
import urllib.request
from datetime import datetime, timezone
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from zoneinfo import ZoneInfo
def env(name, default=None):
value = os.environ.get(name, default)
if not value:
raise SystemExit(f"Missing environment variable {name}")
return value
WA_TOKEN = env("WA_TOKEN")
PHONE_NUMBER_ID = env("PHONE_NUMBER_ID")
APP_SECRET = env("APP_SECRET")
VERIFY_TOKEN = env("VERIFY_TOKEN")
INTERNAL_TOKEN = env("INTERNAL_TOKEN")
TEMPLATE_NAME = env("TEMPLATE_NAME", "appointment_booked")
CHANGED_TEMPLATE = env("CHANGED_TEMPLATE", TEMPLATE_NAME) # a second template if you want other wording
NOTES_PARAM_KEY = env("NOTES_PARAM_KEY", "parameter_name") # Meta's syntax block shows param_name
PORT = int(env("PORT", "3000"))
GRAPH_URL = f"https://graph.facebook.com/v26.0/{PHONE_NUMBER_ID}/messages"
lock = threading.Lock()
bookings = {} # booking id -> booking
by_wamid = {} # confirmation wamid -> booking id
seen_inbound = set() # inbound wamids already handled
def to_datetime(value, tz_name):
dt = datetime.fromisoformat(str(value).replace("Z", "+00:00"))
return dt if dt.tzinfo else dt.replace(tzinfo=ZoneInfo(tz_name))
def check_times(start, end):
if start <= datetime.now(timezone.utc):
raise ValueError("start is in the past")
if end and end <= start:
raise ValueError("end must be after start")
def build_booking(data):
booking_id = str(data.get("booking_id", ""))
phone = re.sub(r"\D", "", str(data.get("phone", "")))
if not re.fullmatch(r"[\w-]{1,64}", booking_id):
raise ValueError("booking_id must be 1-64 letters, digits, _ or -")
if not re.fullmatch(r"[1-9]\d{7,14}", phone):
raise ValueError("phone must be E.164 with the country code")
if data.get("whatsapp_opt_in") is not True:
raise ValueError("no WhatsApp opt-in recorded for this booking")
tz_name = str(data.get("time_zone", "UTC"))
start = to_datetime(data["start"], tz_name)
end = to_datetime(data["end"], tz_name) if data.get("end") else None
check_times(start, end)
location = str(data.get("location") or "")
contact_phone = str(data.get("contact_phone") or "")
if len(location) > 100:
raise ValueError("location is limited to 100 characters")
if not location and not contact_phone:
raise ValueError("Meta needs location, booking_url or phone_number at send time")
return {
"id": booking_id,
"phone": phone,
"guest_name": str(data.get("guest_name") or "there"),
"service": str(data.get("service") or "appointment"),
"start": start,
"end": end,
"time_zone": tz_name,
"location": location,
"contact_phone": contact_phone,
"confirmation_number": str(data.get("confirmation_number") or booking_id),
"manage_token": secrets.token_urlsafe(12), # your manage page maps this token to the booking
"opt_in": True,
"state": "new",
"customer_notes": [],
}
def booking_message(b, template):
status = {"start_datetime": b["start"].isoformat(timespec="seconds")}
if b["end"]:
status["end_datetime"] = b["end"].isoformat(timespec="seconds")
if b["location"]:
status["location"] = b["location"]
if b["contact_phone"]:
status["phone_number"] = b["contact_phone"]
status["booking_management_url"] = b["manage_token"]
status["notes"] = {"parameters": [{NOTES_PARAM_KEY: "confirmation_number", "text": b["confirmation_number"]}]}
return {
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": b["phone"],
"type": "template",
"template": {
"name": template,
"language": {"policy": "deterministic", "code": "en_US"},
"components": [
{"type": "header"},
{
"type": "body",
"parameters": [
{"type": "text", "parameter_name": "guest_name", "text": b["guest_name"]},
{"type": "text", "parameter_name": "service", "text": b["service"]},
],
},
{
"type": "button",
"sub_type": "booking_status",
"index": 0,
"parameters": [{"type": "action", "action": {"booking_status": status}}],
},
],
},
}
def send_whatsapp(payload, attempts=4):
data = json.dumps(payload).encode("utf-8")
last = ""
for attempt in range(1, attempts + 1):
request = urllib.request.Request(GRAPH_URL, data=data, method="POST", headers={
"Authorization": f"Bearer {WA_TOKEN}",
"Content-Type": "application/json",
})
try:
with urllib.request.urlopen(request, timeout=15) as response:
return json.load(response)["messages"][0]["id"]
except urllib.error.HTTPError as err:
detail = err.read().decode("utf-8", "replace")
if err.code != 429 and err.code < 500:
raise RuntimeError(f"Meta returned {err.code}: {detail}") # template or parameter mismatch
last = f"HTTP {err.code}: {detail}"
except (urllib.error.URLError, OSError) as err:
last = str(err)
if attempt < attempts:
time.sleep(2 ** attempt)
raise RuntimeError(f"send failed after {attempts} attempts: {last}")
def send_text(to, body):
try:
send_whatsapp({"messaging_product": "whatsapp", "to": to, "type": "text", "text": {"body": body}})
except RuntimeError as err:
print("reply failed", to, err)
def write_back(booking, text):
# Replace with a note or comment on the booking in your own system.
booking["customer_notes"].append({"at": datetime.now(timezone.utc).isoformat(), "text": text})
print("note added to booking", booking["id"], repr(text))
def find_booking(msg):
context_id = (msg.get("context") or {}).get("id")
with lock:
if context_id in by_wamid:
return bookings.get(by_wamid[context_id])
mine = [b for b in bookings.values() if b["phone"] == msg.get("from") and b["state"] == "sent"]
return max(mine, key=lambda b: b["start"]) if mine else None
def handle_message(msg):
with lock:
if msg.get("id") in seen_inbound:
return # Meta retried this webhook
seen_inbound.add(msg.get("id"))
sender = msg.get("from")
if msg.get("type") != "text" or not sender:
return
text = (msg.get("text") or {}).get("body", "").strip()
if re.fullmatch(r"(?i)stop", text):
with lock:
for b in bookings.values():
if b["phone"] == sender:
b["opt_in"] = False
send_text(sender, "You will not get booking messages here anymore.")
return
booking = find_booking(msg)
if booking is None:
print("message with no booking", msg.get("id"))
return
write_back(booking, text)
send_text(sender, "Thanks, we added your message to your booking. To change the time, use the link in your confirmation.")
class Handler(BaseHTTPRequestHandler):
def reply(self, code, obj):
body = json.dumps(obj, default=str).encode("utf-8")
self.send_response(code)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def do_GET(self):
url = urllib.parse.urlparse(self.path)
query = urllib.parse.parse_qs(url.query)
if url.path == "/webhook" and query.get("hub.mode") == ["subscribe"] \
and query.get("hub.verify_token") == [VERIFY_TOKEN]:
challenge = query.get("hub.challenge", [""])[0].encode("utf-8")
self.send_response(200)
self.send_header("Content-Type", "text/plain")
self.send_header("Content-Length", str(len(challenge)))
self.end_headers()
self.wfile.write(challenge)
return
self.reply(403, {"error": "verification failed"})
def do_POST(self):
path = urllib.parse.urlparse(self.path).path
raw = self.rfile.read(int(self.headers.get("Content-Length") or 0))
if path == "/webhook":
return self.webhook(raw)
auth = self.headers.get("Authorization", "").encode("utf-8")
if not hmac.compare_digest(auth, f"Bearer {INTERNAL_TOKEN}".encode("utf-8")):
return self.reply(401, {"error": "unauthorized"})
try:
data = json.loads(raw or b"{}")
except ValueError:
return self.reply(400, {"error": "invalid JSON"})
if path == "/bookings":
return self.confirm(data)
if path == "/bookings/changed":
return self.changed(data)
return self.reply(404, {"error": "not found"})
def confirm(self, data):
try:
booking = build_booking(data)
except (KeyError, ValueError, TypeError) as err:
return self.reply(400, {"error": str(err)})
with lock:
existing = bookings.get(booking["id"])
if existing and existing["state"] != "send_failed":
return self.reply(200, {"booking_id": existing["id"], "manage_token": existing["manage_token"]})
bookings[booking["id"]] = booking
return self.send_booking(booking, TEMPLATE_NAME, 201)
def changed(self, data):
# Your manage page calls this after the customer moves the booking.
with lock:
booking = bookings.get(str(data.get("booking_id", "")))
if booking is None:
return self.reply(404, {"error": "unknown booking"})
if not booking["opt_in"]:
return self.reply(409, {"error": "customer opted out of WhatsApp"})
try:
tz_name = str(data.get("time_zone", booking["time_zone"]))
start = to_datetime(data["start"], tz_name)
end = to_datetime(data["end"], tz_name) if data.get("end") else None
check_times(start, end)
except (KeyError, ValueError, TypeError) as err:
return self.reply(400, {"error": str(err)})
with lock:
booking.update(start=start, end=end, time_zone=tz_name)
return self.send_booking(booking, CHANGED_TEMPLATE, 200)
def send_booking(self, booking, template, code):
try:
wamid = send_whatsapp(booking_message(booking, template))
except RuntimeError as err:
booking["state"] = "send_failed"
return self.reply(502, {"error": str(err)})
with lock:
booking["state"] = "sent"
by_wamid[wamid] = booking["id"]
return self.reply(code, {"booking_id": booking["id"], "manage_token": booking["manage_token"], "wamid": wamid})
def webhook(self, raw):
expected = "sha256=" + hmac.new(APP_SECRET.encode("utf-8"), raw, hashlib.sha256).hexdigest()
received = self.headers.get("X-Hub-Signature-256", "").encode("utf-8")
if not hmac.compare_digest(received, expected.encode("utf-8")):
return self.reply(401, {"error": "bad signature"})
self.reply(200, {"ok": True}) # answer first, work after
try:
body = json.loads(raw)
except ValueError:
return
for entry in body.get("entry", []):
for change in entry.get("changes", []):
if change.get("field") != "messages":
continue
value = change.get("value", {})
for status in value.get("statuses", []):
if status.get("status") == "failed":
print("send failed", by_wamid.get(status.get("id")), json.dumps(status.get("errors")))
for msg in value.get("messages", []):
handle_message(msg)
if __name__ == "__main__":
print(f"listening on {PORT}")
ThreadingHTTPServer(("", PORT), Handler).serve_forever()
Confirm a booking from your system with one call. The response returns the manage_token that your manage page uses to find the booking.
curl -X POST http://localhost:3000/bookings \
-H "Authorization: Bearer $INTERNAL_TOKEN" \
-H "Content-Type: application/json" \
-d '{"booking_id":"bk-1042","phone":"+16505551234","guest_name":"Marina","service":"haircut","start":"2026-12-03T09:30","end":"2026-12-03T10:15","time_zone":"America/New_York","location":"456 Elm Street, Suite 2B","confirmation_number":"BK-1042","whatsapp_opt_in":true}'
The manage token is random, because anyone holding the link can open your manage page. Make that page check the token against the booking, and expire it after the appointment.
When the loop breaks
Meta rejects the send
A 4xx from Meta usually means a name, language or parameter mismatch. The sender doesn’t retry those and returns 502 with Meta’s body. If the error points at the notes, switch NOTES_PARAM_KEY to param_name and send again. A missing location and phone_number together is caught before the call, because Meta requires one of them.
The date is wrong or in the past
The sender refuses a start in the past and an end before the start. A local time without an offset is read in the booking’s time_zone, so 2026-12-03T09:30 in America/New_York goes out as -05:00.
The same webhook arrives twice
Meta retries webhooks it thinks failed. The sender skips any inbound message ID it has seen, so a retried reply becomes one note. Move seen_inbound to a table with a unique key before production.
The customer opts out or goes quiet
A reply of STOP clears consent on every booking for that number, and /bookings/changed then refuses to send. No reply means nothing, because the template asks for none. The reminder template is where you ask for Confirm.
A send times out after Meta accepted it
The sender retries network errors, 429 and 5xx three times with backoff. A timeout after acceptance can produce a second confirmation. If that matters more than a missed one, lower the attempt count. Status handling is in WhatsApp message status webhooks.
Where Z-API Omni fits
Omni’s docs don’t cover this template. Its create-template button types are QUICK_REPLY, URL, PHONE_NUMBER, COPY_CODE, OTP, FLOW, CATALOG, MPM, SPM, PAYMENT_REQUEST, ORDER_DETAILS and VOICE_CALL, with no booking_status. Its send schema takes parameters with only type and text, with no action. So the docs show no way to send the booking appointment template, and this post shows no request for it.
What the docs do cover is the custom utility template with QUICK_REPLY and URL buttons. You create it with POST /whatsapp/businesses/{wabaId}/templates, which accepts message_send_ttl_seconds, and a URL button takes one variable at the end. Templates work on Meta Cloud API channels, where Meta’s fees are passed through.
Z-API Omni team