Class: Broadcast::Resources::Autopilots
- Defined in:
- lib/broadcast/resources/autopilots.rb
Overview
Autopilot — AI-generated newsletters.
Requires the autopilot_read / autopilot_write token permissions.
Constant Summary collapse
- REDACTED_KEY_PATTERN =
The API renders a configured key bullet-masked and never returns the real value. Writing a masked value back would replace a working credential with bullets, so it is stripped — same guard as EmailServers#update.
/\A•+\z/
Instance Method Summary collapse
-
#activate(id) ⇒ Object
Activate the autopilot so it runs on its schedule.
-
#create(**attrs) ⇒ Object
Create an autopilot.
- #deactivate(id) ⇒ Object
- #delete(id) ⇒ Object
- #get_autopilot(id) ⇒ Object
- #list(**params) ⇒ Object
- #pause(id) ⇒ Object
-
#runs(id, **params) ⇒ Object
Generation runs, most recent first.
-
#trigger_run(id) ⇒ Object
Queue a generation run now.
-
#update(id, **attrs) ⇒ Object
Update an autopilot.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Broadcast::Resources::Base
Instance Method Details
#activate(id) ⇒ Object
Activate the autopilot so it runs on its schedule.
Requires at least one active source, an API key, and a model. Raises Broadcast::ValidationError naming the missing prerequisites otherwise.
53 54 55 |
# File 'lib/broadcast/resources/autopilots.rb', line 53 def activate(id) post("/api/v1/autopilots/#{id}/activate") end |
#create(**attrs) ⇒ Object
Create an autopilot. Attrs are wrapped under autopilot: on the wire.
name: required, unique per channel
openrouter_api_key: OpenRouter credential (write-only)
ai_model: e.g. 'openai/gpt-4o'
schedule_frequency: 'daily' | 'weekly' | 'biweekly' | 'monthly'
schedule_day_of_week:, schedule_day_of_month:, schedule_time:, schedule_timezone:
copies_to_generate: how many drafts each run produces
tone_description:, content_instructions:, newsletter_structure:
segment_ids: array — restrict the newsletter's audience
33 34 35 |
# File 'lib/broadcast/resources/autopilots.rb', line 33 def create(**attrs) post('/api/v1/autopilots', { autopilot: attrs }) end |
#deactivate(id) ⇒ Object
61 62 63 |
# File 'lib/broadcast/resources/autopilots.rb', line 61 def deactivate(id) post("/api/v1/autopilots/#{id}/deactivate") end |
#delete(id) ⇒ Object
43 44 45 |
# File 'lib/broadcast/resources/autopilots.rb', line 43 def delete(id) @client.request(:delete, "/api/v1/autopilots/#{id}") end |
#get_autopilot(id) ⇒ Object
19 20 21 |
# File 'lib/broadcast/resources/autopilots.rb', line 19 def get_autopilot(id) get("/api/v1/autopilots/#{id}") end |
#list(**params) ⇒ Object
15 16 17 |
# File 'lib/broadcast/resources/autopilots.rb', line 15 def list(**params) get('/api/v1/autopilots', params) end |
#pause(id) ⇒ Object
57 58 59 |
# File 'lib/broadcast/resources/autopilots.rb', line 57 def pause(id) post("/api/v1/autopilots/#{id}/pause") end |
#runs(id, **params) ⇒ Object
Generation runs, most recent first. Supports limit: and offset:.
75 76 77 |
# File 'lib/broadcast/resources/autopilots.rb', line 75 def runs(id, **params) get("/api/v1/autopilots/#{id}/runs", params) end |
#trigger_run(id) ⇒ Object
Queue a generation run now. Returns 202 with the created run — the work
is asynchronous, so poll runs for progress rather than expecting a
finished newsletter here.
68 69 70 |
# File 'lib/broadcast/resources/autopilots.rb', line 68 def trigger_run(id) post("/api/v1/autopilots/#{id}/trigger_run") end |
#update(id, **attrs) ⇒ Object
Update an autopilot. A bullet-masked openrouter_api_key is dropped before sending; pass the real key to rotate it, or omit the field.
39 40 41 |
# File 'lib/broadcast/resources/autopilots.rb', line 39 def update(id, **attrs) patch("/api/v1/autopilots/#{id}", { autopilot: scrub_redacted_key(attrs) }) end |