Use cases
WhatsApp booking confirmations and reminders from Calendly
To confirm Calendly bookings on WhatsApp with HelloHop, subscribe a webhook to invitee.created and invitee.canceled, verify the Calendly-Webhook-Signature header, and call the HelloHop send route for each event. Calendly's webhooks include no reminder event and HelloHop has no scheduler, so the reminder is a row your own timer sends the day before.
Facts (as of October 2026, API v1)
- Calendly signs a webhook with the signing key of its subscription. With a personal access token you choose that key when you create the subscription, and the sample requires one. The header is Calendly-Webhook-Signature, in the form t=timestamp,v1=signature, and v1 is the HMAC-SHA256 in hex of the timestamp, a dot and the request body.
- A reschedule sends both events: invitee.canceled with rescheduled true for the old time and invitee.created for the new one. The sample confirms the new time and stays quiet about the old one.
- Calendly's documentation names no delivery id, so the sample dedupes on the event name plus the invitee URI.
- HelloHop sends the message. The booking form, the signature check, the reminder timer and the consent question are yours. HelloHop has no scheduler, labels or CRM.
- The unified POST
/v1/sessions/{channel}/messagesroute accepts an Idempotency-Key of up to 255 characters. Repeating the same key and body within 24 hours returns the first result without another send, with the response header Idempotent-Replayed: true. - A 504 send_unconfirmed, a timeout, a 409 idempotency_uncertain or a 503 with ambiguous true means the message may have gone out. Treat it as possibly delivered and look at the chat before you send it again.
- The free sandbox channel allows 180 messages sent a day and 10 new chats a month, counted in Bangkok time. That is enough to build and test the whole flow before you pay.
- Prices: from $20 USD per number per month, billed annually, with a free sandbox and no per-message fees.
Steps
- Collect a number and a yes. On your Calendly event type add two questions: "WhatsApp number" and "Message me on WhatsApp about this booking". Only an invitee who answers Yes is messaged.
- Subscribe a webhook. Create a webhook subscription with POST /webhook_subscriptions for invitee.created and invitee.canceled, and pass a signing_key of your own. The sample refuses to start with a key shorter than 24 characters.
- Verify and save. Check the signature on the raw body, reject a timestamp older than three minutes, save the event under its key and answer 200.
- Send the confirmation or the cancel notice. Claim the row, send one message with the row key as the Idempotency-Key, and record the result.
- Run the reminder timer. Each minute, re-run the rows that are due. Record every cancellation by invitee URI, and refuse to send anything for a canceled invitee in the same statement that claims the row.
What Calendly runs and what you run
| Step | Who does it |
|---|---|
| Booking page, availability, calendar invite | Calendly |
| Webhook on invitee.created and invitee.canceled, signed with your key | Calendly |
| Check the signature, save the event, decide who may be messaged | Your receiver |
| Confirmation, cancel notice and reminder wording | Your receiver (the wording in the sample is an example) |
| The reminder clock (24 hours before the start) | Your timer. Calendly's webhooks include no reminder event and the send route has no send-at field. |
| Send each message once | HelloHop: the send route with an Idempotency-Key |
The receiver (Node.js)
The sample uses the raw request body for the signature, because a body that is parsed and written out again can differ from the bytes Calendly signed. It reads the number from your "WhatsApp number" answer, and falls back to the invitee's text_reminder_number, the number given for Calendly's own text reminders. Implement the helpers named in the comments on your own database. The confirmation row and the reminder row are saved in one transaction, a cancellation is remembered by invitee URI even if the booking row never arrived, and every claim checks it. The timer re-runs every pending row that is due from its stored payload, and a database error stops one row or one tick, not the process. A booking less than 24 hours away gets only the confirmation. Calendly retries a failed delivery for up to 24 hours, and its documentation says a webhook that is still failing after that is disabled and has to be created again. Webhook subscriptions are created through Calendly's API. Check Calendly's documentation for which plans include them before you build.
// Calendly webhooks: https://developer.calendly.com/api-docs/overview/webhooks/webhook-signatures
// Header: Calendly-Webhook-Signature: t=<unix seconds>,v1=<hex>. v1 is the HMAC-SHA256 (hex) of t + "." + the request body,
// keyed with the webhook signing key you pass when you create the subscription. With a personal access token Calendly makes the key optional;
// this sample requires one. Calendly's own sample rejects a t older than 3 minutes.
// Events: invitee.created and invitee.canceled. A reschedule fires both, and the canceled payload then has rescheduled true:
// https://developer.calendly.com/docs/api-guides/see-how-webhook-payloads-change-when-invitees-reschedule-events
// Invitee fields (uri, name, timezone, text_reminder_number, rescheduled, reschedule_url, questions_and_answers[{ question, answer }],
// scheduled_event.{ name, start_time }): https://developer.calendly.com/openapi/calendly-api.yaml
// Calendly retries a failed delivery for up to 24 hours. A hook that is still failing after that is disabled and has to be created again.
// Its docs name no delivery id, so the key below is the event name plus the invitee uri.
import crypto from 'node:crypto';
import express from 'express';
const API = 'https://api.hellohop.app/v1';
const { CHANNEL_ID, CHANNEL_TOKEN } = process.env;
// One send. Repeating the same key with the same body returns the first result.
async function sendWhatsApp(key, message) {
try {
const res = await fetch(`${API}/sessions/${CHANNEL_ID}/messages`, {
method: 'POST',
headers: {
Authorization: `Bearer ${CHANNEL_TOKEN}`,
'Content-Type': 'application/json',
'Idempotency-Key': key,
},
body: JSON.stringify(message),
signal: AbortSignal.timeout(15000),
});
const data = await res.json().catch(() => ({}));
const result = { status: res.status, code: data.code, ambiguous: data.ambiguous, id: data.id };
if (classify(result) === 'retry') {
// 429 whatsapp_rate_limited carries no Retry-After, so it falls back to 1 second. This helper waits at most 30 seconds;
// a longer Retry-After is not slept through: result.retryAt (Unix ms) says when the row is due, and your sweep or timer retries then.
const h = res.headers.get('Retry-After');
const ms = Math.max(0, (h ? (/^\d+$/.test(h) ? Number(h) * 1000 : Date.parse(h) - Date.now()) : 1000) || 1000);
result.retryAt = Date.now() + ms;
await new Promise((resolve) => setTimeout(resolve, Math.min(30000, ms)));
}
return result;
} catch {
return { status: 0 }; // timeout or lost connection: the message may have gone out
}
}
// One answer per send: sent (server_ack), queued, retry, unknown or failed.
function classify({ status, code, ambiguous }) {
if (status === 200) return 'sent'; // server_ack, not delivered
if (status === 202) return 'queued'; // observe webhooks, do not resend
// Refused before sending: repeat the same key and body later.
const refused = ['upstream_unavailable', 'hopsmart_settings_unavailable', 'operator_unresolved'];
if (status === 429 || (status === 503 && (ambiguous === false || refused.includes(code)))) return 'retry';
// Possibly sent: look at the chat, never resend.
if (status === 0 || status >= 500 || code === 'idempotency_uncertain') return 'unknown';
return 'failed'; // an unlinked channel, idempotency_conflict, a bad request: fix it, do not retry
}
// Your events table: unique key, payload, state, claimed_at (Unix ms), message_id, next_attempt (Unix ms, default 0). Helpers:
// saveEvent(key, payload) insert a pending row once; a repeat changes nothing
// claimSend(key) atomic pending -> claimed, only when next_attempt <= now; sets claimed_at; true for one caller only
// finish(key, expected, state, id, nextAttempt) UPDATE only WHERE state = expected; save the message id
// retry returns to pending and saves nextAttempt (the helper's retryAt); all other outcomes stop automatic sends
// skipPending(key) UPDATE pending -> skipped only; never overwrites a claim or an outcome
// saveBody(key, text) / savedBody(key) keep the exact text, so a retry sends the same body
// Your timer calls recoverAbandonedClaims first, then re-runs pending rows. Never re-send unknown rows.
// db.run(sql, params) executes SQL in your database; claimed_at is Unix milliseconds.
async function recoverAbandonedClaims() {
await db.run("UPDATE events SET state = 'unknown' WHERE state = 'claimed' AND (claimed_at IS NULL OR claimed_at < ?)",
[Date.now() - 5 * 60 * 1000]);
}
const app = express();
// Also yours:
// hasOptedOut(phone) true if this number asked you to stop
// saveEvent(key, payload, dueAt) as above; dueAt (Unix ms) is stored as next_attempt, so claimSend waits until then
// saveBooking(key, payload, reminder, uri) ONE transaction: insert the confirmation row and the reminder row (each unique, a repeat changes
// nothing). Insert nothing and return false if this invitee uri is already canceled
// markCanceled(uri) upsert canceled = 1 for the invitee uri, even when no rows exist yet
// claimSend(key, uri) as above, but when the invitee uri is canceled it marks that row skipped in the SAME statement and returns false, so the timer stops retrying it. The cancel notice passes no uri
// dueKeys(now) keys of every pending row that is due: booking rows and reminder rows (calendly-reminder-...)
// eventPayload(key) the saved payload text
const { CALENDLY_SIGNING_KEY } = process.env;
if (!CALENDLY_SIGNING_KEY || CALENDLY_SIGNING_KEY.length < 24) throw new Error('Set CALENDLY_SIGNING_KEY to the signing key you gave Calendly (24 characters or more) before you start');
function validCalendly(raw, header) {
const parts = Object.fromEntries(String(header ?? '').split(',').map((p) => p.trim().split('=')));
const t = Number(parts.t);
if (typeof parts.v1 !== 'string' || !Number.isFinite(t) || Math.abs(Date.now() / 1000 - t) > 180) return false;
// The body is the raw bytes Calendly sent. Do not parse and re-serialize it before hashing.
const expected = crypto.createHmac('sha256', CALENDLY_SIGNING_KEY).update(`${parts.t}.${raw.toString('utf8')}`).digest('hex');
const got = Buffer.from(parts.v1), want = Buffer.from(expected); // compare bytes: a non-ASCII header must not throw
return got.length === want.length && crypto.timingSafeEqual(got, want);
}
// Your booking page needs two questions: "WhatsApp number" (with country code) and
// "Message me on WhatsApp about this booking" (a yes/no or a checkbox that answers Yes).
// If that answer is missing, text_reminder_number (the invitee's number for Calendly's text reminders) is used instead.
const askedYes = (inv) => inv.questions_and_answers?.some((x) => /whatsapp/i.test(x.question) && /^(yes|true|checked)$/i.test(String(x.answer).trim()));
const phoneOf = (inv) => String(inv.questions_and_answers?.find((x) => /whatsapp number/i.test(x.question))?.answer ?? inv.text_reminder_number ?? '').replace(/\D/g, '');
const when = (inv) => {
const start = inv.scheduled_event.start_time;
try { return new Date(start).toLocaleString('en-US', { timeZone: inv.timezone || 'UTC', dateStyle: 'medium', timeStyle: 'short' }) + ` (${inv.timezone || 'UTC'})`; }
catch { return new Date(start).toISOString().slice(0, 16).replace('T', ' ') + ' UTC'; }
};
// One message from one saved row: claim, keep the exact text, send, record the result. A retry sends the same text.
async function sendRow(key, makeText, to, uri) {
if (!(await claimSend(key, uri))) return; // refused when the booking was canceled
let text = await savedBody(key);
if (!text) { text = makeText(); await saveBody(key, text); }
const result = await sendWhatsApp(key, { type: 'text', to, text });
await finish(key, 'claimed', classify(result), result.id, result.retryAt);
}
async function processBooking(key, event, inv) {
const phone = phoneOf(inv);
// Consent comes from the booking form. Check your own opt-out list right before the claim as well.
if (!phone || !askedYes(inv) || (await hasOptedOut(phone))) return skipPending(key);
const name = String(inv.name ?? 'there').slice(0, 60);
const title = String(inv.scheduled_event.name ?? 'booking').slice(0, 80);
if (event === 'invitee.canceled') {
// A reschedule also sends invitee.created for the new time, which gets the confirmation. Say nothing about the old one.
if (inv.rescheduled === true) return skipPending(key);
return sendRow(key, () => `Hi ${name}, your ${title} on ${when(inv)} is canceled. Reply here if you want another time.`, phone); // no uri: the notice must pass
}
await sendRow(key, () => `Hi ${name}, your ${title} is booked for ${when(inv)}. To change it: ${inv.reschedule_url}`, phone, inv.uri);
}
// The reminder is your timer's job: Calendly's webhooks include no reminder event and the send route has no send-at field.
// It is built here and saved together with the booking row, so a crash after the confirmation cannot lose it.
function reminderFor(inv) {
const phone = phoneOf(inv), dueAt = Date.parse(inv.scheduled_event.start_time) - 24 * 60 * 60 * 1000;
if (!phone || !askedYes(inv) || !(dueAt > Date.now())) return null; // a booking less than 24 hours away gets only the confirmation
const name = String(inv.name ?? 'there').slice(0, 60), title = String(inv.scheduled_event.name ?? 'booking').slice(0, 80);
return { key: `calendly-reminder-${inv.uri}`, dueAt, payload: JSON.stringify({ uri: inv.uri, phone, text: `Hi ${name}, reminder: your ${title} is on ${when(inv)}.` }) };
}
app.post('/webhooks/calendly', express.raw({ type: 'application/json' }), async (req, res) => {
if (!validCalendly(req.body, req.get('Calendly-Webhook-Signature'))) return res.sendStatus(401);
const body = JSON.parse(req.body.toString('utf8'));
if (body.event !== 'invitee.created' && body.event !== 'invitee.canceled') return res.sendStatus(200);
const key = `calendly-${body.event}-${body.payload.uri}`; // a repeated delivery finds the same row
try { // durable first; a database error answers 500 and Calendly delivers it again
if (body.event === 'invitee.canceled') {
await markCanceled(body.payload.uri); // remembered even if the booking row never arrived
await saveEvent(key, req.body.toString('utf8'));
} else if (!(await saveBooking(key, req.body.toString('utf8'), reminderFor(body.payload), body.payload.uri))) {
return res.sendStatus(200); // this booking was already canceled: nothing is saved or sent
}
} catch {
return res.sendStatus(500);
}
res.sendStatus(200);
processBooking(key, body.event, body.payload).catch(console.error); // a failure leaves a row for your timer
});
// Your timer: every minute re-run the pending rows that are due. A database error stops one row or one tick, never the process.
setInterval(async () => {
try {
await recoverAbandonedClaims();
for (const key of await dueKeys(Date.now())) {
try { // a row that cannot be read or parsed stays as it is and is tried again on the next tick
const saved = JSON.parse(await eventPayload(key));
if (!key.startsWith('calendly-reminder-')) { // a booking row left pending (a retry, a crash): run it again from its saved payload
await processBooking(key, saved.event, saved.payload);
} else if (await hasOptedOut(saved.phone)) {
await skipPending(key);
} else {
await sendRow(key, () => saved.text, saved.phone, saved.uri);
}
} catch (err) { console.error(key, err); }
}
} catch (err) { console.error(err); }
}, 60 * 1000);
app.listen(3009);What the handler does with each send result
| Send result | What your handler does |
|---|---|
| 200 server_ack | WhatsApp acknowledged the send. Mark it sent and save id; this is not a delivery receipt. |
| 202 queued | Persisted in the queue, not delivered. A channel that queues its sends (for example while accepted sends drain) answers every text send this way, with id, status queued, position and expires_at. Mark it queued and save id. Observe the result through webhooks without resending. |
| 429, or 503 with ambiguous false or code upstream_unavailable, hopsmart_settings_unavailable or operator_unresolved | Refused before sending. Honor Retry-After, keep the same key and body, and retry later. The Node helper waits at most 30 seconds before returning retry with a retryAt time, and the pages that keep a due time skip the row until then; the other Node timer pages retry on their next run. The Flask, Python reminder and PHP samples return the time to retry instead of waiting; the Sheets helper saves next_attempt_at and skips the row until then. |
| 504 send_unconfirmed, 409 idempotency_uncertain, 503 with ambiguous true, a timeout or a lost response | Possibly delivered. Mark it unknown and look at the chat before any resend. Never force a resend of an uncertain key with a new key. |
| 409 idempotency_conflict | The same key was used for a different message. Fix how you build the key. The first message is unchanged. |
| Any other 409 | Mark it failed. Fix the channel before scheduling another attempt. |
| Other 4xx | The request is wrong and a retry will not fix it. Log it and move on. |
Subscribe to message and message.status webhooks and verify their signatures. The result of a queued send arrives as a message event: match the saved response id to payload.id. message.status reports delivered or read for each id in payload.ids. A send held by HopSmart™ expires 72 hours after acceptance, and the 202 carries expires_at. If no event arrives, read the job with GET /hopsmart/jobs/{id}. Save event ids to deduplicate. Do not resend queued work while waiting for a result.
Using Cal.com instead
Cal.com sends webhooks for BOOKING_CREATED, BOOKING_CANCELLED and BOOKING_RESCHEDULED and signs them with the secret you set on the webhook, in a header named x-cal-signature-256. The payload is shaped differently from Calendly's, with a triggerEvent field and the booking inside payload. Cal.com describes the signature as an HMAC-SHA256 of the payload. Take its exact encoding and the attendee phone field from the Cal.com webhook documentation, and confirm both on a test delivery. Keep the rest of this flow the same: save before answering, one row per booking event, a due row for the reminder, and message only people who said yes.
Who may be messaged
Message only people who answered yes on the booking form, keep each message about their booking, and stop when they ask. The sample checks your opt-out list before every send, and recording a stop request in that list is your code. Consent rules differ by country, so check the ones that apply to you.
Questions
- How do I verify a Calendly webhook?
- Read the t and v1 values from the Calendly-Webhook-Signature header, compute the HMAC-SHA256 in hex of t, a dot and the raw body with your signing key, and compare it with v1 in constant time. Reject a t more than three minutes old, the tolerance in the Calendly example.
- What happens when someone reschedules?
- Calendly sends invitee.canceled with rescheduled true for the old booking and invitee.created for the new one. Confirm the new one and skip the cancel notice.
- Can HelloHop send the reminder for me?
- No. HelloHop has no scheduler and the send route has no send-at field. Save a due row when the booking arrives and let your own timer send it.
- How do I avoid a double confirmation?
- Build the key from the event name and the invitee URI, save the row before you answer 200, claim it before you send, and use the same key as the Idempotency-Key.
- Where does the phone number come from?
- The sample reads the answer to the booking question you add, and falls back to the invitee text_reminder_number. Ask for the number with its country code.
Free sandbox, forever. Upgrade when you're ready.
Start freeKeep going
HelloHop is an independent WhatsApp API for developers: send and receive messages, automate groups and communities, and get signed webhooks. Not affiliated with WhatsApp or Meta. You link your own number.