Toolbox.Scenario.UserAction (runbox v7.0.1)

Toolbox for working with scenario user actions.

User action is action created by scenario via Runbox.Scenario.UIAction and fired by user (usually from UI). Scenario is usually also a receiver of fired action. Assumed workflow is following:

  1. Scenario creates list of actions (using Runbox.Scenario.UIAction) to be fired in the future and saves it somewhere (in incident asset for example).

  2. UI displays available actions.

  3. User fires selected action from UI.

  4. UI pushes the action to raw Kafka topic (defined in action) with extra data attached (usually some comment).

  5. Normalizer pipeline recieves the action and sends it to target scenario.

Link to this section Summary

Types

t()

Fired user action.

Functions

Unpacks action and makes it fired (prepared for sending to target topic).

Helper for UserAction forwading to be used in normalizer.

Packs user action to JWT to be used (fired) later (from UI for example).

Parses string containing JSON to Toolbox.Scenario.UserAction.

Link to this section Types

@type t() :: %Toolbox.Scenario.UserAction{
  data: any(),
  details: map(),
  type: String.t(),
  user: String.t()
}

Fired user action.

When action is fired by the user, it should be pushed to raw topic with current timestamp to be correctly reordered by Normalizer. Properties type and details should contain enough information for routing action to the target scenario. Property user is ID of user who fired the action, data contains extra information attached by environment where user fired the action (for example comment filled by the user on UI).

Link to this section Functions

Link to this function

fire(packed, user, data)

@spec fire(Joken.bearer_token(), String.t(), any()) ::
  {:ok, topic :: String.t(), String.t()} | {:error, Joken.error_reason()}

Unpacks action and makes it fired (prepared for sending to target topic).

Routing properties (type, details) are propagated from packed action, user and data properties are attached to fired action. Target topic is also extracted from packed action.

Returns error if packed action (JWT) is not valid.

Link to this function

normalizer_pipeline_step(msg)

@spec normalizer_pipeline_step(Toolbox.Message.t()) :: Toolbox.Message.t()

Helper for UserAction forwading to be used in normalizer.

If helper is used in normalizer pipeline configuration in config.ini like

[pipelines.some_pipeline]
definition = Toolbox.Scenario.UserAction.normalizer_pipeline_step

than Toolbox.Message body will contain fired Toolbox.Scenario.UserAction.

Link to this function

pack(topic, type, details)

@spec pack(String.t(), String.t(), map()) ::
  {:ok, Joken.bearer_token()} | {:error, Joken.error_reason()}

Packs user action to JWT to be used (fired) later (from UI for example).

Parameter details must be a map encodable to JSON. Because details can be (and it is!) encoded/decoded to/from JSON during its life-cycle, atom property names of details are always converted to string property names in fired action's details.

JWT is not used for security reasons - it is just good enough envelope protecting action against accidental corruption on its journey.

Link to this function

parse_raw_action(msg)

@spec parse_raw_action(String.t()) :: t()

Parses string containing JSON to Toolbox.Scenario.UserAction.