Module: Mailblastr::Automations
- Defined in:
- lib/mailblastr/automations.rb
Overview
Automations are DOMAIN-FIRST: domain is required on create, and only
Events.send calls naming the same domain trigger them.
Class Method Summary collapse
-
.add_step(automation_id, params) ⇒ Object
Append a step.
-
.create(params) ⇒ Object
POST /automations Mailblastr::Automations.create({ name: "Welcome series", domain: "yourdomain.com", trigger: "contact.created" }) The built-in "mailblastr:schedule" trigger fires once at
trigger_config({ at: ISO 8601 instant, timezone: IANA name }), enrolling every contact of the domain's pool —trigger_configis required with that trigger and not accepted on any other. -
.create_with_ai(automation_id, params) ⇒ Object
Build (or extend) the automation's steps from a prompt.
-
.delete(automation_id) ⇒ Object
DELETE /automations/:id.
-
.delete_step(automation_id, step_id) ⇒ Object
Delete a step.
-
.get(automation_id) ⇒ Object
GET /automations/:id.
-
.get_run(automation_id, run_id) ⇒ Object
Retrieve a single run with its step trace.
-
.list(params = {}) ⇒ Object
GET /automations.
-
.runs(automation_id, params = {}) ⇒ Object
List an automation's runs.
-
.stop(automation_id) ⇒ Object
Stop an automation — no new runs; in-progress runs finish.
-
.update(automation_id, params) ⇒ Object
PATCH /automations/:id — params: { name:, status: "enabled"|"disabled", ... }
trigger_config({ at:, timezone: }) updates the "mailblastr:schedule" trigger's schedule (only valid on automations with that trigger). -
.update_step(automation_id, step_id, params) ⇒ Object
Edit a step in place (automation must be disabled).
Class Method Details
.add_step(automation_id, params) ⇒ Object
Append a step. POST /automations/:id/steps — params: { type:, config:, key: }
The automation must be disabled first, and type: "trigger" is
rejected here (the trigger lives on the automation, not in steps).
40 41 42 |
# File 'lib/mailblastr/automations.rb', line 40 def add_step(automation_id, params) Client.request(:post, "/automations/#{Client.path_escape(automation_id)}/steps", body: params) end |
.create(params) ⇒ Object
POST /automations
Mailblastr::Automations.create({ name: "Welcome series", domain: "yourdomain.com",
trigger: "contact.created" })
The built-in "mailblastr:schedule" trigger fires once at
trigger_config ({ at: ISO 8601 instant, timezone: IANA name }),
enrolling every contact of the domain's pool — trigger_config is
required with that trigger and not accepted on any other.
15 16 17 18 |
# File 'lib/mailblastr/automations.rb', line 15 def create(params) Client.require_domain!(params, "Automations.create") Client.request(:post, "/automations", body: params) end |
.create_with_ai(automation_id, params) ⇒ Object
Build (or extend) the automation's steps from a prompt.
POST /automations/:id/ai — params: { prompt:, template_ids:, events:, attach: }
prompt is required and capped at 2000 characters. Without attach the
automation must have no steps yet; pass attach ({ from:, type:,
before: }) to append to an existing graph. The automation must be
stopped, and the route is limited to 20 requests per minute per account.
65 66 67 |
# File 'lib/mailblastr/automations.rb', line 65 def create_with_ai(automation_id, params) Client.request(:post, "/automations/#{Client.path_escape(automation_id)}/ai", body: params) end |
.delete(automation_id) ⇒ Object
DELETE /automations/:id
90 91 92 |
# File 'lib/mailblastr/automations.rb', line 90 def delete(automation_id) Client.request(:delete, "/automations/#{Client.path_escape(automation_id)}") end |
.delete_step(automation_id, step_id) ⇒ Object
Delete a step. DELETE /automations/:id/steps/:step_id
55 56 57 |
# File 'lib/mailblastr/automations.rb', line 55 def delete_step(automation_id, step_id) Client.request(:delete, "/automations/#{Client.path_escape(automation_id)}/steps/#{Client.path_escape(step_id)}") end |
.get(automation_id) ⇒ Object
GET /automations/:id
21 22 23 |
# File 'lib/mailblastr/automations.rb', line 21 def get(automation_id) Client.request(:get, "/automations/#{Client.path_escape(automation_id)}") end |
.get_run(automation_id, run_id) ⇒ Object
Retrieve a single run with its step trace. GET /automations/:id/runs/:run_id
80 81 82 |
# File 'lib/mailblastr/automations.rb', line 80 def get_run(automation_id, run_id) Client.request(:get, "/automations/#{Client.path_escape(automation_id)}/runs/#{Client.path_escape(run_id)}") end |
.list(params = {}) ⇒ Object
GET /automations
26 27 28 |
# File 'lib/mailblastr/automations.rb', line 26 def list(params = {}) Client.request(:get, "/automations", query: Client.pagination(params)) end |
.runs(automation_id, params = {}) ⇒ Object
List an automation's runs. status filters to specific run statuses
("running", "completed", "failed", "skipped") and accepts an Array or a
comma-separated String. GET /automations/:id/runs
72 73 74 75 76 77 |
# File 'lib/mailblastr/automations.rb', line 72 def runs(automation_id, params = {}) query = Client.pagination(params) status = Client.opt(params, :status) query[:status] = status.is_a?(Array) ? status.join(",") : status unless status.nil? Client.request(:get, "/automations/#{Client.path_escape(automation_id)}/runs", query: query) end |
.stop(automation_id) ⇒ Object
Stop an automation — no new runs; in-progress runs finish. POST /automations/:id/stop
85 86 87 |
# File 'lib/mailblastr/automations.rb', line 85 def stop(automation_id) Client.request(:post, "/automations/#{Client.path_escape(automation_id)}/stop") end |
.update(automation_id, params) ⇒ Object
PATCH /automations/:id — params: { name:, status: "enabled"|"disabled", ... }
trigger_config ({ at:, timezone: }) updates the "mailblastr:schedule"
trigger's schedule (only valid on automations with that trigger).
33 34 35 |
# File 'lib/mailblastr/automations.rb', line 33 def update(automation_id, params) Client.request(:patch, "/automations/#{Client.path_escape(automation_id)}", body: params) end |
.update_step(automation_id, step_id, params) ⇒ Object
Edit a step in place (automation must be disabled). PATCH /automations/:id/steps/:step_id
46 47 48 49 50 51 52 |
# File 'lib/mailblastr/automations.rb', line 46 def update_step(automation_id, step_id, params) Client.request( :patch, "/automations/#{Client.path_escape(automation_id)}/steps/#{Client.path_escape(step_id)}", body: params ) end |