Sake.Elicit (Sake v0.4.3)

Copy Markdown View Source

Asks the person for input from inside a component.

case Sake.Elicit.form(ctx, :who, "Who should be greeted?", schema) do
  {:ok, %{"name" => name}} -> ...
  :decline -> ...
  :cancel -> ...
  {:error, :unsupported} -> ...
end

On a modern connection the call ends the handler; Sake answers the client with an input-required result, and when the client retries, the handler runs again and the same call returns the answer. So a handler must have no side effects before its elicitation calls. On a legacy connection the call blocks until the client answers on the stream; the request carries the handler's key in _meta under "ai.hattori.sake/key", so a client can tell which question is being asked. Inside a task (see Sake.Tasks) the call waits until the client answers through tasks/update; a task cancelled meanwhile reads as :cancel.

Summary

Functions

form(ctx, key, message, schema)

@spec form(Sake.Context.t(), atom() | String.t(), String.t(), map()) ::
  {:ok, map()} | :decline | :cancel | {:error, :unsupported}

url(ctx, key, message, url)

@spec url(Sake.Context.t(), atom() | String.t(), String.t(), String.t()) ::
  :ok | :decline | :cancel | {:error, :unsupported}