Mepụta WhatsApp Flow site na API, lelee ya ma bipụta ya, zipu ya onye ahịa n'ime chat ma ọ bụ site na bọtịnụ template, ma nata ubi ejuputara na webhook gị.
N'ime nduzi a, ị na-ewu fọm ịrịọ ọnụ ahịa nke na-emeghe n'ime WhatsApp. Onye ahịa na-enye aha ya, na-ahọrọ ọrụ ọ chọrọ wee họrọ ụbọchị ọ chọrọ, sistemu gị na-enweta azịza dị ka ubi dị ọcha kama ederede chat n'efu.
Ihe onye ahịa hụrụ: ozi n'ime chat nwere bọtịnụ Rịọ ọnụ ahịa. Bọtịnụ ahụ na-emeghe ihuenyo fọm n'ime WhatsApp, nwere ubi aha, ndepụta ọrụ na ihe ịhọrọ ụbọchị. Ha na-pịa Zipu arịrịọ, fọm ahụ na-emechi, obere azịza "Ezipuru" na-apụta n'ime chat, ma ọ dịghị anya ozi ekele gị na-abịa.
Ihe ị na-ahụ: flow yana ọnọdụ ya n'ime API, njikọ nlele iji nwalee fọm ahụ n'ime browser, nhalụ message.status maka ozi nwere fọm ahụ, na otu nhalụ message.received nwere azịza onye ahịa n'ime data.flow.response. Azịza ahụ na-egosikwa na Inbox na Activity Log.
POST /flows. Ọ na-amalite dị ka draft, azịza ahụ na-edepụta njehie nyocha WhatsApp.PUT /flows/{id}/json, nwalee fọm ahụ site na njikọ nlele ya, wee bipụta ya site na POST /flows/{id}/publish.POST /messages yana ozi flow mmekọrịta. N'èzí oge ahụ: template e kwadoro nwere bọtịnụ Flow.message.received nwere type interactive, interactive.type nfm_reply na ihe flow nwere ubi ndị ahụ na flow_token ị zipuru.Flows bụ nke WhatsApp Business Account dum. Flow ị mepụtara, gbanwe, bipụta ma ọ bụ kwụsị, ndị nọmba niile n'otu WhatsApp Business Account ahụ na-ekerịta ya, na flow.status_changed na-aga nọmba niile. Jiri aha na-egosi ihe flow ahụ bụ maka ya.
plan_not_allowed; ọrụ akwụsịrị na-azaghachi 403 service_not_live. Lee Mmalite.| Ikike | Ihe ọ bụ maka nduzi a |
|---|---|
templates:manage | Mepụta flow (POST /flows), dezie Flow JSON ya (PUT /flows/{id}/json), bipụta ya (POST /flows/{id}/publish), mepụta njikọ nlele ọhụrụ, kwụsị ma ọ bụ hichapụ ya. Yana mepụta template nwere bọtịnụ Flow (POST /templates) |
messages:read | Gụọ flows (GET /flows, GET /flows/{id}, GET /flows/{id}/json) na njikọ nlele (GET /flows/{id}/preview) |
messages:send | Zipu fọm na ozi ekele (POST /messages) |
webhooks:manage | Debanye webhook nke na-anata azịza (POST /webhooks). Ịnwere ike ịtinye ya na ibe API key n'okpuru Webhooks |
Igodo Default (emere tupu igodo nwee ikike) enweghị templates:manage. Mepụta igodo nwere ikike ahụ, ma ọ bụ Full access (*). GET /v1/YOUR_NUMBER/me na-egosi ikike igodo ị nwere.
Ihe igodo sandbox nwere ike ime na ihe ọ na-enweghị ike ime ebe a. Igodo sandbox n'ọnụ nọmba gị (igodo nwere akara sandbox, emere na ibe API key) nwere ike ịgụ flows (GET /flows, GET /flows/{id}, GET /flows/{id}/json, GET /flows/{id}/preview), na POST /messages nwere ozi flow na-eme nyocha niile ma ezipughị ihe ọ bụla: azịza nwere "sandbox": true, id ozi malite na wamid.SANDBOX., nhalụ message.status ka na-abịa. Ime, gbanwe, bipụta, kwụsị na hichapụ flows na-eweta 403 sandbox_key, n'ihi na ha na-agbanwe WhatsApp Business Account gị. Instant sandbox maka nọmba demo 12025550100 enweghị oku flow ọ bụla (403 not_in_instant_sandbox). Ya mere: wuo wee bipụta flow ahụ site na igodo a na-ejikọta, nwalee ya site na njikọ nlele, wee nwalee koodu gị na-ezipu site na igodo sandbox. Nkọwa: Sandbox.
Oku ọ bụla na-aga https://api.app2email.com/v1/YOUR_NUMBER yana Authorization: Bearer YOUR_API_KEY. YOUR_NUMBER bụ nọmba WhatsApp ị na-ezipu site na ya: koodu mba mbụ, naanị ọnụọgụ.
Flow bụ ndepụta ihuenyo. Nke a nwere otu ihuenyo, QUOTE, nwere isi okwu, obere ederede, ubi atọ na bọtịnụ. Ọrụ complete nke bọtịnụ na-emechi fọm ahụ wee zipu payload ya azụ gị: ${form.name} bụ uru nke ubi a kpọrọ name, na ndị ọzọ. Aha ị họrọ n'ime payload bụ aha ubi ị ga-anata.
Chekwaa ya dị ka quote-request.json:
{
"version": "7.2",
"screens": [
{
"id": "QUOTE",
"title": "Request a quote",
"terminal": true,
"success": true,
"data": {},
"layout": {
"type": "SingleColumnLayout",
"children": [
{ "type": "TextHeading", "text": "Tell us what you need" },
{ "type": "TextBody", "text": "We answer every request within one working day." },
{ "type": "TextInput", "name": "name", "label": "Your name", "input-type": "text", "required": true },
{
"type": "Dropdown",
"name": "service",
"label": "Service",
"required": true,
"data-source": [
{ "id": "window_cleaning", "title": "Window cleaning" },
{ "id": "gutter_cleaning", "title": "Gutter cleaning" },
{ "id": "pressure_washing", "title": "Pressure washing" }
]
},
{ "type": "DatePicker", "name": "preferred_date", "label": "Preferred date", "required": true },
{
"type": "Footer",
"label": "Send request",
"on-click-action": {
"name": "complete",
"payload": {
"name": "${form.name}",
"service": "${form.service}",
"preferred_date": "${form.preferred_date}"
}
}
}
]
}
}
]
}Akụrụngwa (TextHeading, TextInput, Dropdown, DatePicker, Footer ...) na njirimara ha bụ nke WhatsApp, ọ bụghị nke app2email: app2email na-enye Flow JSON na WhatsApp dị ka ọ dị, WhatsApp ya onwe ya na-enyocha ya. Lee akwụkwọ Meta maka WhatsApp Flows maka akụrụngwa niile. Fọm a achọghị sava nke gị mgbe onye ahịa na-ejuputa ya: ihe niile dị na JSON, azịza ndị ahụ na-alọta n'otu ozi.
POST /flows (ikike templates:manage) na-anara name (nke ime, onye ahịa adịghị ahụ ya, ruo mkpụrụedemede 200), opekata otu n'ime categories (SIGN_UP, SIGN_IN, APPOINTMENT_BOOKING, LEAD_GENERATION, CONTACT_US, CUSTOMER_SUPPORT, SURVEY, OTHER) na flow_json (ihe ma ọ bụ mkpụrụedemede, ruo 10 MB).
# Builds the body from the file with jq, then creates the draft
jq -n --slurpfile f quote-request.json \
'{name: "quote_request", categories: ["LEAD_GENERATION"], flow_json: $f[0]}' |
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/flows \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
--data @-import { readFile } from "node:fs/promises";
const flowJson = JSON.parse(await readFile("quote-request.json", "utf8"));
const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/flows", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ name: "quote_request", categories: ["LEAD_GENERATION"], flow_json: flowJson }),
});
const created = await res.json();
console.log(res.status, created.flow?.id, created.validation_errors);import json, os, requests
with open("quote-request.json") as f:
flow_json = json.load(f)
res = requests.post("https://api.app2email.com/v1/YOUR_NUMBER/flows",
headers={"Authorization": f"Bearer {os.environ['API_KEY']}"},
json={"name": "quote_request", "categories": ["LEAD_GENERATION"], "flow_json": flow_json},
timeout=30)
created = res.json()
print(res.status_code, created.get("flow", {}).get("id"), created.get("validation_errors"))Ihe ị na-enweta azụ (201 Created):
{
"success": true,
"request_id": "f1new",
"flow": {
"id": "1234567890123456",
"name": "quote_request",
"status": "DRAFT"
},
"validation_errors": [],
"note": "The flow belongs to the whole WhatsApp Business Account: every number on it can send it."
}Debe flow.id: oku ọ bụla ọzọ na ozi ị na-ezipu na-eji ya. validation_errors efu pụtara na WhatsApp enweghị ihe ọ chọrọ ịgbanwe. Aha akaụntụ ahụ ejirila na-azaghachi 409 flow_name_taken.
Ọ bụrụ na ị tinye "publish": true n'otu arịrịọ ahụ, flow na-enweghị njehie ka a na-ebipụta ozugbo. Nke a enweghị ike ịkagbu, ya mere nduzi a na-ebipụta n'usoro dị iche mgbe ị nwalesịrị fọm ahụ. clone_flow_id na-eme ihe ọzọ: ọ na-eme oke nke flow dị n'otu akaụntụ ahụ.
Mgbe WhatsApp chọtara nsogbu, a ka na-emepụta flow dị ka draft, validation_errors na-edepụta nke ọ bụla yana error, error_type na message nke WhatsApp, ebe dị na JSON (line_start, line_end, column_start, column_end) na pointers. Dịka ihe atụ, mgbe e mere njehie na type akụrụngwa (akpọkwala nkenke, ederede bụ nke WhatsApp):
{
"success": true,
"request_id": "f1new",
"flow": { "id": "1234567890123456", "name": "quote_request", "status": "DRAFT" },
"validation_errors": [
{
"error": "INVALID_PROPERTY_VALUE",
"error_type": "FLOW_JSON_ERROR",
"message": "Invalid value found for property 'type'.",
"line_start": 15,
"line_end": 15,
"column_start": 25,
"column_end": 36
}
]
}Dozie faịlụ ahụ wee zipu Flow JSON dum ọzọ site na PUT /flows/{id}/json (ikike templates:manage). Ahịrị ahụ bụ Flow JSON n'onwe ya (ma ọ bụ {"flow_json": {...}}), ruo 10 MB.
curl -X PUT https://api.app2email.com/v1/YOUR_NUMBER/flows/1234567890123456/json \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
--data @quote-request.jsonconst res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/flows/1234567890123456/json", {
method: "PUT",
headers: { Authorization: `Bearer ${process.env.API_KEY}`, "Content-Type": "application/json" },
body: await readFile("quote-request.json", "utf8"),
});
console.log((await res.json()).validation_errors);with open("quote-request.json", "rb") as f:
res = requests.put("https://api.app2email.com/v1/YOUR_NUMBER/flows/1234567890123456/json",
headers={"Authorization": f"Bearer {os.environ['API_KEY']}",
"Content-Type": "application/json"},
data=f.read(), timeout=30)
print(res.json()["validation_errors"])Ihe ị na-enweta azụ:
{
"success": true,
"request_id": "f1put",
"flow_id": "1234567890123456",
"validation_errors": [],
"note": "WhatsApp found no errors. Publish with POST /flows/1234567890123456/publish (cannot be undone)."
}Ahịrị nke abụghị JSON n'ezie na-azaghachi 400 invalid_json; flow_json nke a na-agaghị agụ dị ka Flow JSON na-azaghachi 400 invalid_flow_json. GET /flows/{id}/json na-enye Flow JSON WhatsApp na-echekwa maka flow ahụ.
GET /flows/{id}/preview (ikike messages:read) na-enye njikọ nlele nke na-arụ ọrụ ruo ụbọchị 30. Tinye &interactive=true n'njikọ ahụ iji juputa fọm ahụ n'onwe gị.
curl https://api.app2email.com/v1/YOUR_NUMBER/flows/1234567890123456/preview \
-H "Authorization: Bearer YOUR_API_KEY"Ihe ị na-enweta azụ:
{
"success": true,
"request_id": "f1prv",
"flow_id": "1234567890123456",
"preview_url": "https://business.facebook.com/wa/manage/flows/1234567890123456/preview/?token=b9d6a1c2",
"expires_at": "2026-12-06T01:00:00+0000",
"note": "Anyone with the link can see the flow until it expires (30 days). Add &interactive=true to try it."
}Onye ọ bụla nwere njikọ ahụ nwere ike imeghe ya, ma n'ime iframe. Ọ bụrụ na njikọ pụọ n'ebe a na-agaghị, POST /flows/{id}/preview (ikike templates:manage) na-emepụta otu ọhụrụ, ochie ahụ kwụsịkwara ọrụ ozugbo.
Naanị flow e bipụtara ka a ka nwere ike izipu ya onye ahịa. POST /flows/{id}/publish (ikike templates:manage, enweghị body) na-ebipụta draft nke enweghị njehie validation.
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/flows/1234567890123456/publish \
-H "Authorization: Bearer YOUR_API_KEY"const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/flows/1234567890123456/publish", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.API_KEY}` },
});
console.log(res.status, await res.json());res = requests.post("https://api.app2email.com/v1/YOUR_NUMBER/flows/1234567890123456/publish",
headers={"Authorization": f"Bearer {os.environ['API_KEY']}"}, timeout=30)
print(res.status_code, res.json())Ihe ị na-enweta azụ:
{
"success": true,
"request_id": "f1pub",
"flow_id": "1234567890123456",
"name": "quote_request",
"previous_status": "DRAFT",
"status": "PUBLISHED",
"note": "Published for every number on this WhatsApp Business Account. It cannot be deleted (deprecate it instead). Changing its name, categories, endpoint or Flow JSON puts it back to DRAFT until you publish again; messages already sent keep the old version."
}Ebipụta enweghị ike ịkagbu. Webhook gị na-anatakwa flow.status_changed nwere new_status PUBLISHED (ihe atụ n'okpuru). Mgbe WhatsApp ebipụtaghị ya (ọ bụghị draft, nwere njehie validation, ma ọ bụ nyocha ebipụta dara), azịza bụ 422 flow_cannot_publish.
Tupu izipu, GET /flows/{id} (ikike messages:read) na-egosi ọnọdụ, njehie validation, ụdị Flow JSON na health_status, nke na-ekwu ma a ka nwere ike izipu flow ahụ ugbu a:
{
"success": true,
"request_id": "f1get",
"flow": {
"id": "1234567890123456",
"name": "quote_request",
"status": "PUBLISHED",
"categories": ["LEAD_GENERATION"],
"validation_errors": [],
"json_version": "7.2",
"health_status": {
"can_send_message": "AVAILABLE",
"entities": [{ "entity_type": "FLOW", "id": "1234567890123456", "can_send_message": "AVAILABLE" }]
}
}
}can_send_message bụ AVAILABLE, LIMITED ma ọ bụ BLOCKED.
N'ime oge awa 24 (onye ahịa dere gị n'ime awa 24 gara aga, dịka "Enwere m ike nweta ọnụ ahịa?"), zipu fọm dị ka ozi mmekọrịta n'efu site na POST /messages (ikike messages:send):
| Akụkụ | Ihe ị ga-etinye |
|---|---|
interactive.type | flow |
header, body | Ederede dị n'elu bọtịnụ. header bụ nhọrọ |
action.name | flow |
flow_message_version | "3" |
flow_id | Id nke flow site na nzọụkwụ 2 |
flow_cta | Ederede bọtịnụ, ruo mkpụrụedemede 30 |
flow_token | Ntụaka gị maka arịrịọ a, dịka ọmụmaatụ id onye ndu gị. Ọ na-alọta n'azịza, ya mere ị ga-ama arịrịọ ndị azịza ahụ bụ nke ya |
flow_action, flow_action_payload.screen | navigate na id nke ihuenyo mbụ, QUOTE |
Isi Idempotency-Key | Uru pụrụ iche maka izipu a. Otu arịrịọ ahụ yana otu igodo n'ime awa 24 agaghị ezipu ọzọ |
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/messages \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: quote-form-lead-0042" \
-d '{
"to": "61412345678",
"type": "interactive",
"interactive": {
"type": "flow",
"header": { "type": "text", "text": "Request a quote" },
"body": { "text": "Tell us what you need and when. It takes 30 seconds." },
"action": {
"name": "flow",
"parameters": {
"flow_message_version": "3",
"flow_id": "1234567890123456",
"flow_cta": "Request a quote",
"flow_token": "quote-lead-0042",
"flow_action": "navigate",
"flow_action_payload": { "screen": "QUOTE" }
}
}
}
}'const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/messages", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": `quote-form-${leadId}`,
},
body: JSON.stringify({
to: "61412345678",
type: "interactive",
interactive: {
type: "flow",
header: { type: "text", text: "Request a quote" },
body: { text: "Tell us what you need and when. It takes 30 seconds." },
action: {
name: "flow",
parameters: {
flow_message_version: "3",
flow_id: "1234567890123456",
flow_cta: "Request a quote",
flow_token: `quote-${leadId}`,
flow_action: "navigate",
flow_action_payload: { screen: "QUOTE" },
},
},
},
}),
});
console.log(res.status, await res.json());res = requests.post(
"https://api.app2email.com/v1/YOUR_NUMBER/messages",
headers={"Authorization": f"Bearer {os.environ['API_KEY']}", "Idempotency-Key": f"quote-form-{lead_id}"},
json={
"to": "61412345678",
"type": "interactive",
"interactive": {
"type": "flow",
"header": {"type": "text", "text": "Request a quote"},
"body": {"text": "Tell us what you need and when. It takes 30 seconds."},
"action": {
"name": "flow",
"parameters": {
"flow_message_version": "3",
"flow_id": "1234567890123456",
"flow_cta": "Request a quote",
"flow_token": f"quote-{lead_id}",
"flow_action": "navigate",
"flow_action_payload": {"screen": "QUOTE"},
},
},
},
},
timeout=10,
)
print(res.status_code, res.json())Ihe ị na-enweta azụ (200):
{
"success": true,
"request_id": "kxrkf",
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBI1RjQyNUE3NEYxMzAzMzQ5MkEA",
"status": "accepted",
"type": "interactive",
"from": "4976659348270",
"to": "61412345678",
"window_closes_at": "2026-11-22T08:45:00Z",
"conversation_url": "https://www.app2email.com/conversation/61412345678_4976659348270_...",
"contacts": [{ "input": "61412345678", "wa_id": "61412345678" }]
}accepted pụtara na WhatsApp anabataala ozi ahụ. Debe message_id: azịza onye ahịa na-ezo aka na ya. N'èzí oge ahụ, oku ahụ na-azaghachi 422 outside_24h_window.
N'èzí oge awa 24 (onye ahịa nke weebụsaịtị gị, ma ọ bụ onye ahịa dere izu gara aga), naanị template e kwadoro nwere ike ịmalite mkparịta ụka. Mepụta template nwere bọtịnụ nke na-emeghe Flow, na WhatsApp Manager ma ọ bụ site na POST /templates (ikike templates:manage, components n'ụdị WhatsApp, lee akwụkwọ Meta). WhatsApp na-enyocha ya (nkeji ole na ole ruo otu ụbọchị), template.status_changed na-agwa gị nsonaazụ. Mgbe ahụ zipu ya site na akụkụ button nke sub_type flow. action ya na-ebu flow_token:
{
"to": "61412345678",
"type": "template",
"template": {
"name": "quote_request",
"language": { "code": "en" },
"components": [
{
"type": "button",
"sub_type": "flow",
"index": "0",
"parameters": [
{ "type": "action", "action": { "flow_token": "quote-lead-0042" } }
]
}
]
}
}index bụ ọnọdụ bọtịnụ ahụ n'ime template, malite na "0". flow_token bụ nhọrọ; na-enweghị ya, ị gaghị ama azịza ọ bụ nke arịrịọ ahụ, ya mere zipu otu. action.flow_action_data na-ebufe uru na ihuenyo mbụ, maka Flow JSON nke ihuenyo ya na-anara data; fọm a enweghị ihe ọ bụla. GET /templates (ikike messages:read) na-edepụta template gị, maka nke ọ bụla e kwadoro ọ na-enye arịrịọ ihe atụ zuru ezu. Ọ bụrụ na uru template adabaghị, azịza bụ 422 template_parameters_invalid yana example_request ziri ezi.
message.status maka ozi fọm ahụ (sent, delivered, read), dịka ozi ọ bụla ọzọ, wee nata azịza ahụ:{
"id": "evt_Pa3k9m2Lw8Rt5Yp1Zs014",
"type": "message.received",
"created": "2026-11-21T09:14:00.000Z",
"number": "4976659348270",
"data": {
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgASGBQzQUZCMTY0MDc2MUYwNzBDNTY5MAA=",
"from": "61412345678",
"name": "Jane Citizen",
"type": "interactive",
"text": "[FLOW] Sent\r\nname: Jane Citizen\r\nservice: gutter_cleaning\r\npreferred_date: 2026-12-03",
"in_reply_to": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBI1RjQyNUE3NEYxMzAzMzQ5MkEA",
"context": {
"from": "4976659348270",
"id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBI1RjQyNUE3NEYxMzAzMzQ5MkEA"
},
"interactive": { "type": "nfm_reply" },
"flow": {
"name": "flow",
"body": "Sent",
"token": "quote-lead-0042",
"response": {
"flow_token": "quote-lead-0042",
"name": "Jane Citizen",
"service": "gutter_cleaning",
"preferred_date": "2026-12-03"
}
},
"conversation_url": "https://www.app2email.com/conversation/61412345678_4976659348270_k3XbQ9rTzP2mWv7a1c9e",
"timestamp": "2026-11-21T09:14:00.000Z"
}
}data.flow.response bụ ihe onye ahịa jupụtara, n'okpuru aha nke payload gị, yana flow_token. Azịza Dropdown bụ id nke nhọrọ ahụ (gutter_cleaning), ọ bụghị aha ya.data.flow.token bụ flow_token ị zipuru: jiri ya chọta lead gị.in_reply_to na context.id bụ message_id nke ozi fọm ị zipuru.data.text bụ nkọwa a na-agụ nke otu azịza ahụ, maka logs na ndị mmadụ.from_user_id na-enweghị from. Id ahụ na-arụ ọrụ ebe ọ bụla nọmba na-arụ ọrụ.Ụdị abụọ ahụ na-enyocha akara, na-agafe nhalụ ha emeela, na-edebe naanị azịza Flow nwere token quote-, na-echekwa lead ahụ wee ekele. Tọọ NUMBER, API_KEY na WEBHOOK_SECRET (secret whsec_... nke webhook gị) tupu ịmalite.
// Node.js 18 or newer. npm install express then node server.mjs
import crypto from "node:crypto";
import express from "express";
const { NUMBER, API_KEY, WEBHOOK_SECRET, PORT = 3000 } = process.env;
const API = `https://api.app2email.com/v1/${NUMBER}`;
const SERVICES = new Set(["window_cleaning", "gutter_cleaning", "pressure_washing"]);
const done = new Set(); // handled event ids: use a database table or Redis in production
function verify(raw, header, secret) {
const t = /(?:^|,)\s*t=(\d+)/.exec(header ?? "")?.[1];
const v1 = [...(header ?? "").matchAll(/(?:^|,)\s*v1=([0-9a-f]+)/g)].map((m) => m[1]); // two during a secret change
if (!t || v1.length === 0 || Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
const expected = crypto.createHmac("sha256", secret).update(t + ".").update(raw).digest("hex");
return v1.some((v) => v.length === expected.length && crypto.timingSafeEqual(Buffer.from(v), Buffer.from(expected)));
}
async function saveLead(lead) {
console.log("new quote request", lead); // your CRM or database: one row per flow token
}
async function thank(to, messageId, name) {
const res = await fetch(`${API}/messages`, {
method: "POST",
signal: AbortSignal.timeout(4000),
headers: { Authorization: `Bearer ${API_KEY}`, "Content-Type": "application/json", "Idempotency-Key": `thanks-${messageId}` },
body: JSON.stringify({ to, type: "text", text: { body: `Thanks ${name}! You will get your quote within one working day.` } }),
});
const json = await res.json();
if (res.status === 429 || res.status >= 500) throw new Error(`${json.error?.code} ${json.request_id}`);
if (!res.ok) console.warn("thank-you not sent:", json.error?.code, json.error?.how_to_fix, json.request_id);
}
const app = express();
app.post("/webhook", express.raw({ type: "application/json" }), async (req, res) => {
if (!verify(req.body, req.get("X-App2email-Signature"), WEBHOOK_SECRET)) return res.sendStatus(401);
const event = JSON.parse(req.body);
const m = event.data ?? {};
const isQuote = event.type === "message.received" && m.interactive?.type === "nfm_reply" && m.flow?.token?.startsWith("quote-");
if (!isQuote || done.has(event.id)) return res.sendStatus(200);
const answers = m.flow.response ?? {};
const lead = {
token: m.flow.token,
contact: m.from || m.from_user_id,
name: String(answers.name ?? "").slice(0, 100),
service: SERVICES.has(answers.service) ? answers.service : "other",
preferred_date: /^\d{4}-\d{2}-\d{2}$/.test(answers.preferred_date ?? "") ? answers.preferred_date : null,
message_id: m.message_id,
};
try {
await saveLead(lead);
if (!event.test) await thank(lead.contact, m.message_id, lead.name); // test events have a made-up contact
done.add(event.id); // only after it worked: a failed event comes again
res.sendStatus(200);
} catch (err) {
console.error("not handled, app2email will send it again:", event.id, err.message);
res.sendStatus(503);
}
});
app.listen(PORT, () => console.log(`listening on http://localhost:${PORT}/webhook`));# Python 3.9 or newer. pip install flask requests then flask --app server run --port 3000
import hashlib, hmac, json, os, re, time
import requests
from flask import Flask, request
NUMBER, API_KEY, SECRET = os.environ["NUMBER"], os.environ["API_KEY"], os.environ["WEBHOOK_SECRET"]
API = f"https://api.app2email.com/v1/{NUMBER}"
SERVICES = {"window_cleaning", "gutter_cleaning", "pressure_washing"}
done = set() # handled event ids: use a database table or Redis in production
def verify(raw: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
t = re.search(r"(?:^|,)\s*t=(\d+)", header or "")
v1 = re.findall(r"(?:^|,)\s*v1=([0-9a-f]+)", header or "") # two during a secret change
if not t or not v1 or abs(time.time() - int(t.group(1))) > tolerance:
return False
expected = hmac.new(secret.encode(), t.group(1).encode() + b"." + raw, hashlib.sha256).hexdigest()
return any(hmac.compare_digest(v, expected) for v in v1)
def save_lead(lead):
print("new quote request", lead) # your CRM or database: one row per flow token
def thank(to, message_id, name):
res = requests.post(f"{API}/messages", timeout=4,
headers={"Authorization": f"Bearer {API_KEY}", "Idempotency-Key": f"thanks-{message_id}"},
json={"to": to, "type": "text",
"text": {"body": f"Thanks {name}! You will get your quote within one working day."}})
data = res.json()
if res.status_code == 429 or res.status_code >= 500:
raise RuntimeError(f"{data.get('error', {}).get('code')} {data.get('request_id')}")
if not res.ok:
print("thank-you not sent:", data["error"]["code"], data["error"].get("how_to_fix"), data.get("request_id"))
app = Flask(__name__)
@app.post("/webhook")
def webhook():
raw = request.get_data()
if not verify(raw, request.headers.get("X-App2email-Signature"), SECRET):
return "bad signature", 401
event = json.loads(raw)
m = event.get("data") or {}
flow = m.get("flow") or {}
is_quote = (event.get("type") == "message.received"
and (m.get("interactive") or {}).get("type") == "nfm_reply"
and str(flow.get("token", "")).startswith("quote-"))
if not is_quote or event["id"] in done:
return "", 200
answers = flow.get("response") or {}
date = str(answers.get("preferred_date", ""))
lead = {
"token": flow["token"],
"contact": m.get("from") or m.get("from_user_id"),
"name": str(answers.get("name", ""))[:100],
"service": answers.get("service") if answers.get("service") in SERVICES else "other",
"preferred_date": date if re.fullmatch(r"\d{4}-\d{2}-\d{2}", date) else None,
"message_id": m.get("message_id"),
}
try:
save_lead(lead)
if not event.get("test"): # test events have a made-up contact
thank(lead["contact"], m["message_id"], lead["name"])
except Exception as err:
print("not handled, app2email will send it again:", event["id"], err)
return "", 503
done.add(event["id"]) # only after it worked: a failed event comes again
return "", 200Iji nwalee onye nnata na-enweghị onye ahịa n'ezie, zipu ya ihe nlereanya gị: POST /webhooks/{id}/test (ikike webhooks:manage) yana {"event": {...}} na ahụ message.received dị n'elu. Nhalụ nnwale nwere "test": true na isi X-App2email-Test: true, a na-ebinye akara ha dịka ihe niile, ruo nnwale 30 n'otu awa maka nọmba ọ bụla.
flow.status_changed na-akọ ihe na-eme na flow: ebipụtara, ọ na-egbu egbu, egbochiri ya, kwụsịrị ya, alert nke Meta mepụtara ma ọ bụ hichapụrụ maka njikọ ma ọ bụ onye ahịa, ma ọ bụ ịdọ aka ná ntị na Flow JSON version ya ga-agwụ n'oge dị nso. Nọmba niile n'WhatsApp Business Account ahụ na-anata ya.
{
"id": "evt_Xq3k9m2Lw8Rt5Yp1Zs21",
"type": "flow.status_changed",
"created": "2026-11-21T09:05:00.000Z",
"number": "4976659348270",
"data": {
"flow_id": "1234567890123456",
"change": "status",
"event": "FLOW_STATUS_CHANGE",
"old_status": "DRAFT",
"new_status": "PUBLISHED",
"message": "Flow quote_request changed status from DRAFT to PUBLISHED",
"timestamp": "2026-11-21T09:05:00.000Z"
}
}Lelee maka new_status THROTTLED ma ọ bụ BLOCKED, na maka change flow_version_expiry_warning: warning ya na-ekwu mgbe ụdị Flow JSON ga-akwụsị ịgbanwe. Mgbe ahụ flow ahụ enweghị ike izipu ọzọ, ya mere bugharịa JSON gaa version ọhụrụ site na PUT /flows/{id}/json wee bipụta ọzọ.
PUT /flows/{id}/json yana JSON ọhụrụ, ma ọ bụ PATCH /flows/{id} yana name, categories ma ọ bụ endpoint_uri ọhụrụ. Flow e bipụtara na-alaghachi DRAFT ruo mgbe ị bipụtara ya ọzọ, ma ozi e zipuru ka na-eji ụdị ochie. Flow ụfọdụ enweghị ike ịgbanwe (409 flow_not_editable, dịka ihe e kwụsịrị): detuo ya site na POST /flows na clone_flow_id, gbanwe ọkọlọtọ ahụ wee bipụta ya.POST /flows/{id}/deprecate (ikike templates:manage). Ọ gaghị ezipu ma ọ bụ mepee ọzọ. Nke a enweghị ike ịkagbu.DELETE /flows/{id} na-arụ ọrụ maka drafts naanị. Flow e bipụtara na-azaghachi 409 flow_not_deletable: kwụsị ya kama.GET /flows (ikike messages:read) na-edepụta flow niile nke akaụntụ ahụ yana id, aha, ọnọdụ, categories na njehie validation, 1 ruo 100 n'otu oge (limit, na cursor yana next_cursor nke azịza gara aga).Fọm chọrọ data ndụ. Fọm nduzi a onwe ya dị nke ya. Flow nke na-anakọta data mgbe onye ahịa na-ejuputa ya (oge efu, ọnụ ahịa) na-eji ebe data nke gị: endpoint_uri nke flow, na igodo ọha RSA 2048-bit nke nọmba ahụ tọrọ site na PUT /flows/encryption-key (ikike templates:manage; GET /flows/encryption-key na-egosi ya). Nọmba ọ bụla nwere igodo nke ya. Ebe Book-and-Pay na-eji igodo ahụ maka Flows booking ya, itinye igodo ọzọ na-azaghachi 409 encryption_key_managed.
Ịchọghị Flow JSON ide? app2email na-arụkwa fọm WhatsApp maka gị. Submit-Info na-agbanwe ndepụta ajụjụ dị mfe ka ọ bụrụ fọm WhatsApp na ibe weebụ (POST /submit/forms, POST /submit/forms/{key}/publish, POST /submit/forms/{key}/send, ikike submissions:manage); azịza ya na-abịa dị ka submission.created. Ngalaba Book-and-Pay nwere fọm booking na fọm ndị ọzọ ị na-zipu site na POST /flows/{key}/send (ikike bookings:manage); fọm Flow nke ngalaba ahụ na-akọ flow.completed, flow booking na-akọ booking.created. Flows ị mepụtara site na POST /flows na-akọ azịza ha dị ka message.received, dịka egosiri n'elu.
Nyochaa nhalụ ọ bụla. Nyochaa X-App2email-Signature (t=<unix seconds>,v1=<hex>, HMAC-SHA256 nke t, otu ntụpọ na raw body, yana secret whsec_... nke webhook) n'ihe niile dị na raw body, tupu ị gbakọọ ya. Nyochaa v1= ọ bụla, tụnyere ha n'otu oge ka a ghara ịgbanwe, wee jụ t karịrị nkeji 5.
Dedupe site na id n'ezie. Debe id nke nhalụ ọ bụla ị kpaliri (ọ bụkwa X-App2email-Delivery) opekata mpe ụbọchị abụọ: a na-ezipu nhalụ dara ọzọ ihe dị ka awa 32. Chekwaa otu lead maka flow_token ọ bụla, ka onye ahịa zipuru fọm otu ugboro karịa ma na-emelite arịrịọ ya kama ịmepụta nke ọzọ.
Zipu ozi ọ bụla otu ugboro. Nye POST /messages ọ bụla Idempotency-Key (maka fọm: id lead gị; maka ekele: message_id nke azịza). Otu igodo na otu body n'ime awa 24 na-alọghachi azịza mbụ yana Idempotent-Replayed: true. Igodo otu ahụ yana body ọzọ: 422 idempotency_key_reused. 409 idempotency_request_in_progress: chere wee nwaa ọzọ yana otu igodo.
Zaa ngwa ngwa. Zaghachi 2xx n'ime sekọnd 10; a naghị agbaso redirects. Maka ọrụ dị oke, chekwaa nhalụ, zaghachi 200 wee hazie ya site na queue.
Kpachara oke. Azịza ọ bụla nwere X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset na X-RateLimit-Policy. Karịa oke: 429 rate_limited yana Retry-After; chere, wee zipu ọzọ. Oke WhatsApp n'onwe ya (429 whatsapp_rate_limit, too_many_messages_to_recipient) chọrọ nkeji ole na ole. Ozi fọm ọ bụla na-agụ dị ka otu ozi nke atụmatụ gị.
Lezie anya n'oge awa 24. Ozi fọm mmekọrịta bụ n'efu: ọ na-aga naanị onye ahịa dere n'ime awa 24 gara aga (app2email na-akwụsị nkeji 15 tupu oge; window_closes_at bụ oge kpọmkwem). Ndị ọzọ nwere template e kwadoro nwere bọtịnụ Flow.
Opt-in na Do Not Call. Ọ bụrụ na template bọtịnụ Flow gị bụ template ahịa, ọ na-agbaso otu iwu dịka template ahịa ọ bụla: onye ahịa nke dị na Do Not Call list gị azaghachi 403 recipient_opted_out, nọmba chọrọ opt-in azaghachi 403 recipient_not_opted_in maka onye ahịa na-enweghị ya. Template ozi (utility) ka nwere ike izipu. Lee Zipu mkpọsa ahịa nke na-erube isi n'opt-in.
Were azịza dị ka data. Onye ahịa dere ha. Lelee ọ bụla (id ọrụ a maara, ụbọchị n'ezie, ogologo ziri ezi) tupu ọ banye n'ime database gị, ma emesịa ya dị ka iwu ma ọ bụ nye AI model agwakọtara ya na ntụziaka gị.
Gbanwe flows nke ọma. Flows na-ekerịta site na nọmba niile nke WhatsApp Business Account, mgbanwe nke flow e bipụtara na-alaghachi DRAFT ruo mgbe ị bipụtara ọzọ. Debe Flow JSON n'ime version control gị, nwalee mgbanwe site na njikọ nlele, lee flow.status_changed.
Ikike kacha ntakịrị. Onye nnata chọrọ messages:send naanị (maka ekele). Debe templates:manage na igodo dị iche nke naanị scripts nhazi gị na-eji. Debe igodo na sava, ọ bụghị na ibe weebụ ma ọ bụ log.
| Ihe ị hụrụ | Ihe kpatara ya | Ngwọta |
|---|---|---|
403 insufficient_scope | Igodo enweghị ikike (details.required_scope) | Mepụta igodo nwere templates:manage iji wuo flows, messages:send iji zipu ha |
403 sandbox_key | Igodo sandbox enweghị ike ịmepụta, gbanwe ma bipụta flows | Jiri igodo a na-ejikọta maka oku ndị a; debe igodo sandbox maka nnwale POST /messages |
403 not_in_instant_sandbox | Nọmba demo 12025550100 enweghị oku flow | Jiri nọmba gị ejikọtara n'onwe |
400 invalid_flow_name | name efuru ma ọ bụ karịa mkpụrụedemede 200 | Zipu aha dị nkenke nke ime, dịka ọmụmaatụ quote_request |
400 invalid_flow_categories | categories efuru ma ọ bụ nwere uru a na-amaghị | Zipu ndepụta nwere opekata mpe otu category, dịka ["LEAD_GENERATION"] |
400 invalid_flow_json, invalid_json | Flow JSON ma ọ bụ body abụghị JSON ziri ezi, ma ọ bụ abụghị object | Lelee bracket, quotes na commas; zipu Flow JSON dị ka object |
400 invalid_flow_field | Ubi nwere ụdị uru ezighi ezi, dịka publish abụghị true ma ọ bụ false | Jiri ubi name, categories, flow_json, publish, endpoint_uri, clone_flow_id |
400 invalid_flow_id, 404 flow_not_found | Id nke adreesị abụghị flow nke akaụntụ a | GET /flows na-edepụta id ndị ahụ |
404 flow_json_not_found | Flow enweghị Flow JSON fọdụrụ | Bulite ya site na PUT /flows/{id}/json |
validation_errors abụghị efu | WhatsApp chọtara nsogbu na Flow JSON | Dozie nke ọ bụla n'ahịrị na kolum ya, wee PUT /flows/{id}/json ọzọ |
409 flow_name_taken | Akaụntụ nwere flow nwere aha a | Họrọ aha ọzọ |
413 flow_json_too_large | Flow JSON karịrị oke 10 MB nke WhatsApp | Mee ka ọ dị obere |
422 flow_cannot_publish | Flow abụghị draft, nwere njehie validation, ma ọ bụ dara nyocha ebipụta | GET /flows/{id} na-egosi validation_errors na health_status; dozie ha wee bipụta ọzọ |
422 flow_rejected | WhatsApp anabataghị arịrịọ ahụ | Gụọ whatsapp_error n'azịza, dozie arịrịọ ahụ wee zipu ọzọ |
409 flow_not_editable | WhatsApp adịghị ekwe ka a gbanwe flow a | Detụọ ya site na clone_flow_id, gbanwe ọkọlọtọ ahụ wee bipụta ya |
409 flow_not_deletable | Flow e bipụtara enweghị ike ihichapụ | Kwụsị ya site na POST /flows/{id}/deprecate |
409 flow_not_published | Naanị flow e bipụtara ka a ka nwere ike ikwụsị | Ọ dịghị ihe ikwụsị; a ka ike ihichapụ draft |
409 encryption_key_managed | Book-and-Pay na-eji igodo encryption Flow nke nọmba ahụ | Hapụ igodo ka ọ dị; flow nwere ebe data nke gị chọrọ nọmba na-enweghị Book-and-Pay |
403 flow_blocked_by_integrity | Meta egbochiri ime ma ọ bụ bipụta flows na akaụntụ WhatsApp a | Kpọtụrụ nkwado Meta site na WhatsApp Manager |
403 whatsapp_permission_missing | Meta enyeghị app2email ikike a chọrọ maka akaụntụ gị | Ịlaghachi ọzọ enyeghị aka; kpọtụrụ support@app2email.com |
422 outside_24h_window | Onye ahịa dere ihe karịrị awa 24 gara aga | Zipu template e kwadoro nwere bọtịnụ Flow ọzọ |
404 template_not_found, 422 template_not_approved | Aha ma ọ bụ asụsụ template ahụ adịghị mma, ma ọ bụ e kwadoghị ya fọdụrụ | Họrọ otu site na GET /templates nwere ọnọdụ APPROVED |
422 template_parameters_invalid | Akụkụ bọtịnụ adabaghị template ahụ | Tụnyere ya na example_request n'azịza ahụ |
400 invalid_interactive | Akụkụ mmekọrịta adịghị mma (ụdị ya ma ọ bụ ogologo ederede) | Lelee interactive.type flow, action.parameters, wee debe flow_cta ruo mkpụrụedemede 30 |
429 rate_limited | Oku ndị dị oke maka igodo a | Chere sekọnd Retry-After, wee nwaa ọzọ |
502 whatsapp_error | WhatsApp jụrụ arịrịọ ahụ n'njehie na-enweghị koodu nke ya | Gụọ whatsapp_error; nwaa ọzọ mgbe e mesịrị, zipu request_id na nkwado ma ọ bụrụ na ọ na-adịgide |
| Fọm ahụ na-emeghe, ma azịza adịghị abịa | Webhook akwụsịla, ma ọ bụ onye nnata gị na-atụfu nhalụ ahụ | GET /webhooks na-egosi active na nnyefe ikpeazụ; GET /webhooks/{id}/deliveries?status=failed na-egosi ihe dara |
Azịza ọ bụla nwere request_id. GET /requests/{id} na-egosi ihe e debanyere maka ya, support@app2email.com nwekwara ike ịchọta ya. Koodu niile: Njehie.
Ee. MCP server https://api.app2email.com/mcp/flows nwere otu oku dị ka tools: list_flows, get_flow, create_flow, update_flow, get_flow_json, update_flow_json, publish_flow, deprecate_flow, delete_flow, get_flow_preview na renew_flow_preview. Lee Kwe ka AI agent na-achịkwa WhatsApp gị site na MCP na MCP.
Oku ozi fọm mmekọrịta na-aga otu kọntaktị n'otu oku, n'ime window ha. Iji ruo ọtụtụ ndị ahịa, zipu template e kwadoro nwere bọtịnụ Flow, dịka mkpọsa maka otu, ma soro iwu opt-in maka template ahịa. Nye onye ahịa ọ bụla flow_token nke ya ọ bụrụ na ị chọrọ ịtụnyere azịza na ndị mmadụ.
Ozi e zipuru ka na-eji version flow ahụ ha zipuru ya. Mgbanwe na-amalite ịrụ ọrụ maka ozi ọhụrụ mgbe ị bipụtara ọzọ. Flow e kwụsịrị enweghị ike izipu ma ọ bụ mepee ọzọ.
Ee: webhook nwere "format": "meta" na-anata ihe na-abịa site na WhatsApp dị ka body Meta n'onwe ya (entry[].changes[]), a na-ebinye ya akara otu ụzọ. Na ụdị default app2email, azịza ahụ emepechala n'ime data.flow, dịka egosiri n'elu. data.whatsapp na-ebukwa object ozi Meta agbanwebeghị.
Oge efu, booking na ncheta site na Book-and-Pay API.
Nata ozi n'otu webhook e bịnyere akara wee zaa site na koodu gị.
Template e kwadoro maka ozi n'èzí oge awa 24, yana ọnọdụ nnyefe.
Debe lead fọm gị na-anakọta n'akụkụ data ndị ahịa gị ndị ọzọ.