الرسائل
أرسل رسائل صادرة، اعرض رسائل صندوق، استرجع رسالة واحدة، واحذف الرسائل.
تتطلب جميع الطلبات ترويسة x-api-key. العنوان الأساسي لكل نقطة نهاية هو https://api.agentsend.io.
كائن Message
كل نقطة نهاية تُرجع رسالة تُعيد هذا الشكل.
{
"id": "msg_01hx9k2v3w4x5y6z7a8b9c0d",
"inboxId": "ibx_01hx9k2v3w4x5y6z7a8b9c0d",
"threadId": "thr_01hx9k2v3w4x5y6z7a8b9c0d",
"direction": "outbound",
"fromAddress": "agent@yourdomain.com",
"toAddresses": ["customer@example.com"],
"ccAddresses": [],
"subject": "Hello from AgentSend",
"bodyText": "This email was sent by an AI agent.",
"bodyHtml": "<p>This email was sent by an AI agent.</p>",
"delivery": "email",
"status": "delivered",
"attachments": [],
"messageIdHeader": "<msg_01hx9k2v...@agentsend.io>",
"createdAt": "2026-04-16T10:23:00.000Z"
}| الحقل | النوع | الوصف |
|---|---|---|
id | string (uuid) | المعرّف الفريد للرسالة. |
inboxId | string (uuid) | الصندوق الذي تنتمي إليه هذه الرسالة. |
threadId | string (uuid) | المحادثة التي تنتمي إليها هذه الرسالة. |
direction | enum | outbound للرسائل المرسلة، inbound للرسائل المستلمة. |
fromAddress | string | عنوان بريد المرسل. |
toAddresses | string[] | عناوين المستلمين الرئيسيين. |
ccAddresses | string[] | عناوين مستلمي CC. |
subject | string | سطر موضوع الرسالة. |
bodyText | string | null | النص العادي. |
bodyHtml | string | null | نص HTML. |
delivery | enum | email عندما يسلّم AgentSend الرسالة إلى SES، dry-run عندما تحاكي هذه البيئة التسليم دون إرسال فعلي. |
status | enum | حالة التسليم الحالية. إحدى القيم: queued، sending، sent، delivered، failed، bounced، complained، received. |
attachments | AttachmentMeta[] | مصفوفة كائنات بيانات المرفقات (id، filename، contentType، size). |
messageIdHeader | string | قيمة ترويسة Message-ID وفق RFC 5322. |
createdAt | string (ISO 8601) | وقت إنشاء الرسالة. |
إرسال رسالة
أرسل بريداً صادراً من صندوق. توضع الرسالة في قائمة الانتظار فوراً وتُرجع 202 Accepted مع كائن Message الجديد. تحقق من delivery لمعرفة ما إذا أرسلت البيئة بريداً حقيقياً (email) أو حاكته فقط (dry-run). تتوفر تحديثات حالة التسليم عبر Webhooks أو بالاستعلام الدوري لـGET /messages/{id}.
معاملات المسار
| المعامل | Type | Description |
|---|---|---|
inboxId مطلوب |
string (uuid) | معرّف الصندوق المطلوب الإرسال منه. |
جسم الطلب
| Parameter | Type | Description |
|---|---|---|
to مطلوب |
string[] | عنوان أو أكثر للمستلمين. |
subject مطلوب |
string | سطر موضوع الرسالة. الحد الأقصى 998 حرفاً. |
cc |
string[] | عناوين مستلمي CC. |
bcc |
string[] | عناوين مستلمي BCC. عناوين BCC غير مرئية للمستلمين الآخرين. |
bodyText |
string | النص العادي. يجب تقديم واحد على الأقل من bodyText أو bodyHtml. |
bodyHtml |
string | نص HTML. يولّد AgentSend بديلاً نصياً تلقائياً إذا قُدّم HTML فقط. |
threadId |
string (uuid) | أرفق هذه الرسالة بمحادثة قائمة. إذا تُركت، تُنشأ محادثة جديدة. |
attachmentIds |
string[] (uuid) | معرّفات المرفقات المرفوعة مسبقاً المطلوب تضمينها. ارفع الملفات أولاً عبر واجهة المرفقات. |
مثال على الطلب
const res = await fetch( `https://api.agentsend.io/inboxes/${inboxId}/messages`, { method: "POST", headers: { "x-api-key": process.env.AGENTSEND_API_KEY, "Content-Type": "application/json", }, body: JSON.stringify({ to: ["customer@example.com"], cc: ["manager@example.com"], subject: "Your order is confirmed", bodyText: "Hi, your order #1234 has been confirmed.", bodyHtml: "<p>Hi, your order <strong>#1234</strong> has been confirmed.</p>", attachmentIds: ["att_01hx9k2v3w4x5y6z7a8b9c0d"], }), } ); const message = await res.json(); console.log(message.id, message.status); // "msg_...", "queued"
الاستجابة — 202 Accepted
{
"id": "msg_01hx9k2v3w4x5y6z7a8b9c0d",
"inboxId": "ibx_01hx9k2v3w4x5y6z7a8b9c0d",
"threadId": "thr_01hx9k2v3w4x5y6z7a8b9c0d",
"direction": "outbound",
"fromAddress": "agent@yourdomain.com",
"toAddresses": ["customer@example.com"],
"ccAddresses": ["manager@example.com"],
"subject": "Your order is confirmed",
"bodyText": "Hi, your order #1234 has been confirmed.",
"bodyHtml": "<p>Hi, your order <strong>#1234</strong> has been confirmed.</p>",
"delivery": "email",
"status": "queued",
"attachments": [
{
"id": "att_01hx9k2v3w4x5y6z7a8b9c0d",
"filename": "invoice.pdf",
"contentType": "application/pdf",
"size": 204800
}
],
"messageIdHeader": "<msg_01hx9k2v3w4x5y6z7a8b9c0d@agentsend.io>",
"createdAt": "2026-04-16T10:23:00.000Z"
}قائمة الرسائل
تُرجع قائمة مقسَّمة لرسائل الصندوق، مرتَّبة بـcreatedAt تنازلياً. استخدم مرشّح status لاسترجاع الرسائل في حالة تسليم محددة فقط — مثلاً status=received لجلب الرسائل الواردة التي يجب أن يعالجها وكيلك.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
inboxId مطلوب |
string (uuid) | الصندوق المطلوب عرض رسائله. |
معاملات الاستعلام
| Parameter | Type | Description |
|---|---|---|
limit |
integer | عدد الرسائل المطلوب إرجاعها. الافتراضي 20. الحد الأقصى 100. |
offset |
integer | عدد الرسائل المطلوب تخطيها للترقيم. الافتراضي 0. |
status |
enum | رشّح حسب حالة التسليم. إحدى القيم: queued، sending، sent، delivered، failed، bounced، complained، received. |
Request Example
const res = await fetch( `https://api.agentsend.io/inboxes/${inboxId}/messages?status=received&limit=50`, { headers: { "x-api-key": process.env.AGENTSEND_API_KEY }, } ); const { data, total } = await res.json(); for (const msg of data) { console.log(msg.fromAddress, msg.subject); }
الاستجابة — 200 OK
{
"data": [
{
"id": "msg_01hx9k2v3w4x5y6z7a8b9c0d",
"inboxId": "ibx_01hx9k2v3w4x5y6z7a8b9c0d",
"threadId": "thr_01hx9k2v3w4x5y6z7a8b9c0d",
"direction": "inbound",
"fromAddress": "customer@example.com",
"toAddresses": ["agent@yourdomain.com"],
"ccAddresses": [],
"subject": "Re: Your order is confirmed",
"bodyText": "Thanks! Can I change the delivery address?",
"bodyHtml": null,
"status": "received",
"attachments": [],
"messageIdHeader": "<abc123@mail.example.com>",
"createdAt": "2026-04-16T10:45:00.000Z"
}
],
"total": 1,
"limit": 50,
"offset": 0
}الحصول على رسالة
استرجع رسالة واحدة حسب معرّفها. استخدم هذا لاستعلام تحديثات حالة التسليم بعد الإرسال.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id مطلوب |
string (uuid) | معرّف الرسالة المطلوب استرجاعها. |
Request Example
const res = await fetch( `https://api.agentsend.io/messages/${messageId}`, { headers: { "x-api-key": process.env.AGENTSEND_API_KEY }, } ); const message = await res.json(); console.log(message.status); // "delivered"
Response — 200 OK
تُرجع كائن Message واحداً.
{
"id": "msg_01hx9k2v3w4x5y6z7a8b9c0d",
"inboxId": "ibx_01hx9k2v3w4x5y6z7a8b9c0d",
"threadId": "thr_01hx9k2v3w4x5y6z7a8b9c0d",
"direction": "outbound",
"fromAddress": "agent@yourdomain.com",
"toAddresses": ["customer@example.com"],
"ccAddresses": [],
"subject": "Your order is confirmed",
"bodyText": "Hi, your order #1234 has been confirmed.",
"bodyHtml": "<p>Hi, your order <strong>#1234</strong> has been confirmed.</p>",
"delivery": "email",
"status": "delivered",
"attachments": [],
"messageIdHeader": "<msg_01hx9k2v3w4x5y6z7a8b9c0d@agentsend.io>",
"createdAt": "2026-04-16T10:23:00.000Z"
}حذف رسالة
احذف رسالة نهائياً. لا يمكن التراجع عن هذا الإجراء. حذف الرسالة لا يلغي إرسالها — إذا كانت قد أُرسلت بالفعل إلى المستلمين، لا يمكن استرجاعها.
حذف الرسالة الوحيدة في محادثة سيحذف تلك المحادثة أيضاً.
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id مطلوب |
string (uuid) | معرّف الرسالة المطلوب حذفها. |
Request Example
await fetch( `https://api.agentsend.io/messages/${messageId}`, { method: "DELETE", headers: { "x-api-key": process.env.AGENTSEND_API_KEY }, } ); // 204 No Content
الاستجابة — 204 No Content
تُرجع جسماً فارغاً عند النجاح.
حالات التسليم
يتنقل حقل status عبر الحالات التالية للرسائل الصادرة. تصل الرسائل الواردة بـstatus: "received".
| الحالة | Description |
|---|---|
queued | تم قبول الرسالة وتنتظر الإرسال. |
sending | جاري إرسالها إلى خادم بريد المستلم. |
sent | قبلها خادم بريد المستلم. |
delivered | تأكيد التسليم إلى صندوق المستلم (حيث يدعم ذلك). |
failed | فشل تسليم دائم. تحقق من أحداث webhook للتفاصيل. |
bounced | ارتداد حاد — العنوان غير موجود أو رفض الخادم التسليم. |
complained | وسم المستلم الرسالة كبريد مزعج. |
received | رسالة واردة استُلمت في الصندوق. |
اشترك في Webhooks لتلقي انتقالات الحالة فورياً بدلاً من استعلام نقطة GET.