Omni.Content.Data (Omni v2.0.0)

Copy Markdown View Source

A data content block: structured data sent to the model as JSON.

Used in decisions, as part of the state or of a question's instructions (see Omni.Decision). Not a message content block.

Omni.Content.Data.new(%{ticket: %{subject: "Refund", plan: :enterprise}})
#=> %Omni.Content.Data{data: %{"ticket" => %{"subject" => "Refund", "plan" => "enterprise"}}}

Struct fields

  • :data - the data, as the JSON-decoded map the model sees

new/1 passes the map through JSON, so the struct holds exactly what the model sees: string keys, atoms as strings, and any struct with a JSON.Encoder implementation (such as Date) in its JSON form. A value JSON can't encode raises here, not when the request is sent.

Summary

Types

t()

Structured data, as the JSON-decoded map sent to the model.

Functions

Creates a data block from the data map itself, or from a keyword list (data: map), normalising the map through JSON.

Types

t()

@type t() :: %Omni.Content.Data{data: map()}

Structured data, as the JSON-decoded map sent to the model.

Functions

new(data)

@spec new(map() | Enumerable.t()) :: t()

Creates a data block from the data map itself, or from a keyword list (data: map), normalising the map through JSON.

Omni.Content.Data.new(%{plan: :pro})
Omni.Content.Data.new(data: %{plan: :pro})

A map is always the data, never attributes (unlike Omni.Content.Text.new/1), so new(%{data: x}) builds %{"data" => x}.

Raises if :data is missing, is not a plain map, or holds a value JSON can't encode.