API Reference

תיעוד מלא של כל ה-API endpoints של מערכת Communication Hub עם דוגמאות קוד, פרמטרים ותגובות.

Base URL: /api/communication-hub
GET
קריאת נתונים
POST
יצירה חדשה
PUT
עדכון מלא
DELETE
מחיקה

Messages API

ניהול הודעות - שליחה, קריאה, עדכון ומחיקה

GET /api/communication-hub/messages

קבלת רשימת הודעות עם תמיכה בסינון, חיפוש ועימוד

Query Parameters:
שם סוג חובה תיאור
page integer לא מספר עמוד (ברירת מחדל: 1)
per_page integer לא פריטים בעמוד (ברירת מחדל: 20)
channel string לא סינון לפי ערוץ: email, whatsapp, sms, push
status string לא סינון לפי סטטוס: pending, sent, delivered, failed
search string לא חיפוש חופשי בתוכן הודעה או נמען
date_from string לא תאריך התחלה (YYYY-MM-DD)
date_to string לא תאריך סיום (YYYY-MM-DD)
דוגמת בקשה:
// JavaScript Fetch API const response = await fetch('/api/communication-hub/messages?page=1&channel=email&status=sent', { method: 'GET', headers: { 'Authorization': 'Bearer YOUR_TOKEN', 'Content-Type': 'application/json' } }); const data = await response.json();
תגובה מוצלחת:
200 OK
{ "success": true, "messages": [ { "id": 1, "channel": "email", "recipient": "customer@example.com", "subject": "ברוכים הבאים!", "content": "תודה שהצטרפת אלינו...", "status": "sent", "priority": "normal", "created_at": "2025-11-30T10:30:00Z", "sent_at": "2025-11-30T10:30:05Z" } ], "pagination": { "page": 1, "per_page": 20, "total": 150, "pages": 8 } }
POST /api/communication-hub/messages

שליחת הודעה חדשה דרך ערוץ תקשורת

Request Body:
שם סוג חובה תיאור
channel string כן ערוץ: email, whatsapp, sms, push
recipient string כן כתובת נמען (מייל/טלפון)
content string כן* תוכן ההודעה (או template_id)
template_id integer לא מזהה תבנית (במקום content)
variables object לא משתנים להחלפה בתבנית
subject string לא נושא (נדרש ל-email)
priority string לא עדיפות: low, normal, high, urgent
scheduled_at string לא תזמון שליחה (ISO 8601)
customer_id integer לא קישור ללקוח במערכת
דוגמת בקשה:
// שליחת Email const response = await fetch('/api/communication-hub/messages', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_TOKEN', 'Content-Type': 'application/json' }, body: JSON.stringify({ channel: 'email', recipient: 'customer@example.com', subject: 'הזמנה #12345 אושרה', content: 'שלום רב, הזמנתך אושרה ותישלח בקרוב.', priority: 'normal', customer_id: 123 }) }); // שליחה עם תבנית const response = await fetch('/api/communication-hub/messages', { method: 'POST', headers: { ... }, body: JSON.stringify({ channel: 'whatsapp', recipient: '+972501234567', template_id: 5, variables: { customer_name: 'ישראל ישראלי', order_id: '12345', delivery_date: '01/12/2025' } }) });
תגובה מוצלחת:
201 Created
{ "success": true, "message_id": 456, "status": "queued", "estimated_delivery": "2025-11-30T10:35:00Z" }
שגיאות אפשריות:
400 Bad Request - פרמטרים חסרים
422 Unprocessable Entity - כתובת נמען לא תקינה
GET /api/communication-hub/messages/{id}

קבלת פרטי הודעה בודדת

דוגמת תגובה:
{ "success": true, "message": { "id": 456, "channel": "email", "recipient": "customer@example.com", "subject": "הזמנה #12345 אושרה", "content": "שלום רב...", "status": "delivered", "priority": "normal", "created_at": "2025-11-30T10:30:00Z", "sent_at": "2025-11-30T10:30:05Z", "delivered_at": "2025-11-30T10:30:10Z", "customer": { "id": 123, "name": "ישראל ישראלי" }, "delivery_info": { "provider_id": "msg_abc123", "attempts": 1 } } }
POST /api/communication-hub/messages/{id}/retry

ניסיון חוזר לשליחת הודעה שנכשלה

200 OK
{ "success": true, "message": "Message queued for retry", "attempt_number": 2 }

Templates API

ניהול תבניות הודעות

GET /api/communication-hub/templates

קבלת רשימת תבניות

Query Parameters:
שם סוג תיאור
channel string סינון לפי ערוץ
category string קטגוריה: marketing, transactional, notification
is_active boolean סינון לפי סטטוס פעיל
POST /api/communication-hub/templates

יצירת תבנית חדשה

Request Body:
{ "name": "אישור הזמנה", "channel": "email", "category": "transactional", "subject": "הזמנה #{{order_id}} אושרה", "content": "שלום {{customer_name}},\n\nהזמנתך מספר {{order_id}} אושרה בהצלחה.\nתאריך משלוח משוער: {{delivery_date}}\n\nתודה,\nצוות TechLabs", "html_content": "<h1>שלום {{customer_name}}</h1>...", "variables": [ { "name": "customer_name", "description": "שם הלקוח", "required": true }, { "name": "order_id", "description": "מספר הזמנה", "required": true }, { "name": "delivery_date", "description": "תאריך משלוח", "required": false } ], "is_active": true }
POST /api/communication-hub/templates/{id}/preview

תצוגה מקדימה של תבנית עם משתנים

