صاوب سلسلة drip من templates موافَق عليها بوقفات بينهم، سجّل الزبناء الجداد، وقفها ملي يجاوبو ولا يخرجو من الـ opt-in، وتابع التقرير ديال كل خطوة.
فهاد الدليل غادي تصاوب سلسلة ديال تلات رسايل ترحيب: ترحيب فاليوم لي يسجل فيه الزبون، نصيحة ديال العناية بعد يومين، وعرض تخفيض فاليوم 7. كتصاوبها مرة وحدة. من بعد، كل زبون كتسجلو كيوصلو الرسايل حسب الجدول ديالو.
شنو كيشوف الزبون: رسالة WhatsApp من البزنس ديالك كيوصلو بعد ما يسجل: "Hi Jane, welcome to Green Leaf Plants!". بعد يومين رابط لدليل العناية بالنباتات ديالك. فاليوم 7 كود تخفيض 10% للطلب الجاي. إلا جاوب فأي وقت، السلسلة كتوقف وفريقك كياخد الشات. إلا كتب STOP، ما غيوصلوش عندك حتى إعلان.
شنو كتشوف نتا: لكل خطوة، شحال من رسالة تصيفطات (posted)، تصيفطات (sent)، توصلات (delivered)، تقراو (read)، فشلات (failed)، وكليكات. ولكل زبون، شنو الخطوات لي وصلاتو، إمتى كتجي الخطوة الجاية، وعلاش وقف. أحداث الـ webhook كتقول لنظامك ملي الزبون يكليك على رابط وملي يخرج من السلسلة.
POST /sequences: من 1 حتى 20 خطوة، كل خطوة template بالقيم ديالها وبوقفة.POST /sequences/{id}/enrolments، ولا خليه app2email يسجل كاع لي كياخدو tag.sequence.finished كل مرة.ما كيتصيفط والو حتى تسجل الزبناء. صاوب سلسلة ما كتصيفط والو.
sequences_not_enabled. رقم WhatsApp شخصي مربوط بـ QR ما يقدرش يصيفط templates، فما عندو حتى سلسلة (403 sequence_personal_number).| الصلاحية | شنو كتدير ليها فهاد الدليل |
|---|---|
templates:manage | صاوب التلات templates (POST /templates) |
messages:send | صاوب السلسلة وبدّلها وحبسها وامسحها، سجّل الزبناء وحيّدهم (POST /sequences، PUT /sequences/{id}، DELETE /sequences/{id}، POST /sequences/{id}/enrolments، DELETE /sequences/{id}/enrolments/{contact}) |
messages:read | حالة الـ templates، تقرير السلسلة، شكون فيها (GET /templates، GET /sequences/{id}، GET /sequences/{id}/enrolments، GET /broadcasts/{code}) |
contacts:manage | غير إلا كتسجل بالـ tag: عطي الـ contacts الـ tag (PATCH /contacts/{identity}) |
webhooks:manage | زيد الـ webhook لي غيستقبل الأحداث (POST /webhooks). تقدر تزيدو كذلك فصفحة مفتاح API بلا كود |
GET /v1/YOUR_NUMBER/me كيبين الصلاحيات ديال المفتاح لي عندك.
التجربة الأولى. مفتاح sandbox على رقمك (مفتاح فيه علامة sandbox، مصاوب فصفحة مفاتيح API) كيقدر يقرا السلاسل ديالك وتقاريرها وتسجيلاتها، وPOST /sequences/{id}/enrolments بـ "dry_run": true كيحسب شكون غيتسجل بلا ما يسجل حتى واحد. صاوب السلاسل وبدّلها وامسحها، والتسجيلات الحقيقية، كيجاوبو 403 sandbox_key: استعمل مفتاح عادي لهادشي. التجربة الفورية (الرقم ديال التجربة 12025550100 من POST https://api.app2email.com/v1/account/sandbox) ما عندها حتى سلسلة؛ كتجاوب 403 not_in_instant_sandbox. التفاصيل: Sandbox.
كل خطوة هي template، و Meta كيحسب كل template حسب الكاتيغوري ديالها وبلاد الزبون. اختار الكاتيغوري لي كيطابق شنو كتقول الرسالة:
| اليوم | الخطوة | Template | الكاتيغوري |
|---|---|---|---|
| 0 | ترحيب | welcome_new_customer | MARKETING. الترحيب ممكن يكون UTILITY غير ملي يكون غير على الحساب ولا الطلب لي دار الزبون، وما فيهش حتى شي دعاية |
| 2 | نصيحة العناية | plant_care_tips | MARKETING. النصايح والمحتوى ماشي على معاملة |
| 7 | العرض | welcome_offer | MARKETING. أي تخفيض ولا عرض تسويق |
Meta كيراجع الكاتيغوري مع الـ template، والعرض لي يتصيفط كـ UTILITY كيترفض ولا كيتحول لـ MARKETING. الـ templates ديال MARKETING كيتصيفطو غير للناس لي ماشي فلائحة Do Not Call ديالك، ومع قاعدة opt-in مفعّلة غير للناس لي عندهم سجل opt-in. باش تحسب شحال كتكلف السلسلة، استعمل حاسبة أثمان WhatsApp: تلات templates ديال MARKETING لكل زبون، مضروبة فعدد الزبناء لي كتتوقع فالشهر.
كل نداء كيمشي لـ https://api.app2email.com/v1/YOUR_NUMBER بـ Authorization: Bearer YOUR_API_KEY. YOUR_NUMBER هو رقم WhatsApp ديالك: رمز البلاد الأول، وغير الأرقام.
كتب كل رسالة بمتغيرات مرقمة، وعطي قيمة نموذجية لكل وحدة فـ example، وزيد footer كيقول كيفاش توقف. STOP وترجماتها كلمات opt-out معروفة عند app2email. حط كل رابط فمتغير، ماشي فالنص الثابت: app2email كيقدر من بعد يعطي كل زبون رابط خاص بيه مُتتبَّع (شوف الخطوة 2).
| Template | الـ Body | القيم |
|---|---|---|
welcome_new_customer | Hi {{1}}, welcome to Green Leaf Plants! We are happy you are here. Reply to this message any time if you have a question. | الاسم |
plant_care_tips | Hi {{1}}, here is our quick guide to keeping your new plants happy: {{2}} Happy growing! | الاسم، الرابط |
welcome_offer | Hi {{1}}, thanks for being with us this week. Use the code {{2}} for 10% off your next order: {{3}} The code is valid for 7 days. | الاسم، الكود، الرابط |
العرض، فطلب وحدو (التلاتة الآخرين نفس الشي بنصهم ونماذجهم):
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/templates \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "welcome_offer",
"language": "en",
"category": "MARKETING",
"components": [
{
"type": "BODY",
"text": "Hi {{1}}, thanks for being with us this week. Use the code {{2}} for 10% off your next order: {{3}} The code is valid for 7 days.",
"example": { "body_text": [["Jane", "WELCOME10", "https://www.example.com/shop"]] }
},
{ "type": "FOOTER", "text": "Reply STOP to opt out" }
]
}'const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/templates", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
name: "welcome_offer",
language: "en",
category: "MARKETING",
components: [
{
type: "BODY",
text: "Hi {{1}}, thanks for being with us this week. Use the code {{2}} for 10% off your next order: {{3}} The code is valid for 7 days.",
example: { body_text: [["Jane", "WELCOME10", "https://www.example.com/shop"]] },
},
{ type: "FOOTER", text: "Reply STOP to opt out" },
],
}),
});
console.log(res.status, await res.json());import os, requests
res = requests.post(
"https://api.app2email.com/v1/YOUR_NUMBER/templates",
headers={"Authorization": f"Bearer {os.environ['API_KEY']}"},
json={
"name": "welcome_offer",
"language": "en",
"category": "MARKETING",
"components": [
{
"type": "BODY",
"text": "Hi {{1}}, thanks for being with us this week. Use the code {{2}} for 10% off your next order: {{3}} The code is valid for 7 days.",
"example": {"body_text": [["Jane", "WELCOME10", "https://www.example.com/shop"]]},
},
{"type": "FOOTER", "text": "Reply STOP to opt out"},
],
},
timeout=10,
)
print(res.status_code, res.json())شنو كتاخد (201 Created): الـ template تصيفط لـ Meta باش يراجعه.
{
"success": true,
"request_id": "c3ppl",
"template": {
"id": "2234567890",
"name": "welcome_offer",
"language": "en",
"category": "MARKETING",
"status": "PENDING"
},
"note": "Submitted to WhatsApp for review (minutes to a day). You get a template.status_changed webhook event with the result, or GET https://api.app2email.com/v1/4976659348270/templates/welcome_offer."
}المراجعة كتدوم من دقايق حتى نهار. الحدث template.status_changed كيقولك النتيجة (status APPROVED مع can_send: true، ولا REJECTED مع reason)، ولا تقدر تسولها بـ GET /templates/welcome_offer. استنى حتى التلاتة يكونو APPROVED قبل ما تسجل حتى واحد. المراجعة بتفصيل أكثر: صيفط إشعارات الطلبات والمواعيد بالـ templates.
نداء وحد بالتلات خطوات. الوقفات كتحسب من الخطوة لي قبلها، يعني اليوم 7 هو 5 أيام بعد النصيحة ديال اليوم 2:
| الخطوة | الوقفة | كتتصيفط فـ |
|---|---|---|
welcome_new_customer | wait_days: 0 | اليوم 0، مباشرة بعد التسجيل |
plant_care_tips | wait_days: 2 | اليوم 2 |
welcome_offer | wait_days: 5 | اليوم 7 |
الوقفة ممكن تكون wait_minutes ولا wait_hours ولا wait_days؛ إلا صيفطتهم مع بعض كيتجمعو. كل وقفة من 0 حتى 90 يوم.
فقيم الخطوة، {name} هو اسم الـ contact. إلا ما كانش معروف، كيُستعمل name_fallback بدلو (الافتراضي "there"). track_clicks مفعّل بشكل افتراضي: كل عنوان فالقيم كيولي رابط مُتتبَّع خاص لكل contact، باش تشوف شكون كليكا.
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/sequences \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Welcome series",
"stop_on_reply": true,
"steps": [
{ "wait_days": 0, "template_name": "welcome_new_customer", "language": "en",
"parameters": { "body": ["{name}"], "name_fallback": "there" } },
{ "wait_days": 2, "template_name": "plant_care_tips", "language": "en",
"parameters": { "body": ["{name}", "https://www.example.com/plant-care"], "name_fallback": "there" } },
{ "wait_days": 5, "template_name": "welcome_offer", "language": "en",
"parameters": { "body": ["{name}", "WELCOME10", "https://www.example.com/shop"], "name_fallback": "there" } }
]
}'const step = (wait_days, template_name, body) => ({
wait_days, template_name, language: "en", parameters: { body, name_fallback: "there" },
});
const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/sequences", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
name: "Welcome series",
stop_on_reply: true,
steps: [
step(0, "welcome_new_customer", ["{name}"]),
step(2, "plant_care_tips", ["{name}", "https://www.example.com/plant-care"]),
step(5, "welcome_offer", ["{name}", "WELCOME10", "https://www.example.com/shop"]),
],
}),
});
const { sequence } = await res.json();
console.log(res.status, sequence.id, sequence.steps.map((s) => s.id));def step(wait_days, template_name, body):
return {"wait_days": wait_days, "template_name": template_name, "language": "en",
"parameters": {"body": body, "name_fallback": "there"}}
res = requests.post(
"https://api.app2email.com/v1/YOUR_NUMBER/sequences",
headers={"Authorization": f"Bearer {os.environ['API_KEY']}"},
json={
"name": "Welcome series",
"stop_on_reply": True,
"steps": [
step(0, "welcome_new_customer", ["{name}"]),
step(2, "plant_care_tips", ["{name}", "https://www.example.com/plant-care"]),
step(5, "welcome_offer", ["{name}", "WELCOME10", "https://www.example.com/shop"]),
],
},
timeout=10,
)
sequence = res.json()["sequence"]
print(res.status_code, sequence["id"], [s["id"] for s in sequence["steps"]])شنو كتاخد (201 Created؛ مختصر لأول خطوة فـ steps وreport):
{
"success": true,
"request_id": "s2new",
"sequence": {
"id": 12,
"name": "Welcome series",
"status": "active",
"stop_on_reply": true,
"enrol_tag": "",
"enrol_tag_since": null,
"created_by": "api",
"created_at": "2026-11-19T01:00:00.000Z",
"updated_at": "2026-11-19T01:00:00.000Z",
"steps": [
{
"id": 31,
"position": 0,
"wait_days": 0,
"wait_minutes": 0,
"template_name": "welcome_new_customer",
"language": "en",
"parameters": { "body": ["{name}"], "name_fallback": "there" },
"track_clicks": true,
"report_code": null
}
],
"counts": { "enrolled": 0, "active": 0, "finished": 0, "stopped": 0, "stopped_by_reply": 0, "opted_out": 0 },
"report": [
{ "step_id": 31, "position": 0, "template_name": "welcome_new_customer", "posted": 0, "sent": 0, "delivered": 0, "read": 0, "failed": 0, "clicked": 0, "clicks": 0, "report_url": null }
]
}
}خزن sequence.id والـ id ديال الخطوات: خاصك الـ ids ديال الخطوات باش تبدل الخطوات من بعد بلا ما تضيع تقاريرها. التلات خطوات الأخرى كيجاو بنفس الطريقة، بـ wait_minutes 2880 و7200. stop_on_reply كيكون true بشكل افتراضي؛ الـ opt-out كيوقف الـ contact dima، مهما قال. الرقم يقدر يعندو حتى 100 سلسلة.
POST /sequences ما كياخدش Idempotency-Key. إلا ضاع الجواب، شوف GET /sequences قبل ما تصاوب من جديد، باش ما يبقاش عندك جوج.
صيفط الأرقام (numbers)، الأرقام مع الأسامي (contacts)، كاع الـ contacts ديال شريحة محفوظة (segment_id)، ولا كاع الـ contacts لي عندهم tag (tag)، حتى 5000 فكل نداء. ابدا بـ "dry_run": true: كيحسب شكون غيتسجل ومايسجل حتى واحد.
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/sequences/12/enrolments \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contacts": [
{ "number": "61412345678", "name": "Jane" },
{ "number": "61498765432", "name": "Tom" }
],
"dry_run": true
}'async function enrol(sequenceId, contacts, dryRun = false) {
const res = await fetch(`https://api.app2email.com/v1/YOUR_NUMBER/sequences/${sequenceId}/enrolments`, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ contacts, dry_run: dryRun }),
});
return res.json();
}
const contacts = [{ number: "61412345678", name: "Jane" }, { number: "61498765432", name: "Tom" }];
console.log(await enrol(12, contacts, true)); // count only
console.log(await enrol(12, contacts)); // for realdef enrol(sequence_id, contacts, dry_run=False):
res = requests.post(
f"https://api.app2email.com/v1/YOUR_NUMBER/sequences/{sequence_id}/enrolments",
headers={"Authorization": f"Bearer {os.environ['API_KEY']}"},
json={"contacts": contacts, "dry_run": dry_run},
timeout=10,
)
return res.json()
contacts = [{"number": "61412345678", "name": "Jane"}, {"number": "61498765432", "name": "Tom"}]
print(enrol(12, contacts, dry_run=True)) # count only
print(enrol(12, contacts)) # for realشنو كتاخد (200، نفس الشكل بـ dry_run وبلاه):
{
"success": true,
"request_id": "s7enr",
"sequence_id": 12,
"enrolled": 2,
"already_in_it": 0,
"on_do_not_call_list": 0,
"not_a_number": 0,
"first_step_at": "2026-11-19T01:00:00.000Z",
"note": null
}من بعد صيفط نفس الـ body بلا dry_run. الـ contacts لي فلائحة Do Not Call، والـ contacts لي دخلو السلسلة ديجا، وأي شي ماشي رقم هاتف، كيتجاوزو وكيتحسبو. هادشي كيخلي النداء آمن يتعاود: الـ contact ما كيتسجلش مرتين أبدا. first_step_at هو الوقت لي غتخرج فيه أول خطوة.
فالكود ديال التسجيل ديالك، سجّل كل زبون جديد ملي يسجل، بسميتو، باش الترحيب يوصلو فالحين.
نداء وحد (ولا زيدو فصفحة مفتاح API تحت Webhooks). خزن السر whsec_... لي كيجي فالجواب: هو لي كيمضي كل حدث.
curl -X POST https://api.app2email.com/v1/YOUR_NUMBER/webhooks \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://www.example.com/whatsapp/webhook"}'كل webhook كيوصلو كاع أنواع الأحداث؛ الكود ديالك كيختار sequence.finished وlink.clicked والباقي لي تحت حسب type، وكيجاوب 2xx للباقي فـ 10 ثواني. كيفاش تسيطو وتشيك على الإمضاء، مع tunnel لكمبيوترك: صاوب chatbot ديال WhatsApp بالـ API.
ما عندكش عنوان عام؟ GET /events?wait=25&types=sequence.finished (صلاحية messages:read) كيجيب نفس الأحداث.
GET /sequences/{id} فيه الأرقام والتقرير لكل خطوة. GET /sequences/{id}/enrolments فيه كل contact.
curl https://api.app2email.com/v1/YOUR_NUMBER/sequences/12 \
-H "Authorization: Bearer YOUR_API_KEY"
# who is still in it, with the next step and when it is due
curl "https://api.app2email.com/v1/YOUR_NUMBER/sequences/12/enrolments?status=active&limit=100" \
-H "Authorization: Bearer YOUR_API_KEY"const headers = { Authorization: `Bearer ${process.env.API_KEY}` };
const { sequence } = await (await fetch("https://api.app2email.com/v1/YOUR_NUMBER/sequences/12", { headers })).json();
console.log(sequence.counts);
for (const row of sequence.report) console.log(row.template_name, row.delivered, row.read, row.clicked);
const { enrolments } = await (await fetch(
"https://api.app2email.com/v1/YOUR_NUMBER/sequences/12/enrolments?status=active&limit=100", { headers })).json();
for (const e of enrolments) console.log(e.contact, e.steps_sent, e.next_at);headers = {"Authorization": f"Bearer {os.environ['API_KEY']}"}
sequence = requests.get("https://api.app2email.com/v1/YOUR_NUMBER/sequences/12", headers=headers, timeout=10).json()["sequence"]
print(sequence["counts"])
for row in sequence["report"]:
print(row["template_name"], row["delivered"], row["read"], row["clicked"])
enrolments = requests.get("https://api.app2email.com/v1/YOUR_NUMBER/sequences/12/enrolments",
params={"status": "active", "limit": 100}, headers=headers, timeout=10).json()["enrolments"]
for e in enrolments:
print(e["contact"], e["steps_sent"], e["next_at"])شنو كتاخد من GET /sequences/12 بعد سيمانة (مختصر: steps محذوفة):
{
"success": true,
"request_id": "s3get",
"sequence": {
"id": 12,
"name": "Welcome series",
"status": "active",
"stop_on_reply": true,
"enrol_tag": "",
"counts": { "enrolled": 120, "active": 64, "finished": 31, "stopped": 25, "stopped_by_reply": 21, "opted_out": 3 },
"report": [
{ "step_id": 31, "position": 0, "template_name": "welcome_new_customer", "posted": 120, "sent": 120, "delivered": 118, "read": 97, "failed": 2, "clicked": 0, "clicks": 0,
"report_url": "https://www.app2email.com/dashboard/log/broadcast/k3XbQ9rTzP2mWv7a1c9e" },
{ "step_id": 32, "position": 1, "template_name": "plant_care_tips", "posted": 81, "sent": 81, "delivered": 80, "read": 66, "failed": 0, "clicked": 29, "clicks": 41,
"report_url": "https://www.app2email.com/dashboard/log/broadcast/m7TqW2xRb9LpZc4d8e1f" },
{ "step_id": 33, "position": 2, "template_name": "welcome_offer", "posted": 34, "sent": 34, "delivered": 34, "read": 30, "failed": 0, "clicked": 12, "clicks": 15,
"report_url": "https://www.app2email.com/dashboard/log/broadcast/p2HsK8vYc3NwQf6g9h2j" }
]
}
}counts: شحال تسجلو، شحال مازالين فيها، شحال وصلو لكاع الخطوات (finished)، ولا خرجو بدري (stopped، ومنهم stopped_by_reply لي جاوبو وopted_out لي دارو opt-out).report، لكل خطوة: posted، sent، delivered، read، failed، وclicked (الـ contacts لي كليكاو على رابط مُتتبَّع ديال الخطوة؛ clicks كيحسب كاع الكليكات).report_code فـ steps من بعد أول صيفطة. GET /broadcasts/{code} بيه كيعطيك نتيجة هاديك الخطوة لكل رقم، بحال تقرير الحملة؛ report_url كيحلها فـ dashboard.تسجيل وحد من GET /sequences/12/enrolments:
{
"success": true,
"request_id": "s6enl",
"sequence_id": 12,
"enrolments": [
{
"id": 501,
"contact": "61412345678",
"name": "Jane",
"status": "active",
"stop_reason": null,
"steps_sent": 1,
"next_step": 2,
"next_at": "2026-11-21T01:00:00.000Z",
"last_sent_at": "2026-11-19T01:00:00.000Z",
"enrolled_at": "2026-11-19T01:00:00.000Z",
"enrolled_by": "api",
"finished_at": null,
"history": [
{ "step": 31, "position": 0, "at": "2026-11-19T01:00:00.000Z", "ok": true, "error": "" }
]
}
]
}status هي active ولا finished ولا stopped؛ stop_reason كيقول علاش خرج الـ contact. history فيه كل محاولة لكل خطوة: ok: false مع error ملي الخطوة ما قدرتش تخرج. limit من 1 حتى 500 (الافتراضي 100)، والأحدث هو الأول.
لـ Jane، لي تسجلات فـ 19 نونبر:
اليوم 0: "Hi Jane, welcome to Green Leaf Plants!" كيوصلها بعد لحظة من التسجيل. الـ webhook ديالك كيوصلو أحداث message.status ليها (sent، delivered، read)، بحال أي رسالة أخرى.
اليوم 2: نصيحة العناية كتوصل. رابطها هو الرابط الخاص ديالها المُتتبَّع (https://www.app2email.com/l/...). ملي تحلو، الـ webhook ديالك كيوصلو link.clicked مع السلسلة والخطوة:
{
"id": "evt_Cmp3k9m2Lw8Rt5Yp1Zs03",
"type": "link.clicked",
"created": "2026-11-21T08:12:00.000Z",
"number": "4976659348270",
"data": {
"contact": "61412345678",
"url": "https://www.example.com/plant-care",
"broadcast_code": null,
"sequence_id": 12,
"step_id": 32,
"first_click": true,
"clicks": 1,
"browser": "Safari",
"timestamp": "2026-11-21T08:12:00.000Z"
}
}link.clicked كيجي على كل كليك؛ first_click كيكون true غير فأول كليك ديالها. معاينات الروابط والـ crawlers ما كيتحسبوش.
اليوم 7: العرض كيوصل. ملي تكون هي الخطوة الأخيرة، الـ webhook ديالك كيوصلو sequence.finished بـ result completed:
{
"id": "evt_Cmp3k9m2Lw8Rt5Yp1Zs02",
"type": "sequence.finished",
"created": "2026-11-26T01:00:00.000Z",
"number": "4976659348270",
"data": {
"sequence_id": 12,
"sequence": "Welcome series",
"contact": "61412345678",
"result": "completed",
"reason": null,
"steps_sent": 3,
"steps": 3,
"enrolled_at": "2026-11-19T01:00:00.000Z",
"by": "api",
"timestamp": "2026-11-26T01:00:00.000Z"
}
}ملي تجاوب فاليوم 3 ("Do you deliver on Saturdays?")، الـ webhook ديالك كيوصلو message.received، شاتها كيبان فـ Inbox، والعرض ما كيتصيفطش. sequence.finished كيجي بـ result stopped، وreason replied، وsteps_sent 2. شي واحد (ولا البوت ديالك) كيجاوبها فالنافذة ديال 24 ساعة لي فتحتها رسالتها. شوف سلّم الشات من البوت لشي واحد وبالعكس.
ملي تكتب STOP (ولا تكليك على "Stop promotions")، كتمشي لائحة Do Not Call فالحين. الـ webhook ديالك كيوصلو contact.opted_out، وsequence.finished مع reason opted_out.
كاع الأسباب ديال result stopped:
reason | شنو وقع |
|---|---|
replied | الـ contact جاوب (غير ملي يكون stop_on_reply true) |
opted_out | الـ contact دار opt-out |
removed | حيدتيه بـ DELETE /sequences/{id}/enrolments/{contact} |
sequence_deleted | مسحتي السلسلة |
failed، not_allowed | خطوة ما قدرتش تخرج لهاد الـ contact. history ديال التسجيل فيه error ديال الخطوة |
وقف الكل فين ما كانو بـ PUT /sequences/{id} و{"status": "paused"}؛ {"status": "active"} كيكمل. صيفط غير اللي كيتبدل. الجواب هو السلسلة كاملة.
curl -X PUT https://api.app2email.com/v1/YOUR_NUMBER/sequences/12 \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"status": "paused"}'بدّل الخطوات بـ steps فنفس النداء. كيبدّل اللائحة كاملة، بالترتيب: صيفط id ديال الخطوة باش تحافظ عليها وعلى تقريرها، والخطوة بلا id كتكون جديدة، والخطوة لي ما تزادش كتتمسح. الـ contacts لي عدّاو آخر خطوة كيكملو. هنا العرض كينتقل من اليوم 7 لليوم 10:
curl -X PUT https://api.app2email.com/v1/YOUR_NUMBER/sequences/12 \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"steps": [
{ "id": 31, "wait_days": 0, "template_name": "welcome_new_customer", "language": "en", "parameters": { "body": ["{name}"] } },
{ "id": 32, "wait_days": 2, "template_name": "plant_care_tips", "language": "en", "parameters": { "body": ["{name}", "https://www.example.com/plant-care"] } },
{ "id": 33, "wait_days": 8, "template_name": "welcome_offer", "language": "en", "parameters": { "body": ["{name}", "WELCOME10", "https://www.example.com/shop"] } }
]
}'حيّد contact وحد، مثلا ملي يشري قبل ما يوصل العرض:
curl -X DELETE https://api.app2email.com/v1/YOUR_NUMBER/sequences/12/enrolments/61412345678 \
-H "Authorization: Bearer YOUR_API_KEY"{
"success": true,
"request_id": "s8rem",
"sequence_id": 12,
"contact": "61412345678",
"status": "stopped",
"stop_reason": "removed"
}من بعد كيجي sequence.finished بـ reason removed. الـ contact لي ماشي فالسلسلة دابا كيجاوب 404 enrolment_not_found.
أرشف السلسلة بـ DELETE /sequences/{id}. كاع لي فيها كيوقفو (sequence.finished بـ reason sequence_deleted لكل واحد)، والتقرير كيبقى: GET /sequences?all=true كيبقى كيعرضها.
{
"success": true,
"request_id": "s5del",
"id": 12,
"status": "archived",
"stopped": 4
}بدل ما تنادي POST /sequences/{id}/enrolments من كود التسجيل ديالك، عطي السلسلة enrol_tag. الـ contacts لي كياخدو هاد الـ tag من دابا، كيتسجلو من طرف app2email، كل واحد مرة وحدة. "" كيطفيه. الـ contacts لي عندهم الـ tag قبل ما ما كيتسجلوش؛ سجّلهم مرة وحدة بـ {"tag": "new-customer"} إلا بغيتهم هوما كذلك.
curl -X PUT https://api.app2email.com/v1/YOUR_NUMBER/sequences/12 \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"enrol_tag": "new-customer"}'من بعد، حط tag على الـ contact ملي يسجل (صلاحية contacts:manage). الـ tags لي كتصيفط كتبدل tags الـ contact، فصيفط اللائحة كاملة:
curl -X PATCH https://api.app2email.com/v1/YOUR_NUMBER/contacts/61412345678 \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Jane", "tags": ["new-customer"]}'enrol_tag_since فالسلسلة كيبين من إمتى الـ tag كيحسب. الـ contacts كيقدرو كذلك يتسجلو من dashboard ولا من automation.
Handler صغير كيشيك على الإمضاء، كيتجاهل الأحداث لي شافهم، وكيسجل شكون خلّص وشكون كليكا. عيّن WEBHOOK_SECRET على قيمة whsec_... ديال الـ webhook ديالك.
// Node.js 18 or newer. npm install express then node drip-events.mjs
import crypto from "node:crypto";
import express from "express";
const { WEBHOOK_SECRET, PORT = 3000 } = process.env;
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]);
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)));
}
const app = express();
app.post("/whatsapp/webhook", express.raw({ type: "application/json" }), (req, res) => {
if (!verify(req.body, req.get("X-App2email-Signature"), WEBHOOK_SECRET)) return res.sendStatus(401);
const event = JSON.parse(req.body);
if (event.test || done.has(event.id)) return res.sendStatus(200);
const d = event.data;
if (event.type === "sequence.finished") {
// result completed, or stopped with reason replied | opted_out | removed | failed | not_allowed | sequence_deleted
console.log(`sequence ${d.sequence_id}: ${d.contact} ${d.result} ${d.reason ?? ""} after ${d.steps_sent}/${d.steps} steps`);
} else if (event.type === "link.clicked" && d.sequence_id && d.first_click) {
console.log(`sequence ${d.sequence_id} step ${d.step_id}: ${d.contact} opened ${d.url}`);
} else if (event.type === "contact.opted_out") {
console.log(`${d.number} opted out (${d.source}): mark it in your CRM too`);
}
done.add(event.id);
res.sendStatus(200);
});
app.listen(PORT, () => console.log(`listening on http://localhost:${PORT}/whatsapp/webhook`));# Python 3.9 or newer. pip install flask then flask --app drip_events run --port 3000
import hashlib, hmac, json, os, re, time
from flask import Flask, request
SECRET = os.environ["WEBHOOK_SECRET"]
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 "")
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)
app = Flask(__name__)
@app.post("/whatsapp/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)
if event.get("test") or event["id"] in done:
return "", 200
d = event["data"]
if event["type"] == "sequence.finished":
# result completed, or stopped with reason replied | opted_out | removed | failed | not_allowed | sequence_deleted
print(f"sequence {d['sequence_id']}: {d['contact']} {d['result']} {d.get('reason') or ''} after {d.get('steps_sent')}/{d.get('steps')} steps")
elif event["type"] == "link.clicked" and d.get("sequence_id") and d.get("first_click"):
print(f"sequence {d['sequence_id']} step {d['step_id']}: {d['contact']} opened {d['url']}")
elif event["type"] == "contact.opted_out":
print(f"{d['number']} opted out ({d['source']}): mark it in your CRM too")
done.add(event["id"])
return "", 200حسب التكلفة بـ حاسبة أثمان WhatsApp. من بعد، meta_pricing فـ GET /usage كيحسب رسايل الشهر ديال الفوترة حسب كاتيغوري Meta مع تكلفة تقريبية، وpricing فأحداث message.status كيبين كيفاش Meta حسب كل رسالة.
صادق الـ templates قبل التسجيل. كل template ديال كل خطوة خاصها تكون APPROVED باللغة ديال الخطوة. الخطوة لي ما تقدرش تتصيفط كتبان ok: false مع error فـ history ديال التسجيل، والـ contact يقدر يخرج بـ reason failed. راقب template.status_changed: الـ template لي Meta يوقفها ولا يعطّلها من بعد ما تقدر تتصيفط كذلك.
غير الناس لي وافقو. سجّل الزبناء لي عطاوك موافقة على رسايل WhatsApp التسويقية. الـ contacts لي فلائحة Do Not Call كيتجاوزو ملي يتسجلو، والـ opt-out فوسط السلسلة كيوقفها فالحين. ومع قاعدة opt-in مفعّلة (PUT /settings/optin)، خطوات MARKETING كيتصيفطو غير للأرقام لي عندها سجل opt-in؛ سجّلهم بـ POST /optins.
خلي STOP فالـ footer. كل template تسويقية كتقول كيفاش توقف. بزاف د الـ blocks والتقارير كيخفضو تقييم الجودة ديالك، والتقييم الواطي يقدر يوقف template ويخفض حد الرسايل ديالك. GET /health كيبين quality_rating.
خلي stop_on_reply مفعّل. الزبون لي كيكتب ليك كيبغي جواب، ماشي الخطوة الجاية. جاوبو فـ Inbox ولا من البوت ديالك، فالنافذة ديال 24 ساعة لي فتحتها رسالته.
شيك على كل حدث. شيك على X-App2email-Signature على الـ body الخام بالسر whsec_... ديال الـ webhook، بطريقة constant time، وارفض t لي عمرو تجاوز 5 دقايق. الكود لي فوق كيدير هادشي.
حيّد التكرار بـ id الحدث. خزن id ديال كل حدث تعالج (وكذلك فـ header X-App2email-Delivery) على الأقل يومين: الـ webhook لي ما جاوبش 2xx كيتصيفطّ ليه نفس الحدث من بعد، بنفس الـ id. للسجلات ديالك، مكان الـ contact فالسلسلة هو الزوج sequence_id وcontact؛ كل كليك هو step_id وcontact وclicks.
عاود التسجيل بأمان. نداءات السلسلة ما كياخدوش Idempotency-Key. POST /sequences/{id}/enrolments آمن يتصيفط مرة أخرى: الـ contacts لي دخلو السلسلة ديجا كيتجاوزو وكيتحسبو فـ already_in_it. ما تعاودش POST /sequences بلا تفكير؛ شوف GET /sequences قبل.
احترم الحدود. حتى 5000 contact فكل نداء تسجيل (400 sequence_too_many_contacts فوق هادشي)، 20 خطوة فكل سلسلة، 100 سلسلة لكل رقم. كل جواب فيه X-RateLimit-Limit، X-RateLimit-Remaining وX-RateLimit-Reset؛ فوق الحد كتجيك 429 rate_limited مع Retry-After. شوف الحدود.
أقل صلاحية. الكود لي كيسجل الزبناء الجداد خاصو messages:send غير. خلي المفتاح فالسيرفر ديالك، ماشي فصفحة ويب ولا فـ log.
| اللي كتشوف | علاش | الحل |
|---|---|---|
403 sequences_not_enabled | باقة الرقم ما فيهاش السلاسل ديال drip | كاينين فباقات Standard وProfessional وفالتجربة: بدّل الباقة فصفحة الفوترة |
403 sequence_personal_number | الرقم رقم WhatsApp شخصي مربوط بـ QR، وهادا ما يقدرش يصيفط templates | استعمل رقم WhatsApp Business API |
403 plan_not_allowed، service_not_live | ما كاينش باقة مع الـ API، ولا الخدمة موقوفة | اختار باقة؛ الخدمة الموقوفة كترجع شغالة بزر "Go Live" فصفحة Settings |
403 insufficient_scope | المفتاح ما عندوش صلاحية (الرسالة كتسميها) | استعمل مفتاح فيه messages:send (وmessages:read للتقارير) |
403 sandbox_key | مفتاح sandbox ما يقدرش يصاوب ولا يبدل ولا يمسح سلاسل، ولا يسجل بجد | استعمل مفتاح عادي؛ مع مفتاح sandbox غير القراءة وتسجيلات dry_run كيخدمو |
403 not_in_instant_sandbox | الرقم ديال التجربة ما عندوش سلاسل | استعمل مفتاح لرقمك المربوط |
400 invalid_sequence | السلسلة ولا خطوة ماشي صحيحة (template_name ناقص، وقفة فوق 90 يوم، أكثر من 20 خطوة ...) | صلّح اللي كتسميه الرسالة؛ error.details.problems كيعطيك كاع المشاكل |
409 sequence_limit | الرقم عندو 100 سلسلة | امسح اللي ما بقاش كتستعملها |
409 sequence_empty | السلسلة ما فيهاش خطوات | زيد خطوات بـ PUT /sequences/{id} قبل ما تسجل |
400 sequence_no_contacts | ما كاين حتى واحد باش يتسجل: لا أرقام، لا contacts، لا شريحة، لا tag فيه contacts | صيفط numbers، contacts، segment_id ولا tag فيه contacts |
400 sequence_too_many_contacts | أكثر من 5000 contact فنداء وحد | صيفطهم فمجموعات صغار |
404 sequence_not_found | ما كاينش هاد السلسلة فهاد الرقم، ولا تمسحات | GET /sequences كيعرضها |
404 enrolment_not_found | الـ contact ماشي فالسلسلة دابا | GET /sequences/{id}/enrolments?status=active كيعرض شكون فيها |
enrolled هو 0، ولا on_do_not_call_list ولا already_in_it ماشي 0 | الـ contacts دارو opt-out، ولا دخلو السلسلة ديجا | ماكاينش شي يتصلح: contact ما كيتسجلش مرتين أبدا، وما كيتسجلش ضد opt-out |
history كيبين ok: false، ولا sequence.finished بـ reason failed ولا not_allowed | خطوة ما قدرتش تخرج لهاد الـ contact، مثلا template ماشي موافَق عليها، ولا ما كاين سجل opt-in ومع قاعدة opt-in مفعّلة | اقرا error فـ history؛ وافق على الـ template ولا صلّحها، ولا سجّل الـ opt-in |
429 rate_limited | نداءات زايدة بزاف لهاد المفتاح | استنى Retry-After ثانية، من بعد عاود |
503 sequences_not_ready | السلاسل ديال drip ماشي متوفرين دابا | عاود من بعد؛ إلا بقا هادشي، تواصل مع support@app2email.com مع request_id |
كل جواب فيه request_id. GET /requests/{id} كيبين شنو تسجل ليه، و support@app2email.com كيقدر يلقاه كذلك. كاع الأكواد: Errors.
سيرفر MCP https://api.app2email.com/mcp/sequences عندو نفس النداءات بحال أدوات: list_sequences، get_sequence، create_sequence، update_sequence، delete_sequence، enrol_in_sequence، list_sequence_enrolments وremove_from_sequence. الوكيل يقدر من بعد يجاوب على "كيفاش كتمشي سلسلة الترحيب؟" ولا "حيد فلان من داكشي، شرا دابا". شوف خلّي وكيل AI يسير WhatsApp بـ MCP وMCP.
template تسويقية وحدة لائحة أو شريحة، مع سجلات الموافقة ولائحة Do Not Call.
صاوب template، خليها توافق عليها، وصيفطها ملي يتصيفط الطلب.
Contacts بأسامي وtags وموافقة، محدّثين من نظامك.
ملي زبون يجاوب على خطوة، خلي فريقك ياخد الشات.