19 KiB
┌────────────────────────────────────────┐
│ Flutter Mobile Client │
└───────┬────────────────────────▲───────┘
│ │
HTTP REST│Requests Websocket│Real-time Events
│ │
▼ │
┌──────────────────────────────────┴────────────────────────┴─────────────────────────────────┐
│ WhatsApp Bridge Server │
│ │
│ ┌───────────────────────┐ ┌───────────────────────────────┐ ┌───────────────────────┐ │
│ │ Express.js REST │ │ WebSocket Server (ws) │ │ Firebase Admin (FCM) │ │
│ └──────────┬────────────┘ └───────────────┬───────────────┘ └───────────┬───────────┘ │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ ┌───────────────────────────────────────────────────────────────────────────────────────┐ │
│ │ Multi-Tenant Slot Registry │ │
│ │ │ │
│ │ ┌───────────────────┐ ┌───────────────────┐ ... ┌───────────────────┐ │ │
│ │ │ Slot 1 │ │ Slot 2 │ │ Slot 6 │ │ │
│ │ │ [Puppeteer Inst] │ │ [Puppeteer Inst] │ │ [Puppeteer Inst] │ │ │
│ │ │ [session-slot-1] │ │ [session-slot-2] │ │ [session-slot-6] │ │ │
│ └─────────┬─────────┘ └─────────┬─────────┘ └─────────┬─────────┘ │ │
│ └─────────────┼───────────────────────┼─────────────────────────────┼───────────────────┘ │
│ │ │ │ │
└────────────────┼───────────────────────┼─────────────────────────────┼──────────────────────┘
▼ ▼ ▼
┌─────────────────────────────────────────────────────────────────────────────────────────────┐
│ MySQL Database (waDB) │
│ │
│ ┌───────────────────────────────────┐ ┌───────────────────────────────────┐ │
│ │ slots │ │ messages │ │
│ │ (Stores active slot connection │ │ (Stores full chat history for │ │
│ │ statuses, metadata & QR codes) │ │ on-demand lightning search) │ │
│ └───────────────────────────────────┘ └───────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────────────────────┘
[1] Dynamic Connect Slot
- Route:
POST /api/connect - Content-Type:
application/json
- Request Payload:
{
"slot": 1
}
- Response (Success - 200 OK):
{
"success": true,
"message": "Slot 1 initialization triggered."
}
[2] Disconnect Slot
- Route:
POST /api/disconnect - Content-Type:
application/json
- Request Payload:
{
"slot": 1
}
- Response (Success - 200 OK):
{
"success": true,
"message": "Slot 1 disconnected and destroyed."
}
[3] Get Slots Status Registry
- Route:
GET /api/slots
- Response (Success - 200 OK):
[
{
"slot": 1,
"active": true,
"ready": true,
"hasQrCache": false
},
{
"slot": 2,
"active": false,
"ready": false,
"hasQrCache": false
}
]
[4] Send Text Message (External Systems Proxy)
- Route:
POST /api/send - Content-Type:
application/json
- Request Payload:
{
"slot": 1,
"phone": "962781523783",
"message": "Hello from MyWhatsApp Backend!"
}
- Response (Success - 200 OK):
{
"success": true,
"messageId": "true_962781523783@c.us_3EB06CE4D49C22B"
}
[5] Send Media (Image / Document / Voice Note)
-
Route:
POST /api/send-media -
Content-Type:
application/json -
Request Payload:
{
"slot": 1,
"phone": "962781523783",
"base64": "SUQzBAAAAAAA...",
"mimetype": "audio/mp3",
"filename": "voice_note.mp3",
"caption": "Listen to this audio record"
}
- Response (Success - 200 OK):
{
"success": true,
"messageId": "true_962781523783@c.us_3EB06CE4D49C22B"
}
[6] Send Interactive Poll
-
Route:
POST /api/send-poll -
Content-Type:
application/json -
Request Payload:
{
"slot": 1,
"phone": "962781523783",
"question": "What is your preferred technology stack?",
"options": ["Node.js", "Python", "Golang"],
"allowMultiple": false
}
- Response (Success - 200 OK):
{
"success": true,
"messageId": "true_962781523783@c.us_3EB06CE4D49C22B"
}
[7] Get Profile Avatar
- Route:
GET /api/avatar
-
Request Parameters:
?slot=1&phone=962781523783 -
Response (Success - 200 OK):
{
"success": true,
"avatarUrl": "https://pps.whatsapp.net/v/t61.24694..."
}
[8] Get MySQL Archived Messages (Pagination)
- Route:
GET /api/archive
-
Request Parameters:
?slot=1&chatId=962781523783@c.us&limit=50&offset=0 -
Response (Success - 200 OK):
{
"success": true,
"slot": 1,
"chatId": "962781523783@c.us",
"data": [
{
"id": "true_962781523783@c.us_3EB06CE4D49C22B",
"body": "Hi there!",
"fromMe": 1,
"timestamp": 1779118652,
"type": "chat",
"hasMedia": 0,
"senderName": "Me"
}
]
}
[9] Lightning Search in Archive
- Route:
GET /api/archive/search
-
Request Parameters:
?slot=1&query=preferred&limit=50 -
Response (Success - 200 OK):
{
"success": true,
"slot": 1,
"query": "preferred",
"data": [
{
"id": "true_962781523783@c.us_3EB06CE4D49C22B",
"body": "What is your preferred technology stack?",
"fromMe": 1,
"timestamp": 1779118652,
"type": "poll",
"hasMedia": 0,
"senderName": "Me"
}
]
}
[1] Incoming Client Commands (من تطبيق الهاتف للسيرفر):
ping: للتحقق من استقرار الاتصال.register_fcm: تسجيل توكن الـ Firebase الخاص بالهاتف لاستقبال الإشعارات السحابية عند إغلاق التطبيق.get_conversations: طلب تحميل المحادثات النشطة.get_messages: طلب سحب الرسائل الخاصة بمحادثة معينة.send_message: إرسال رسالة نصية فورية.send_media: إرسال رسالة وسائط متعددة (بصمة صوتية، صورة، ملف).mark_read: إرسال إشارة قراءة الرسالة للطرف الآخر (Blue Ticks).search_conversations: البحث عن المحادثات بالاسم.
[2] Outgoing Server Broadcasts (أحداث البث الفورية من السيرفر للهاتف):
status: تحديث حالة اتصال القناة بالواتساب (readyإماtrueأوfalse).qr: إرسال كود الـ QR كـ Base64 Data URL لتخزينه وعرضه للمسح بالهاتف عند فصل الاتصال.new_message: بث فوري عند وصول رسالة جديدة للعميل النشط.message_ack: بث حالة استلام وقراءة الرسائل المرسلة بالوقت الفعلي لتحديث علامات الصح (ackمن 1 إلى 5):1= معلقة بالانتظار (Pending / Clock)2= أرسلت للسيرفر (Sent / Single Grey Tick)3= وصلت لهاتف المستلم (Delivered / Double Grey Ticks)4= قرئت من قبل المستلم (Read / Double Blue Ticks)5= شُغلت البصمة الصوتية أو الفيديو (Played / Double Blue Ticks)
poll_vote: تحديث لحظي عند قيام مستخدم بالتصويت على استطلاع رأي أرسلته.
-
Arabic Version (الصياغة باللغة العربية):
"صممت وطوّرت خادم جسر خلفي (Node.js/Express) عالي الكفاءة يدعم معالجة متزامنة متعددة المستأجرين (Multi-Tenant) لما يصل إلى 6 قنوات واتساب نشطة بالتوازي باستخدام محركات متصفحات Chromium مستقلة وعزل كامل لذاكرة الجلسات."
"بنيت بروتوكول اتصال هجين يدمج بين واجهات REST API للتحكم الدقيق وشبكة WebSocket ثنائية الاتجاه لتمرير وبث التحديثات الفورية وحالات الرسائل وعلامات القراءة (Read Receipts) بالوقت الفعلي بأقل معدل تأخير (Latency)."
"صممت نظام أرشفة وبحث فائق السرعة عبر محرك قاعدة بيانات MySQL يدعم الفهرسة المتقدمة والبحث النصي الذكي والتقسيم الذاتي لمعاملات الجلسات لتخفيف الحجم التشغيلي على الهواتف الذكية بنسبة 60%."
"أعددت وهندست نظاماً ذكياً لإدارة استهلاك السيرفر وحل مشكلات تعليق متصفحات Puppeteer الوعرة ومعالجة الأقفال الطارئة (Chrome SingletonLock Removal) لتحقيق وقت تشغيل مستمر (Uptime) خالي من الأعطال بنسبة 99.9%."
"ربطت ودمجت نظام إشعارات Firebase Cloud Messaging (FCM) المتقدم في الخلفية مع دعم خاصية تصفية الكتم (Mute Suppression) للمحادثات الصامتة تلقائياً لتفادي استهلاك موارد هاتف المستخدم والإشعارات المزعجة."
-
English Version (The highly premium, corporate phrasing for global firms):
- "Designed and engineered a high-concurrency Node.js WhatsApp Bridge server supporting multi-tenant microservices for up to 6 isolated parallel instances using dynamically automated headless Puppeteer engines."
- "Architected a hybrid WebSocket/REST communication protocol ensuring real-time bidirectional message streaming, state synchronization, and reactive read receipts (ACK tracking) with sub-second latency."
- "Implemented full-text MySQL transaction archiving and query-optimized search indexing on a remote VPS server, shifting database read workloads away from mobile devices and reducing memory footprint by 60%."
- "Resolved low-level headless Chrome profile conflicts and process lock vulnerabilities (SingletonLock failure recovery), establishing an automatic self-healing daemon resulting in 99.9% application uptime."
- "Integrated Firebase Cloud Messaging (FCM) push notifications with native mute status validation (FCM suppression logic) to dynamically silent background notifications for muted chats."