Request Body:
{ "variables": { "customer_name": "ישראל ישראלי", "order_id": "12345", "delivery_date": "01/12/2025" } }
תגובה:
{ "success": true, "preview": { "subject": "הזמנה #12345 אושרה", "content": "שלום ישראל ישראלי,\n\nהזמנתך מספר 12345 אושרה...", "html_content": "<h1>שלום ישראל ישראלי</h1>..." } }

Channels API

הגדרה וניהול ערוצי תקשורת

GET /api/communication-hub/channels

קבלת רשימת ערוצים מוגדרים

{ "success": true, "channels": [ { "id": 1, "type": "email", "name": "SMTP ראשי", "provider": "smtp", "is_active": true, "is_default": true, "stats": { "sent_today": 45, "success_rate": 98.5 } }, { "id": 2, "type": "whatsapp", "name": "Green-API", "provider": "green-api", "is_active": true, "is_default": true } ] }
POST /api/communication-hub/channels

הגדרת ערוץ תקשורת חדש

דוגמה - הגדרת SMTP:
{ "type": "email", "name": "SMTP שירות", "provider": "smtp", "config": { "host": "smtp.example.com", "port": 587, "username": "noreply@example.com", "password": "***********", "from_email": "noreply@example.com", "from_name": "TechLabs", "use_tls": true }, "is_active": true, "is_default": false }
דוגמה - הגדרת WhatsApp:
{ "type": "whatsapp", "name": "WhatsApp Business", "provider": "green-api", "config": { "instance_id": "1234567890", "api_token": "your-api-token", "webhook_url": "https://your-domain.com/webhook/whatsapp" }, "is_active": true }
POST /api/communication-hub/channels/{id}/test

בדיקת חיבור ושליחת הודעת בדיקה

// Request { "test_recipient": "admin@example.com" } // Response { "success": true, "message": "Test message sent successfully", "test_id": "test_abc123" }

Campaigns API

ניהול קמפיינים ושליחה המונית

GET /api/communication-hub/campaigns

קבלת רשימת קמפיינים

POST /api/communication-hub/campaigns

יצירת קמפיין חדש

{ "name": "מבצע חורף 2025", "channel": "email", "template_id": 10, "segment_id": 5, "scheduled_at": "2025-12-01T09:00:00Z", "settings": { "batch_size": 100, "delay_between_batches": 60, "track_opens": true, "track_clicks": true } }
POST /api/communication-hub/campaigns/{id}/start

הפעלת קמפיין

POST /api/communication-hub/campaigns/{id}/pause

השהיית קמפיין

GET /api/communication-hub/campaigns/{id}/stats

סטטיסטיקות קמפיין

{ "success": true, "stats": { "total_recipients": 1500, "sent": 1450, "delivered": 1420, "opened": 680, "clicked": 245, "bounced": 30, "unsubscribed": 5, "open_rate": 47.9, "click_rate": 17.3, "bounce_rate": 2.1 } }

Analytics API

סטטיסטיקות ודוחות

GET /api/communication-hub/analytics/dashboard

נתוני Dashboard כלליים

{ "success": true, "stats": { "today": { "total_sent": 156, "delivered": 152, "failed": 4, "pending": 12 }, "by_channel": { "email": { "sent": 80, "rate": 97.5 }, "whatsapp": { "sent": 50, "rate": 99.0 }, "sms": { "sent": 26, "rate": 96.2 } }, "trends": { "vs_yesterday": +15, "vs_last_week": +8 } } }
GET /api/communication-hub/analytics/timeseries

נתונים לגרף לפי זמן

Query Parameters:
שם תיאור
period day, week, month, year
channel סינון לפי ערוץ (אופציונלי)
metric sent, delivered, opened, clicked

WebSocket Events

עדכונים בזמן אמת

Connection URL: wss://your-domain.com/socket.io/
אירועים זמינים:
אירוע כיוון תיאור
message_status_changed Server → Client עדכון סטטוס הודעה
new_message Server → Client הודעה חדשה נוספה
campaign_progress Server → Client התקדמות קמפיין
channel_status Server → Client שינוי סטטוס ערוץ
subscribe Client → Server הרשמה לעדכונים
דוגמת שימוש:
// התחברות ל-WebSocket const socket = io('https://your-domain.com', { transports: ['websocket'], auth: { token: 'YOUR_TOKEN' } }); // האזנה לעדכוני סטטוס socket.on('message_status_changed', (data) => { console.log(`Message ${data.message_id} status: ${data.status}`); updateMessageInUI(data.message_id, data.status); }); // האזנה להתקדמות קמפיין socket.on('campaign_progress', (data) => { updateProgressBar(data.campaign_id, data.progress); }); // הרשמה לעדכוני קמפיין ספציפי socket.emit('subscribe', { type: 'campaign', id: 123 });

קודי שגיאה

קוד שם תיאור
400 Bad Request פרמטרים חסרים או לא תקינים
401 Unauthorized נדרש אימות / טוקן לא תקין
403 Forbidden אין הרשאה לפעולה זו
404 Not Found המשאב לא נמצא
422 Unprocessable Entity שגיאת ולידציה (כתובת לא תקינה)
429 Too Many Requests חריגה ממגבלת בקשות
500 Internal Server Error שגיאת שרת פנימית
503 Service Unavailable שירות לא זמין (ספק חיצוני)
פורמט תגובת שגיאה:
{ "success": false, "error": { "code": "INVALID_RECIPIENT", "message": "כתובת המייל אינה תקינה", "details": { "field": "recipient", "value": "invalid-email" } } }