Module: CopyAi::Webhook

Extended by:
Webhook
Included in:
Webhook
Defined in:
lib/copy_ai/webhook.rb

Constant Summary collapse

EVENT_TYPES =
[
  "workflowRun.started",
  "workflowRun.completed",
  "workflowRun.failed",
  "workflowCreditLimit.reached"
].freeze
WEBHOOK_URL =
"https://api.copy.ai/api/webhook".freeze

Instance Method Summary collapse

Instance Method Details

#register(client, url:, event_type:, workflow_id: nil) ⇒ Object

If a workflow ID is not included, events for all workflows in your workspace will be received

Raises:

  • (ArgumentError)
[View source]

13
14
15
16
17
18
19
20
# File 'lib/copy_ai/webhook.rb', line 13

def register(client, url:, event_type:, workflow_id: nil)
  raise ArgumentError, "Missing Arguments" if client.nil? || url.nil? || event_type.nil?

  validate!(event_type:)
  webhook_client = client.dup.tap { |c| c.api_endpoint = WEBHOOK_URL }
  body = {url:, eventType: event_type, workflowId: workflow_id}
  webhook_client.post(body:)
end