Ussd.Context (Ussd v0.2.0)

Copy Markdown View Source

The per-request context for a USSD interaction: who is dialing in (uid), which group/session the request belongs to (gid), what they typed (input), and any extra values the caller wants states/actions to see (bag).

Summary

Functions

Reads a value out of the bag set via with_bag/2, or nil if key isn't present.

The identifier shared across a caller's redials (typically their phone number).

What the caller typed for this request. An empty string on the very first request of a session.

Builds a new context. Raises if uid or gid is empty, mirroring the guarantees callers need: every session must be uniquely and group-addressable.

The unique identifier for this specific dial-in (changes on every redial).

Attaches arbitrary extra values (e.g. the phone's network, a request header) that render/1, Ussd.Action.execute/1 and transition/back/paginate callbacks can read back via get/2. Replaces any bag set previously - it isn't merged.

Types

t()

@type t() :: %Ussd.Context{
  bag: map(),
  gid: String.t(),
  input: String.t(),
  uid: String.t()
}

Functions

get(context, key)

@spec get(t(), term()) :: term()

Reads a value out of the bag set via with_bag/2, or nil if key isn't present.

gid(context)

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

The identifier shared across a caller's redials (typically their phone number).

input(context)

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

What the caller typed for this request. An empty string on the very first request of a session.

new(uid, gid, input)

@spec new(String.t(), String.t(), String.t()) :: t()

Builds a new context. Raises if uid or gid is empty, mirroring the guarantees callers need: every session must be uniquely and group-addressable.

uid(context)

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

The unique identifier for this specific dial-in (changes on every redial).

with_bag(context, bag)

@spec with_bag(t(), map()) :: t()

Attaches arbitrary extra values (e.g. the phone's network, a request header) that render/1, Ussd.Action.execute/1 and transition/back/paginate callbacks can read back via get/2. Replaces any bag set previously - it isn't merged.