Skip to content

Inbox commands

Example:

Add a "Thank you" message as suggestion to the operator input bar.

emit "$inbox", Inbox.suggest("Thank you"), to: :operator

Show a toast message to the user.

emit "$inbox", Inbox.toast("This person is not a paying member"), to: :operator

Note: This currently only works in the Inbox, not the studio inbox.

Inbox.form(opts)

Presents a form to the operator.

Options:

  • :schema: The JSON schema for the form. The root of the schema must be an object (that is, a schema with %{"type" => "object"} first).
  • :ui_schema: The UI schema to accompany the schema.
  • :data: Prefilled data for the form.
  • :event: The event (string) that will be called when the form has been filled. Required. The event.payload will be a map with an operator key containing the operator that submitted the form, and a form key with the validated data.
  • :cancel_event: The event (string) that will be called when the form has been cancelled. Optional. The event.payload will be a map with an operator key containing the operator that submitted the form, and a form key with the unfinished, non-validated data.

Inbox.suggest(message)

Suggest messages to the operator.

Examples:

emit "$inbox", Inbox.suggest("Did you turn the device off and back on?"), to: :operator
emit "$inbox", Inbox.suggest([
  "First suggestion",
  "Second suggestion"
]), to: :operator

Inbox.toast(text, opts \\ [])

Display a toast message to the operator.

The toast may either be a simple string, or a translations map where the key is the language ('en', 'nl', etc), and the value is the toast.

The message itself is rendered as markdown, so it may contain links.

Options:

  • :timeout: Automatically remove the toast after this many seconds. Defaults to no timeout.
  • :intent: Either :normal, :error, or :warning. Defaults to :normal.
  • :buttons: A list of commands that must also be present in the ui_commands.

Example:

emit "$inbox", Inbox.toast("Hello operator, this is bot"), to: :operator
# With translations, based on the operator's language:
emit "$inbox", Inbox.toast(%{"en" => "Hello operator", "nl" => "Hallo operator"}), to: :operator