الأتمتة
`automations.list` و`get` و`create` و`update` و`publish` و`pause` و`resume` و`archive` و`duplicate` و`delete` و`sendTest` و`stats` و`listVersions` و`restoreVersion` و`listStarters` و`listEnrollments` و`getEnrollment` و`enroll` و`exitEnrollment`، مع `events.send` و`sendBatch` و`listNames`.
كل الدوالّ
const automation = await openemail.automations.create({ name: 'Welcome series', starter: 'welcome-series', settings: { timezone: 'Europe/London' },}) const saved = await openemail.automations.update(automation.id, { definition: { ...automation.definition, trigger: { kind: 'event', eventName: 'trial.started', filters: [] } }, expectedUpdatedAt: automation.updatedAt,}) if (saved.problems.some((problem) => problem.blocking)) throw new Error(saved.problems[0]?.message) await openemail.automations.sendTest(saved.id, { stepKey: saved.definition.entry ?? '' })const live = await openemail.automations.publish(saved.id) const sent = await openemail.events.send( { name: 'trial.started', email: '[email protected]', properties: { plan: 'starter' }, createContact: true }, { idempotencyKey: 'trial:[email protected]' },) for await (const enrollment of openemail.automations.iterateEnrollments(live.id, { status: 'active' })) { if (enrollment.heldFor) console.log(enrollment.contact.email, enrollment.heldFor)} const stats = await openemail.automations.stats(live.id)const history = await openemail.contacts.listEvents('[email protected]', { name: 'trial.started' }) await openemail.automations.pause(live.id)await openemail.automations.resume(live.id) console.log(sent.enrolled, stats.totals.entered, history.items.length)تحتفظ الأتمتة بمسودة definition وبنسخة published التي تعمل. ويغيّر update المسودة والإعدادات، ويثبّت publish المسودة بوصفها النسخة التالية ويشغّل الأتمتة. ويذكر problems ما يمنع نشر المسودة حتى الآن، ويرفض expectedUpdatedAt بـ 409 version_conflict أي حفظ قد يكتب فوق حفظ شخص آخر.
القراءة تتطلب automations:read والتغيير يتطلب automations:write. وتتطلب publish وresume وsendTest أيضًا emails:send. وتتطلب events.send وevents.sendBatch النطاق contacts:write، وتتطلب contacts.listEvents النطاق contacts:read. ويطلب delete من رمز وصول OAuth رمز تحقق، ولا يطلبه من مفتاح API أبدًا.
يقبل events.sendBatch حتى 100 حدث ولا يرمي استثناءً أبدًا بسبب حدث واحد غير صالح: تسرد الاستجابة accepted وfailed، ولكل منها index الحدث في المصفوفة التي أرسلتها.