KapsoEx.Workflows.Executions (kapso_ex v0.1.0)

Copy Markdown View Source

Start and resume workflow executions and read their history.

Starting executions has an extra per-workflow burst limit (5 to 30 per second depending on the plan); exceeding it returns 429 with retry_after: 1 in the KapsoEx.Error.

Summary

Functions

Gets an execution with its context, variables and event history.

Lists a workflow's executions, most recent first.

Lists an execution's events, most recent first. Params: event_type, limit, before, after.

Lists the workflow executions of a WhatsApp conversation, most recent first. Params: status, limit, before, after.

Resumes an execution in waiting status (for example at a wait for response step), delivering data as the incoming message.

Starts an execution asynchronously (202, with an id and tracking_id). The workflow must be active.

Sets the status of an execution: "ended", "handoff" or "waiting".

Types

result()

@type result() :: {:ok, map()} | {:error, KapsoEx.Error.t()}

Functions

get(client, execution_id)

@spec get(KapsoEx.Client.t(), String.t()) :: result()

Gets an execution with its context, variables and event history.

list(client, workflow_id, params \\ [])

@spec list(KapsoEx.Client.t(), String.t(), map() | keyword()) :: result()

Lists a workflow's executions, most recent first.

Params: status, created_after, created_before, whatsapp_conversation_id, limit, before, after.

list_events(client, execution_id, params \\ [])

@spec list_events(KapsoEx.Client.t(), String.t(), map() | keyword()) :: result()

Lists an execution's events, most recent first. Params: event_type, limit, before, after.

list_for_conversation(client, conversation_id, params \\ [])

@spec list_for_conversation(KapsoEx.Client.t(), String.t(), map() | keyword()) ::
  result()

Lists the workflow executions of a WhatsApp conversation, most recent first. Params: status, limit, before, after.

resume(client, execution_id, data, opts \\ [])

@spec resume(KapsoEx.Client.t(), String.t(), String.t() | map() | list(), keyword()) ::
  result()

Resumes an execution in waiting status (for example at a wait for response step), delivering data as the incoming message.

data is a string, map or list.

Options

  • :kind - message kind, for example "text".
  • :variables - variables to merge into the execution.

Examples

Executions.resume(client, execution_id, "yes", kind: "text", variables: %{confirmed: true})

start(client, workflow_id, attrs)

@spec start(KapsoEx.Client.t(), String.t(), map() | keyword()) :: result()

Starts an execution asynchronously (202, with an id and tracking_id). The workflow must be active.

Attributes: phone_number (E.164) and/or recipient (business-scoped user ID), phone_number_id, variables, context, initial_data.

Executions.start(client, workflow_id,
  phone_number: "+56961567267",
  phone_number_id: "647015955153740",
  variables: %{order_id: "ORD-1234"}
)

update_status(client, execution_id, status)

@spec update_status(KapsoEx.Client.t(), String.t(), String.t()) :: result()

Sets the status of an execution: "ended", "handoff" or "waiting".