الحساب
تغطي هذه الموارد المؤسسة التي تنتمي إليها بيانات الاعتماد. بعضها يرفض مفاتيح API حتى لا يستطيع مفتاح مسرب تغيير من يملك الوصول، فيحتاج إلى رمز وصول لمستخدم مسجل الدخول (السبب). يوضح عمود المصادقة ذلك.
| الدالة | طلب HTTP | القيمة المعادة | المصادقة |
|---|---|---|---|
org.get() |
GET /v1/org |
Org |
مفتاح API أو مستخدم |
org.update(params) |
PATCH /v1/org |
Org |
مستخدم، settings:manage |
org.plan() |
GET /v1/org/plan |
OrgPlan |
مفتاح API أو مستخدم |
org.members.list() |
GET /v1/org/members |
Member[] |
مستخدم |
org.members.update(userId, params) |
PATCH /v1/org/members/:userId |
Member |
مستخدم، members:manage |
org.members.remove(userId) |
DELETE /v1/org/members/:userId |
void |
مستخدم، members:manage |
org.invitations.list() |
GET /v1/org/invitations |
Invitation[] |
مستخدم، members:manage |
org.invitations.create(params, options?) |
POST /v1/org/invitations |
Invitation |
مستخدم، members:manage |
org.invitations.revoke(id) |
DELETE /v1/org/invitations/:id |
void |
مستخدم، members:manage |
preferences.get() |
GET /v1/preferences |
Preferences |
مفتاح API أو مستخدم |
preferences.update(params) |
PATCH /v1/preferences |
Preferences |
settings:manage |
audit.list(params?) |
GET /v1/audit |
Paginated<AuditEntry> |
audit:read |
audit.listAll(params?) |
GET /v1/audit (كل الصفحات) |
AsyncGenerator<AuditEntry> |
audit:read |
blacklist.list(params?) |
GET /v1/blacklist |
Paginated<BlacklistEntry> |
blacklist:manage |
blacklist.listAll(params?) |
GET /v1/blacklist (كل الصفحات) |
AsyncGenerator<BlacklistEntry> |
blacklist:manage |
blacklist.add(params, options?) |
POST /v1/blacklist |
BlacklistEntry |
blacklist:manage |
blacklist.remove(id) |
DELETE /v1/blacklist/:id |
void |
blacklist:manage |
المؤسسة
Section titled “المؤسسة”org.get
Section titled “org.get”تعيد id وname وslug وstatus وplan للمؤسسة. تعمل مع أي مفتاح API، فهي طريقة سريعة للتأكد من صلاحية المفتاح.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
const org = await sms.org.get();console.log(org.id, org.name, org.plan);org.plan
Section titled “org.plan”تعيد الباقة وحدودها بعد احتساب الإضافات، والحدود التي غيّرها فريق SMSFabric لمؤسستك، والاستخدام المحسوب عليها. عندما ينفد الرصيد يفشل الإرسال بالخطأ 429 quota_exceeded، ولا يعيد الـ SDK المحاولة في هذه الحالة، وتحمل error.params اسم الباقة والحد وموعد التجديد.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
const { plan, limits, usage } = await sms.org.plan();console.log(plan.name, usage.messagesThisMonth, limits.messagesPerMonth ?? 'no limit');org.update
Section titled “org.update”تغيّر اسم المؤسسة.
import { SMSFabric } from '@smsfabric/sdk';
const admin = new SMSFabric({ accessToken: process.env.SMSFABRIC_ACCESS_TOKEN });
await admin.org.update({ name: 'Acme Clinics' });الأعضاء
Section titled “الأعضاء”org.members.list
Section titled “org.members.list”كل أعضاء المؤسسة مع role لكل منهم (owner أو admin أو developer أو campaign_manager أو agent أو viewer أو billing).
import { SMSFabric } from '@smsfabric/sdk';
const admin = new SMSFabric({ accessToken: process.env.SMSFABRIC_ACCESS_TOKEN });
for (const m of await admin.org.members.list()) console.log(m.userId, m.email, m.role);org.members.update
Section titled “org.members.update”تغيّر دور العضو، ويسجل التغيير في سجل التدقيق.
import { SMSFabric } from '@smsfabric/sdk';
const admin = new SMSFabric({ accessToken: process.env.SMSFABRIC_ACCESS_TOKEN });
await admin.org.members.update('usr_…', { role: 'campaign_manager' });org.members.remove
Section titled “org.members.remove”تزيل عضوًا من المؤسسة. يبقى حسابه، لكنه يفقد الوصول إلى هذه المؤسسة.
import { SMSFabric } from '@smsfabric/sdk';
const admin = new SMSFabric({ accessToken: process.env.SMSFABRIC_ACCESS_TOKEN });
await admin.org.members.remove('usr_…');الدعوات
Section titled “الدعوات”org.invitations.list
Section titled “org.invitations.list”الدعوات مع email وrole وexpiresAt وacceptedAt.
import { SMSFabric } from '@smsfabric/sdk';
const admin = new SMSFabric({ accessToken: process.env.SMSFABRIC_ACCESS_TOKEN });
const open = (await admin.org.invitations.list()).filter((i) => !i.acceptedAt);console.log(open.map((i) => `${i.email} (${i.role})`));org.invitations.create
Section titled “org.invitations.create”ترسل دعوة بالبريد للانضمام بدور محدد.
import { SMSFabric } from '@smsfabric/sdk';
const admin = new SMSFabric({ accessToken: process.env.SMSFABRIC_ACCESS_TOKEN });
const invitation = await admin.org.invitations.create({ email: 'sara@acme.example', role: 'developer' });console.log(invitation.id, invitation.expiresAt);org.invitations.revoke
Section titled “org.invitations.revoke”تلغي دعوة لم تقبل بعد.
import { SMSFabric } from '@smsfabric/sdk';
const admin = new SMSFabric({ accessToken: process.env.SMSFABRIC_ACCESS_TOKEN });
await admin.org.invitations.revoke('inv_…');التفضيلات
Section titled “التفضيلات”preferences.get
Section titled “preferences.get”تفضيلات الإرسال في المؤسسة: cooldownMs وjitterMs بين رسالتين من الهاتف نفسه، وmaxRetries، والهاتف والشريحة الافتراضيان، وsendWindow، وتحويل الرسائل الواردة، وtimeZone المستخدمة لساعات الهدوء في الحملات.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
const prefs = await sms.preferences.get();console.log(prefs.cooldownMs, prefs.jitterMs, prefs.defaultSimId, prefs.timeZone);preferences.update
Section titled “preferences.update”تغيّر أيًا منها. قيم cooldownMs وjitterMs من 0 إلى 600,000 مللي ثانية، وmaxRetries من 0 إلى 10، وsendWindow بالشكل { start: 'HH:mm', end: 'HH:mm', tz } أو null، وforwardInbound بالشكل { email?, phone?, webhook? } أو null.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
await sms.preferences.update({ cooldownMs: 5_000, jitterMs: 3_000, sendWindow: { start: '09:00', end: '21:00', tz: 'Africa/Cairo' }, timeZone: 'Africa/Cairo',});سجل التدقيق
Section titled “سجل التدقيق”audit.list and listAll
Section titled “audit.list and listAll”الأحداث الأمنية والتغييرات، الأحدث أولًا: تسجيلات الدخول وإنشاء المفاتيح وتغيير الأدوار وبدء الحملات والتصدير وغيرها. صفّ حسب action محدد، مثل apikey.created، أو باستخدام q بجزء من اسم الإجراء أو من اسم المنفذ أو بريده. يحمل actor في كل مدخل الاسم الذي تعرضه (وnull لفريق SMSFabric وللنظام).
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
for await (const entry of sms.audit.listAll({ action: 'campaign.started' })) { console.log(entry.createdAt, entry.actor.name ?? entry.actor.type, entry.action, entry.targetId);}القائمة السوداء
Section titled “القائمة السوداء”لا تصل أي رسالة إلى الأرقام الموجودة في القائمة السوداء: الإرسال إليها يعود بالحالة status: 'blocked'. المستلم الذي يرد بـ STOP يضاف مع source: 'opt_out'، والرد بـ START يزيل ذلك الإدخال.
blacklist.list and listAll
Section titled “blacklist.list and listAll”import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
for await (const entry of sms.blacklist.listAll()) console.log(entry.phone, entry.source, entry.reason);blacklist.add
Section titled “blacklist.add”تضيف رقمًا بصيغة E.164، مع reason اختياري (حتى 500 حرف).
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
const entry = await sms.blacklist.add({ phone: '+201001234567', reason: 'Asked by phone not to be contacted' });console.log(entry.id);blacklist.remove
Section titled “blacklist.remove”تزيل إدخالًا بمعرفه. لا تزل إدخال opt_out إلا إذا طلب الشخص استقبال الرسائل مجددًا.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
await sms.blacklist.remove('blk_…');