الأجهزة
يغطي sms.devices هواتف Android المقترنة بمؤسستك وشرائحها. ويجمع sms.pools الهواتف في مجموعات، فإذا انقطع أحدها تنتقل الرسالة إلى هاتف آخر. القراءة تحتاج إلى devices:read، وكل تعديل يحتاج إلى devices:manage.
| الدالة | طلب HTTP | القيمة المعادة |
|---|---|---|
devices.createPairingToken(options?) |
POST /v1/devices/pairing-tokens |
PairingToken |
devices.list() |
GET /v1/devices |
Device[] |
devices.get(id) |
GET /v1/devices/:id |
Device |
devices.update(id, params) |
PATCH /v1/devices/:id |
Device |
devices.delete(id) |
DELETE /v1/devices/:id |
void |
devices.updateSim(deviceId, simId, params) |
PATCH /v1/devices/:id/sims/:simId |
Sim |
devices.setDefaultSim(deviceId, simId) |
POST /v1/devices/:id/sims/:simId/default |
Sim |
pools.list() |
GET /v1/pools |
Pool[] |
pools.create(params, options?) |
POST /v1/pools |
Pool |
pools.update(id, params) |
PATCH /v1/pools/:id |
Pool |
pools.delete(id) |
DELETE /v1/pools/:id |
void |
devices.createPairingToken
Section titled “devices.createPairingToken”رمز لإقران هاتف جديد، صالح 10 دقائق، من 16 حرفًا ورقمًا (Crockford base32، دون حالة أحرف). اعرض qrPayload كرمز QR وامسحه بتطبيق SMSFabric (الإقران).
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
const pairing = await sms.devices.createPairingToken();console.log(pairing.qrPayload); // smsfabric://pair?server=…&token=…console.log('Expires', pairing.expiresAt);devices.list
Section titled “devices.list”كل الهواتف المقترنة، مع status (online أو offline أو disabled) والبطارية والإشارة والشبكة وإصدار التطبيق وآخر اتصال والشرائح.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
for (const d of await sms.devices.list()) { console.log(d.id, d.name, d.status, `${d.battery ?? '?'}%`, d.sims.map((s) => s.carrier).join(', '));}devices.get
Section titled “devices.get”هاتف واحد.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
const device = await sms.devices.get('dev_…');console.log(device.status, device.lastSeenAt, device.appVersion);devices.update
Section titled “devices.update”تغيّر اسم الهاتف (name، حتى 120 حرفًا)، أو تشغّل الإرسال منه أو توقفه (enabled)، أو تنقله إلى مجموعة (poolId؛ والقيمة null تخرجه منها).
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
const device = await sms.devices.update('dev_…', { name: 'Front desk Pixel', poolId: 'pool_…' });console.log(device.name, device.poolId);devices.delete
Section titled “devices.delete”تلغي اقتران الهاتف وتبطل رمز الجهاز الخاص به، فلا يعود قادرًا على الاتصال بالواجهة البرمجية. لاستخدام الهاتف مجددًا، أقرنه برمز جديد.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
await sms.devices.delete('dev_…');devices.updateSim
Section titled “devices.updateSim”تشغّل الشريحة أو توقفها، أو تضبط حدًا يوميًا (من 0 إلى 100,000 رسالة؛ والقيمة null تزيله)، أو تسمية (حتى 80 حرفًا).
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
const sim = await sms.devices.updateSim('dev_…', 'sim_…', { dailyLimit: 500, label: 'Vodafone business' });console.log(sim.label, sim.dailyLimit);devices.setDefaultSim
Section titled “devices.setDefaultSim”تجعل هذه الشريحة الشريحة الافتراضية للإرسال في المؤسسة: الرسائل التي لا تحدد deviceId أو simId أو poolId تخرج عبرها.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
const sim = await sms.devices.setDefaultSim('dev_…', 'sim_…');console.log(sim.isDefault); // trueالمجموعات
Section titled “المجموعات”المجموعة (pool) هي عدة هواتف تتقاسم العمل. الرسالة المرسلة مع poolId توزع دوريًا على هواتف المجموعة المتصلة؛ وإذا لم يستلمها الهاتف في الوقت المحدد، أو رفضها، أو انقطع اتصاله، تنتقل الرسالة إلى هاتف آخر في المجموعة. تنضم الهواتف عبر devices.update(id, { poolId }). التفاصيل في المجموعات.
pools.list
Section titled “pools.list”كل المجموعات مع معرفات هواتفها.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
for (const pool of await sms.pools.list()) console.log(pool.id, pool.name, pool.deviceIds.length);pools.create
Section titled “pools.create”تنشئ مجموعة فارغة.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
const pool = await sms.pools.create({ name: 'Cairo office' });for (const id of ['dev_…', 'dev_…']) await sms.devices.update(id, { poolId: pool.id });pools.update
Section titled “pools.update”تغيّر اسم المجموعة.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
await sms.pools.update('pool_…', { name: 'Cairo office (2 phones)' });pools.delete
Section titled “pools.delete”تحذف المجموعة. تبقى هواتفها مقترنة، وتصبح قيمة poolId لها null.
import { SMSFabric } from '@smsfabric/sdk';
const sms = new SMSFabric({ apiKey: process.env.SMSFABRIC_API_KEY });
await sms.pools.delete('pool_…');