تخطَّ إلى المستندات
PHP

الأتمتة

`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.php
use OpenEmail\Constants\AutomationEnrollmentStatuses;use OpenEmail\Constants\AutomationTriggerKinds; $automation = $client->automations->create([    'name' => 'Welcome series',    'starter' => 'welcome-series',    'settings' => ['timezone' => 'Europe/London'],]); $definition = $automation['definition'];$definition['trigger'] = ['kind' => AutomationTriggerKinds::EVENT, 'eventName' => 'trial.started', 'filters' => []]; $saved = $client->automations->update($automation['id'], [    'definition' => $definition,    'expectedUpdatedAt' => $automation['updatedAt'],]); foreach ($saved['problems'] as $problem) {    if ($problem['blocking']) {        throw new \RuntimeException($problem['message']);    }} $client->automations->sendTest($saved['id'], ['stepKey' => $saved['definition']['entry'] ?? '']);$live = $client->automations->publish($saved['id']); $sent = $client->events->send([    'name' => 'trial.started',    'email' => '[email protected]',    'properties' => ['plan' => 'starter'],    'createContact' => true,], idempotencyKey: 'trial:[email protected]'); foreach ($client->automations->iterateEnrollments($live['id'], status: AutomationEnrollmentStatuses::ACTIVE) as $enrollment) {    if ($enrollment['heldFor'] !== null) {        echo $enrollment['contact']['email'], ' ', $enrollment['heldFor'], PHP_EOL;    }} $stats = $client->automations->stats($live['id']);$history = $client->contacts->listEvents('[email protected]', name: 'trial.started'); $client->automations->pause($live['id']);$client->automations->resume($live['id']); echo count($sent['enrolled']), ' ', $stats['totals']['entered'], ' ', count($history->items), PHP_EOL;

تحتفظ الأتمتة بمسودة 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 الحدث في المصفوفة التي أرسلتها.

يحمل attributes في جهة الاتصال حقولها المخصصة، وتقرأ الأتمتة أحدها بالصيغة attributes.<key>.