תיעוד מלא של כל ה-API endpoints של מערכת Communication Hub עם דוגמאות קוד, פרמטרים ותגובות.
/api/communication-hub
ניהול הודעות - שליחה, קריאה, עדכון ומחיקה
קבלת רשימת הודעות עם תמיכה בסינון, חיפוש ועימוד
| שם | סוג | חובה | תיאור |
|---|---|---|---|
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();
{
"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
}
}
שליחת הודעה חדשה דרך ערוץ תקשורת
| שם | סוג | חובה | תיאור |
|---|---|---|---|
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'
}
})
});
{
"success": true,
"message_id": 456,
"status": "queued",
"estimated_delivery": "2025-11-30T10:35:00Z"
}
קבלת פרטי הודעה בודדת
{
"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
}
}
}
ניסיון חוזר לשליחת הודעה שנכשלה
{
"success": true,
"message": "Message queued for retry",
"attempt_number": 2
}
ניהול תבניות הודעות
קבלת רשימת תבניות
| שם | סוג | תיאור |
|---|---|---|
channel |
string | סינון לפי ערוץ |
category |
string | קטגוריה: marketing, transactional, notification |
is_active |
boolean | סינון לפי סטטוס פעיל |
יצירת תבנית חדשה
{
"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
}
תצוגה מקדימה של תבנית עם משתנים
{
"variables": {
"customer_name": "ישראל ישראלי",
"order_id": "12345",
"delivery_date": "01/12/2025"
}
}
{
"success": true,
"preview": {
"subject": "הזמנה #12345 אושרה",
"content": "שלום ישראל ישראלי,\n\nהזמנתך מספר 12345 אושרה...",
"html_content": "<h1>שלום ישראל ישראלי</h1>..."
}
}
הגדרה וניהול ערוצי תקשורת
קבלת רשימת ערוצים מוגדרים
{
"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
}
]
}
הגדרת ערוץ תקשורת חדש
{
"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
}
{
"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
}
בדיקת חיבור ושליחת הודעת בדיקה
// Request
{
"test_recipient": "admin@example.com"
}
// Response
{
"success": true,
"message": "Test message sent successfully",
"test_id": "test_abc123"
}
ניהול קמפיינים ושליחה המונית
קבלת רשימת קמפיינים
יצירת קמפיין חדש
{
"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
}
}
הפעלת קמפיין
השהיית קמפיין
סטטיסטיקות קמפיין
{
"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
}
}
סטטיסטיקות ודוחות
נתוני 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
}
}
}
נתונים לגרף לפי זמן
| שם | תיאור |
|---|---|
period |
day, week, month, year |
channel |
סינון לפי ערוץ (אופציונלי) |
metric |
sent, delivered, opened, clicked |
עדכונים בזמן אמת
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"
}
}
}