Use cases
HubSpot follow-up over WhatsApp
A HubSpot webhook tells your receiver that a contact was created or a deal moved to a stage. Your receiver checks HubSpot's signature, finds the contact's phone and consent, sends one WhatsApp message through HelloHop, and logs a note on the contact. Send only to contacts who agreed to WhatsApp.
Facts (as of October 2026, API v1)
- HubSpot webhooks arrive as an array of up to 100 events in one request. Each has objectId and a type field, which the HubSpot guide calls subscriptionType in its field table and eventType in its examples, so the sample reads both. Property changes add propertyName and propertyValue.
- HubSpot does not guarantee order, and it does not guarantee one notification per event. eventId is not guaranteed unique, so the sample keys on the contact or on the deal and stage.
- HubSpot retries a failed delivery up to 10 times over 24 hours. A response slower than 5 seconds counts as a failure.
- HubSpot signs webhooks-API CRM events with v1: a SHA-256 hex digest of your app client secret plus the raw body, in X-HubSpot-Signature. Newer v3 signing sends X-HubSpot-Signature-v3, a base64 HMAC-SHA256 of the method, the full URL, the raw body and the X-HubSpot-Request-Timestamp value, and you reject timestamps older than 5 minutes. The sample checks v3 when that header is present, otherwise v1. Source: HubSpot validating-requests page, developers.hubspot.com/docs/api/webhooks/validating-requests.
- A note is created with POST /crm/v3/objects/notes and linked to a contact with association type id 202.
- 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
- Create the opt-in property. Add a contact property, for example whatsapp_opt_in, that holds true only after the person agreed to WhatsApp messages. Fill it from your own form.
- Subscribe to the events. In your HubSpot app subscribe to contact.creation and deal.propertyChange for the deal stage, and point the target at your HTTPS receiver.
- Verify the signature and save. Check the HubSpot signature (v3 or v1) and, for v3, the timestamp, save one row per contact or per deal and stage, then answer 200 inside 5 seconds.
- Send once. Read the contact, check the phone and consent, then call the send API with an Idempotency-Key built from that row.
- Log back. After the send is recorded, create a note on the contact with the message text.
The job: follow up the moment HubSpot knows
A form fill creates a contact, and a sales rep moves a deal to a stage such as proposal sent. Both are good moments for a short WhatsApp message to a contact who agreed to receive one. HubSpot can send a webhook for each. Your receiver sits between HubSpot and HelloHop, so the consent check, the wording and the note stay under your control.
The receiver (Node.js)
The sample sends one message per new contact and one per deal that reaches the stage in PROPOSAL_STAGE_ID. The message wording is an example: write your own. Implement the database helpers and a timer that runs recovery first. The note is a second write after the message is recorded. A note has no idempotency key, so if that write fails the message is still recorded in your table: retry the note from there and check HubSpot before you post it again. The deal lookup uses the associations path from the HubSpot associations guide, which carries the version date 2026-09. Check the guide for the current date when you deploy.
// HubSpot webhooks (payload, retries): https://developers.hubspot.com/docs/api-reference/legacy/webhooks/guide
// Signatures v1 and v3: https://developers.hubspot.com/docs/apps/legacy-apps/authentication/validating-requests
// Contacts: https://developers.hubspot.com/docs/api-reference/crm-contacts-v3/guide
// Notes: https://developers.hubspot.com/docs/api-reference/crm-notes-v3/guide
// Association read, GET /crm/objects/2026-09/{fromObjectType}/{objectId}/associations/{toObjectType}, results carry toObjectId: https://developers.hubspot.com/docs/api-reference/crm-associations-v4/guide
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();
const { HUBSPOT_CLIENT_SECRET, HUBSPOT_TOKEN, PUBLIC_ORIGIN, PROPOSAL_STAGE_ID } = process.env;
// Webhooks-API CRM events carry X-HubSpot-Signature (v1); newer signing sends X-HubSpot-Signature-v3. Check whichever is present.
const same = (a, b) => a.length === b.length && crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b));
function validHubSpot(req, raw) {
const v3 = req.get('X-HubSpot-Signature-v3');
if (v3) {
const ts = req.get('X-HubSpot-Request-Timestamp');
if (!ts || Math.abs(Date.now() - Number(ts)) > 5 * 60 * 1000) return false; // older than 5 minutes: reject
// Decode only HubSpot's listed escapes, once. Leave %20, %25, %26 and %3D encoded.
const uri = (PUBLIC_ORIGIN + req.originalUrl).replace(/%(3A|2F|3F|40|21|24|27|28|29|2A|2C|3B)/gi, decodeURIComponent);
const source = req.method + uri + raw.toString('utf8') + ts;
return same(v3, crypto.createHmac('sha256', HUBSPOT_CLIENT_SECRET).update(source).digest('base64'));
}
const v1 = req.get('X-HubSpot-Signature') || ''; // v1: SHA-256 of client secret + raw body, hex
return same(v1, crypto.createHash('sha256').update(HUBSPOT_CLIENT_SECRET + raw.toString('utf8')).digest('hex'));
}
async function hs(path, init = {}) {
const res = await fetch(`https://api.hubapi.com${path}`, {
...init,
headers: { Authorization: `Bearer ${HUBSPOT_TOKEN}`, 'Content-Type': 'application/json' },
signal: AbortSignal.timeout(10000),
});
if (!res.ok) throw new Error(`hubspot ${res.status}`); // the row stays pending for the timer
return res.json();
}
// eventId is not guaranteed unique, so key on what must happen once: one message per contact, one per deal and stage.
function eventKey(e) {
const type = e.subscriptionType || e.eventType;
if (type === 'contact.creation') return `hs-contact-${e.objectId}`;
if (type === 'deal.propertyChange' && e.propertyName === 'dealstage' && e.propertyValue === PROPOSAL_STAGE_ID) {
return `hs-deal-${e.objectId}-${e.propertyValue}`;
}
return null;
}
async function processEvent(key, e) {
const isDeal = key.startsWith('hs-deal-');
const contactId = isDeal
? (await hs(`/crm/objects/2026-09/deals/${e.objectId}/associations/contacts`)).results?.[0]?.toObjectId
: e.objectId;
if (!contactId) return skipPending(key);
// whatsapp_opt_in is a custom contact property you create; it holds "true" only after the person agreed.
const { properties: p } = await hs(`/crm/v3/objects/contacts/${contactId}?properties=firstname,phone,whatsapp_opt_in`);
if (!p.phone?.startsWith('+') || p.whatsapp_opt_in !== 'true') return skipPending(key);
if (!(await claimSend(key))) return;
let text = await savedBody(key);
if (!text) {
const name = p.firstname || 'there';
text = isDeal ? `Hi ${name}, your proposal is ready. Reply here with any questions.`
: `Hi ${name}, thanks for getting in touch. How can we help? Reply here and a person will answer.`;
await saveBody(key, text);
}
const result = await sendWhatsApp(key, { type: 'text', to: p.phone.replace(/\D/g, ''), text });
const outcome = classify(result);
await finish(key, 'claimed', outcome, result.id);
if (outcome === 'sent' || outcome === 'queued') {
// Second write, after the message is recorded. A note has no idempotency key: check before you re-post one.
await hs('/crm/v3/objects/notes', {
method: 'POST',
body: JSON.stringify({
properties: { hs_timestamp: new Date().toISOString(), hs_note_body: `WhatsApp message: ${text}` },
associations: [{ to: { id: contactId }, types: [{ associationCategory: 'HUBSPOT_DEFINED', associationTypeId: 202 }] }],
}),
}).catch(console.error);
}
}
app.post('/webhooks/hubspot', express.raw({ type: 'application/json' }), async (req, res) => {
if (!validHubSpot(req, req.body)) return res.sendStatus(401);
const work = JSON.parse(req.body.toString('utf8')).map((e) => [eventKey(e), e]).filter(([key]) => key);
try {
for (const [key, e] of work) await saveEvent(key, JSON.stringify(e)); // durable first, then answer inside 5 seconds
} catch {
return res.sendStatus(500); // HubSpot retries the batch
}
res.sendStatus(200);
for (const [key, e] of work) processEvent(key, e).catch(console.error);
});
app.listen(3004);The send call by hand
API=https://api.hellohop.app/v1
curl -s -X POST "https://api.hellohop.app/v1/sessions/$CHANNEL_ID/messages" \
-H "Authorization: Bearer $CHANNEL_TOKEN" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: hs-contact-CONTACT_ID" \
-d '{"type":"text","to":"66XXXXXXXXX","text":"Hi Anna, thanks for getting in touch. How can we help? Reply here and a person will answer."}'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.
Consent and the phone number
Send only when the contact record shows the person agreed to WhatsApp and the phone starts with a plus and a country code. If either is missing the sample skips the row and sends nothing. HubSpot stores the phone in whatever format it was typed, so normalize it at capture.
Questions
- Does HubSpot send its webhooks to HelloHop?
- No. HubSpot posts to a receiver you own. The receiver verifies HubSpot's signature and calls the HelloHop API.
- Why not key on eventId?
- HubSpot says eventId is not guaranteed unique and that an event can be delivered more than once. The sample keys on the contact, or on the deal and stage, which is what must happen once.
- How do I log the message back to the contact?
- Create a note with POST /crm/v3/objects/notes and associate it to the contact with association type id 202. Do it after the send is recorded.
- What if the send outcome is unknown?
- Mark the row unknown, look at the chat, and never resend it automatically. A timeout, a 409 idempotency_uncertain and a 503 with ambiguous true all mean the message may have gone out.
- Can I try it without paying?
- Yes. Every account has one free sandbox channel that allows 180 messages sent a day.
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.