Omni.Question (Omni v2.0.0)

Copy Markdown View Source

Typed questions for Omni.decide/3.

A decision asks one or more questions about a shared state. Each question is a struct, and its type decides the shape of its answer. The Decisions guide introduces each type.

Build them with Omni.predicate/2, Omni.choice/2 and Omni.score/2, which delegate to each struct's new/2:

[
  urgent: Omni.predicate("Does this need a reply within the hour?"),
  team: Omni.choice("Which team owns this?", billing: "Payments and refunds", infra: "Outages", other: nil),
  anger: Omni.score("How angry is the customer?", ["Calm", "Frustrated but civil", "Very angry"])
]

Choices and levels take a list of keys, or of key: description pairs, or a mix of both. Keys may be atoms or strings, and the answer uses them as given. Questions are validated when the decision is sent, not here (see Omni.Decision).

Instructions

Instructions are parts, like the state (see Omni.Decision): a string is one text part, a map one data part sent as JSON, and a list gives a part for each item. The constructors build them, so the struct holds [%Omni.Content.Text{}] for a string.

Omni.predicate(%{question: "Does the ticket report an outage?", field: "ticket.body"})

Summary

Types

Question instructions, as parts (see Instructions).

Instructions as given to a constructor: a string, a map, a part, or a list of them.

A choice or level key, as given by the caller.

A choice or level: its key and an optional description.

t()

A decision question.

Types

instructions()

@type instructions() :: [Omni.Decision.part()]

Question instructions, as parts (see Instructions).

instructions_input()

@type instructions_input() :: Omni.Decision.parts_input()

Instructions as given to a constructor: a string, a map, a part, or a list of them.

key()

@type key() :: atom() | String.t()

A choice or level key, as given by the caller.

option()

@type option() :: {key(), String.t() | nil}

A choice or level: its key and an optional description.

t()

A decision question.