KapsoEx.Platform.Events (kapso_ex v0.1.0)

Copy Markdown View Source

Project events: timestamped data points you record (for example order.created) that can trigger workflows, plus the definitions that describe them.

Event names are lowercase, optionally with dot-separated segments; each segment starts with a letter and may contain letters, numbers and underscores.

Summary

Functions

Creates an event definition, or updates (and unarchives) the one with the same name. Attributes: name (required), description, property_schema.

Permanently deletes an event definition and all its recorded events. Deletion runs in the background (202 Accepted). To keep history, archive it with update_definition/3 instead.

Gets an event definition.

Lists events, newest first.

Lists event definitions. Params: include_archived.

Updates an event definition: name, description, property_schema, or archived (to hide it while keeping its events).

Types

result()

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

Functions

create_definition(client, attrs)

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

Creates an event definition, or updates (and unarchives) the one with the same name. Attributes: name (required), description, property_schema.

delete_definition(client, id)

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

Permanently deletes an event definition and all its recorded events. Deletion runs in the background (202 Accepted). To keep history, archive it with update_definition/3 instead.

emit(client, name, opts \\ [])

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

Emits an event.

Options

  • :properties - map of event properties.
  • :conversation_id - link the event to a WhatsApp conversation.
  • :occurred_at - DateTime or ISO 8601 string; defaults to now.

Examples

Events.emit(client, "order.created", properties: %{order_id: "1234", total: 59.9})

get_definition(client, id)

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

Gets an event definition.

list(client, params \\ [])

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

Lists events, newest first.

Params: name, conversation_id, occurred_after, occurred_before, limit, before, after.

list_definitions(client, params \\ [])

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

Lists event definitions. Params: include_archived.

update_definition(client, id, attrs)

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

Updates an event definition: name, description, property_schema, or archived (to hide it while keeping its events).