پرش به مستندات
TypeScript

خودکارسازی‌ها

`automations.list`، `get`، `create`، `update`، `publish`، `pause`، `resume`، `archive`، `duplicate`، `delete`، `sendTest`، `stats`، `listVersions`، `restoreVersion`، `listStarters`، `listEnrollments`، `getEnrollment`، `enroll` و `exitEnrollment`، همراه با `events.send`، `sendBatch` و `listNames`.

همهٔ متدها

automations.ts
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 رویداد در آرایه‌ای که فرستادید.