Use cases
WhatsApp lead follow-up and sales pipeline
To follow up leads on WhatsApp with HelloHop, your code sends a welcome message, reads each reply from the signed message webhook and sends timed follow-ups to leads who stay quiet. You keep the stage in your own CRM or Google Sheet and run your own timer. HelloHop has no contact labels, CRM, follow-up sequences, scheduler or pipeline view.
Facts (as of October 2026, API v1)
- HelloHop does not store lead stages, labels or notes, and it has no scheduler. The stage column and the timer are yours. HelloHop sends a message when your code calls the send route.
- An inbound reply arrives as a message webhook signed with the receiver secret. Save its event id first, so a repeated delivery changes nothing.
- The sample keeps stages in a small SQLite table as a stand-in for your CRM or Google Sheet. Its timer sends at most two follow-ups, 24 hours apart, to a lead who has not replied.
- 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
- Capture the inquiry. Post each new lead from your lead ad, web form or automation to your receiver. Include a phone number that starts with + and the country code, and a yes or no answer to your WhatsApp consent question.
- Send the first message. Save the lead as New lead, then send one welcome message with the lead id in the Idempotency-Key.
- Qualify the first reply. Verify the message webhook, save its event id, and let your qualifier (a rule or a model call) decide. A qualified lead gets your calendar link and moves to Qualified.
- Run your own follow-up timer. Every minute, find leads that have not replied and are past their due time. Queue the next message under its own key, up to two per lead, and move the lead to Contacted.
- Book the demo and update the stage. Your calendar or CRM moves the lead to Demo booked, and a person moves it to Quote sent. A reply of STOP marks the lead opted out, and the timer queues nothing more for that lead.
The job: answer fast, follow up twice at most, stop on a reply
The flow below sends one welcome message when a lead comes in and answers the first reply. A lead who stays quiet gets up to two follow-ups, about 24 hours apart: each is due at least 24 hours after the last one was queued, and only once that one has been accepted. A message held for a retry can land later than planned, so treat the spacing as a minimum, not a promise. The first reply is saved before the webhook is acknowledged, so the timer still answers it after a restart. The timer queues nothing more once the lead replies or sends STOP, or once your calendar or CRM marks the demo as booked, and a follow-up still waiting to be sent is canceled at send time.
What you run and what HelloHop runs
| Step | Who does it |
|---|---|
| Capture the inquiry (Meta lead ad, web form or automation) | Your lead-ad receiver, form tool or automation, posting to your own route. The sample does not create a lead from a first inbound message. |
| Qualify with an AI reply | Your receiver and your model call. HelloHop sends the reply text you give it. |
| Tag the stage: New lead, Qualified, Contacted, Quote sent, Demo booked | Your own CRM or Google Sheet. The sample uses a SQLite table. |
| Timed follow-ups | Your timer: cron, a loop, n8n's Wait node or your CRM. HelloHop sends when your timer calls the send route. |
| Book the demo | Your own calendar link. A booking webhook or a person sets Demo booked. |
| Send each message once, receive each reply | HelloHop: the send route with an Idempotency-Key, and the signed message webhook. |
The receiver (Node.js)
The sample needs Express and Node.js 22.13 or later for the built-in node:sqlite module, which Node 22 still marks as experimental. It saves every lead and every outgoing message in SQLite before it sends, so a restart, a repeated webhook delivery or a form posted twice does not send a second copy. It messages only leads posted with whatsapp_ok true and a phone number that starts with +. A reply is matched to a lead by the phone number in chat_jid. A message from a number that is not in the table is ignored. A chat that arrives as a LID with no resolved number is not matched, and a STOP from it gets a 500 so the delivery is retried instead of lost; the LID guide shows which fields to store. Replace the table with writes to your CRM or sheet, and the qualify function with a model call as on the AI chatbot page. The message wording is an example.
// Lead follow-up pipeline. Needs Node.js 22.13 or later (node:sqlite) and: npm install express
import crypto from 'node:crypto';
import { DatabaseSync } from 'node:sqlite';
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
}
const { WEBHOOK_SECRET } = process.env;
if (!WEBHOOK_SECRET || WEBHOOK_SECRET.length < 24) throw new Error('Set WEBHOOK_SECRET to the receiver secret (24 characters or more) before you start');
function validSignature(raw, header) {
const expected = crypto.createHmac('sha256', WEBHOOK_SECRET).update(raw).digest('hex');
return typeof header === 'string' && header.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(header), Buffer.from(expected));
}
const { LEAD_TOKEN, CALENDAR_LINK } = process.env;
if (!LEAD_TOKEN || LEAD_TOKEN.length < 24) throw new Error('Set LEAD_TOKEN (24 characters or more) before you start');
if (!CALENDAR_LINK) throw new Error('Set CALENDAR_LINK to your own booking page before you start');
// A stand-in for your CRM or Google Sheet: one row per lead with a stage column. The API stores no stages.
const STAGES = ['new_lead', 'qualified', 'contacted', 'quote_sent', 'demo_booked', 'opted_out'];
const FOLLOW_UP_AFTER_MS = 24 * 60 * 60 * 1000;
const MAX_FOLLOW_UPS = 2;
const { DB_FILE } = process.env;
const db = new DatabaseSync(DB_FILE || 'leads.db');
db.exec(`
CREATE TABLE IF NOT EXISTS leads (id INTEGER PRIMARY KEY, phone TEXT UNIQUE, name TEXT, source TEXT,
stage TEXT NOT NULL DEFAULT 'new_lead', replied INTEGER NOT NULL DEFAULT 0,
follow_ups INTEGER NOT NULL DEFAULT 0, follow_up_at INTEGER NOT NULL);
CREATE TABLE IF NOT EXISTS sends (key TEXT PRIMARY KEY, lead_id INTEGER, to_phone TEXT, body TEXT,
state TEXT NOT NULL DEFAULT 'pending', next_attempt INTEGER NOT NULL DEFAULT 0, claimed_at INTEGER, message_id TEXT);
CREATE TABLE IF NOT EXISTS seen (event_id TEXT PRIMARY KEY);
CREATE TABLE IF NOT EXISTS replies (lead_id INTEGER PRIMARY KEY, text TEXT, done INTEGER NOT NULL DEFAULT 0);
`);
const one = (sql, ...args) => db.prepare(sql).get(...args);
const run = (sql, ...args) => db.prepare(sql).run(...args);
const inTransaction = (fn) => {
db.exec('BEGIN');
try { const out = fn(); db.exec('COMMIT'); return out; } catch (err) { db.exec('ROLLBACK'); throw err; }
};
// Quote sent and Demo booked are not set by this code. Your calendar's booking webhook, your CRM or a person calls this.
function setStage(leadId, stage) {
if (!STAGES.includes(stage)) throw new Error(`unknown stage ${stage}`);
run("UPDATE leads SET stage = ? WHERE id = ? AND stage != 'opted_out'", stage, leadId);
}
// Save the message text first, then send it once under its key. A retry sends the saved text.
function queueSend(key, leadId, to, body) {
run('INSERT OR IGNORE INTO sends (key, lead_id, to_phone, body) VALUES (?, ?, ?, ?)', key, leadId, to, body);
}
// Checked again at send time: a STOP, a reply or a booked demo after the message was queued cancels it. A claim that already won is in flight.
const SEND_OK = "EXISTS (SELECT 1 FROM leads l WHERE l.id = sends.lead_id AND l.stage != 'opted_out' AND (sends.key NOT LIKE '%-followup-%' OR (l.replied = 0 AND l.stage IN ('new_lead', 'contacted'))))";
async function dispatch(key) {
const now = Date.now();
run(`UPDATE sends SET state = 'skipped' WHERE key = ? AND state = 'pending' AND NOT ${SEND_OK}`, key);
const claim = run(`UPDATE sends SET state = 'claimed', claimed_at = ? WHERE key = ? AND state = 'pending' AND next_attempt <= ? AND ${SEND_OK}`, now, key, now);
if (claim.changes !== 1) return; // sent already, skipped, not due yet, or another run owns it
const row = one('SELECT * FROM sends WHERE key = ?', key);
const result = await sendWhatsApp(key, { type: 'text', to: row.to_phone, text: row.body });
const outcome = classify(result);
if (outcome === 'retry') {
run("UPDATE sends SET state = 'pending', next_attempt = ? WHERE key = ? AND state = 'claimed'", result.retryAt ?? Date.now() + 1000, key);
} else {
run("UPDATE sends SET state = ?, message_id = ? WHERE key = ? AND state = 'claimed'", outcome, result.id ?? null, key);
}
}
// Your timer. The send route has no scheduler: this loop is the schedule.
async function sweep() {
const now = Date.now();
// A claim older than 5 minutes may have gone out: mark it unknown and never resend it.
run("UPDATE sends SET state = 'unknown' WHERE state = 'claimed' AND (claimed_at IS NULL OR claimed_at < ?)", now - 5 * 60 * 1000);
const due = db.prepare("SELECT * FROM leads WHERE replied = 0 AND stage IN ('new_lead', 'contacted') AND follow_ups < ? AND follow_up_at <= ? AND EXISTS (SELECT 1 FROM sends WHERE key = 'lead-' || leads.id || '-' || CASE leads.follow_ups WHEN 0 THEN 'welcome' ELSE 'followup-' || leads.follow_ups END AND state IN ('sent', 'queued'))").all(MAX_FOLLOW_UPS, now);
for (const lead of due) {
inTransaction(() => {
const n = lead.follow_ups + 1;
const moved = run("UPDATE leads SET follow_ups = ?, follow_up_at = ?, stage = 'contacted' WHERE id = ? AND follow_ups = ? AND replied = 0 AND stage IN ('new_lead', 'contacted')", n, now + FOLLOW_UP_AFTER_MS, lead.id, lead.follow_ups);
if (moved.changes === 1) {
queueSend(`lead-${lead.id}-followup-${n}`, lead.id, lead.phone,
`Hi ${lead.name}, checking in on your inquiry. Reply here with any questions, or pick a time: ${CALENDAR_LINK}`);
}
});
}
// Replies saved but not yet answered, for example after a restart.
for (const r of db.prepare('SELECT l.id, l.phone, r.text FROM replies r JOIN leads l ON l.id = r.lead_id WHERE r.done = 0').all()) await answerFirstReply({ id: r.id, phone: r.phone }, r.text);
for (const r of db.prepare("SELECT key FROM sends WHERE state = 'pending' AND next_attempt <= ?").all(now)) await dispatch(r.key);
}
const HANDOFF_REPLY = 'Thanks for your reply. A person will pick this up and answer here soon.';
// Stand-in qualifier. Replace the body with the model call from the chatbot page; keep the return shape.
async function qualify(text) {
if (/price|quote|cost|how much|demo|book|buy/i.test(text || '')) {
return { qualified: true, reply: `Thanks. Here is our calendar if you want a demo: ${CALENDAR_LINK}` };
}
return { qualified: false, reply: HANDOFF_REPLY };
}
const app = express();
function validLeadToken(header) {
const hash = (v) => crypto.createHash('sha256').update(String(v ?? '')).digest();
return crypto.timingSafeEqual(hash(header), hash(LEAD_TOKEN));
}
// Step 1, capture: your lead-ad receiver, web form or automation posts { name, phone, whatsapp_ok, source } here.
app.post('/lead', express.json({ limit: '10kb' }), (req, res) => {
if (!validLeadToken(req.get('X-Lead-Token'))) return res.sendStatus(401);
const { name, phone, whatsapp_ok, source } = req.body ?? {};
const digits = typeof phone === 'string' && phone.startsWith('+') ? phone.replace(/\D/g, '') : ''; // no leading +, no message
if (!digits || whatsapp_ok !== true) return res.json({ accepted: false }); // nothing saved or sent here: without consent or a + number, keep the lead in your CRM and do not message it
const first = String(name || 'there').slice(0, 60);
let key;
try {
key = inTransaction(() => {
run('INSERT OR IGNORE INTO leads (phone, name, source, follow_up_at) VALUES (?, ?, ?, ?)', digits, first, String(source || 'form').slice(0, 40), Date.now() + FOLLOW_UP_AFTER_MS);
const lead = one('SELECT * FROM leads WHERE phone = ?', digits);
const k = `lead-${lead.id}-welcome`; // one welcome per lead, however often the form is posted
queueSend(k, lead.id, digits, `Hi ${first}, thanks for your inquiry. What are you looking for, and roughly when? A person will follow up here. Reply STOP to opt out.`);
return k;
});
} catch {
return res.sendStatus(500); // a 500 asks the sender to post it again
}
res.json({ accepted: true });
dispatch(key).catch(console.error); // the timer also picks up anything left pending
});
// Step 2, qualify: the lead's first reply.
function acceptReply(event) {
const m = event.payload;
return inTransaction(() => {
if (run('INSERT OR IGNORE INTO seen (event_id) VALUES (?)', event.id).changes !== 1) return null; // repeated delivery
const isPhone = /@s\.whatsapp\.net$/.test(m.chat_jid || '');
const isStop = m.type === 'text' && /^\s*stop\s*$/i.test(m.text || '');
// A STOP from a LID with no resolved number cannot be matched to a lead: fail before acknowledging, so the delivery is retried and the failure is visible.
if (!isPhone && isStop) throw new Error('Resolve this sender before acknowledging STOP');
const lead = isPhone ? one('SELECT * FROM leads WHERE phone = ?', m.chat_jid.split('@')[0]) : null; // other messages from such a chat are not matched here
if (!lead || lead.stage === 'opted_out') return null;
if (isStop) { setStage(lead.id, 'opted_out'); return null; }
// The first reply stops new follow-ups. Only the first reply gets an automatic answer; a person takes the rest.
if (run('UPDATE leads SET replied = 1 WHERE id = ? AND replied = 0', lead.id).changes !== 1) return null;
run('INSERT OR IGNORE INTO replies (lead_id, text) VALUES (?, ?)', lead.id, String(m.text || '').slice(0, 1000)); // saved with the seen row, so a restart cannot lose the answer
return lead;
});
}
async function answerFirstReply(lead, text) { // lead needs id and phone
const { qualified, reply } = await qualify(text).catch(() => ({ qualified: false, reply: HANDOFF_REPLY })); // a failed model call hands over to a person
const key = `lead-${lead.id}-reply`;
inTransaction(() => {
if (qualified) run("UPDATE leads SET stage = 'qualified' WHERE id = ? AND stage IN ('new_lead', 'contacted')", lead.id);
queueSend(key, lead.id, lead.phone, reply.slice(0, 1000));
run('UPDATE replies SET done = 1 WHERE lead_id = ?', lead.id);
});
await dispatch(key);
}
app.post('/webhooks/whatsapp', express.raw({ type: 'application/json' }), (req, res) => {
if (!validSignature(req.body, req.get('X-HelloHop-Signature'))) return res.sendStatus(401);
const event = JSON.parse(req.body.toString('utf8'));
const m = event.payload;
if (event.type !== 'message' || m.from_me || m.is_group) return res.sendStatus(200);
let lead;
try {
lead = acceptReply(event);
} catch {
return res.sendStatus(500); // the webhook is delivered again
}
res.sendStatus(200);
if (lead) answerFirstReply(lead, m.text).catch(console.error);
});
setInterval(() => sweep().catch(console.error), 60 * 1000);
sweep().catch(console.error);
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 n8n instead of code
The same flow fits n8n. Start a workflow from your lead source, send with the HelloHop community node or the HTTP Request node, hold the execution with a Wait node, then check whether the lead replied before the next send. A second workflow on the HelloHop Trigger node, which starts on message events, records the reply in your sheet or CRM. The Wait node is part of n8n, and the stage updates happen in your own sheet or CRM. Put the lead id and the step in the Idempotency Key option of the HelloHop node, or in the Idempotency-Key header of an HTTP Request node, so a rerun does not send twice.
Who may be messaged
Message only people who asked to be contacted on WhatsApp, keep each message about their inquiry, and stop when they ask. The sample trusts the whatsapp_ok value your form posts, so recording that consent is your job. Consent rules differ by country, so check the ones that apply to you.
Questions
- Does HelloHop have a CRM or contact labels?
- No. HelloHop sends and receives WhatsApp messages. A saved contact holds a name, not a stage or a label. Keep stages, labels and notes in your own CRM or Google Sheet.
- Can HelloHop schedule my follow-up messages?
- No. The send route has no send-at field, and HelloHop has no follow-up sequences. Schedule follow-ups with your own timer, such as cron, a loop, n8n's Wait node or your CRM, and send each one under its own Idempotency-Key.
- How do I stop follow-ups when a lead replies?
- Mark the lead as replied when the message webhook arrives, and have the timer skip any lead that has replied, booked or opted out.
- How do I avoid messaging a lead twice?
- Before you send, save the outgoing message under a key built from the lead id and the step, such as lead-12-followup-1. Send it with that key as the Idempotency-Key, and reuse the same key and body on a retry.
- Can an AI qualify the lead?
- Yes. Call your model from the receiver, keep its answer short, and hand over to a person when the call fails. The AI chatbot use case shows the call.
Free sandbox, forever. Upgrade when you're ready.
Start freeKeep going
- Schedule follow-up messages
- Meta lead ads follow-up
- AI chatbot with ChatGPT or Claude
- Google Sheets automation
- HubSpot CRM follow-up
- Use HelloHop from n8n
- LID vs phone number in webhooks
- Send a text with Node.js
- Retries and unknown outcomes
- Verify a webhook signature
- Sending messages reference
- Error codes and ambiguous outcomes
- API docs
- Pricing
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.