ExUssd.Menu (ExUssd v0.1.2) View Source
This struct enables USSD customization by modifying its fields.
Link to this section Summary
Types
name
: (Public) This is the value display when Menu is rendered as menu_list. check more onmenu_list
,handler
: (Public) A callback that modifies the current menu struct. Implemented via ExUssd.Handlercallback
: (Internal) A callback function that takes thehandler
callback. This function is triggered when the client is at that menu position.title
: (Public) Outputs the ussd's title,menu_list
: (Public) Takes a list of Ussd Menu struct,error
: (Public) A custom validation error message forvalidation_menu
,show_navigation
: (Public) set to false to hide navigation menu,next
: (Public) navigate's the next menu chunk, default%{name: "MORE", input_match: "98", display_style: ":"}
,previous
: (Public) navigate's the previous menu chunk or the previous menu struct default%{name: "BACK", input_match: "0", display_style: ":"}
,,split
: (Public) This is used to set the chunk size value when rendering menu_list. default value size7
,should_close
: (Public) This triggers ExUssd to end the current registry session,display_style
: (Public) This is used to change default's display style, default ":"parent
: (Internal) saves the previous menu struct to the current menu in order to facilitate navigation,validation_menu
: (Public) Its a special Menu struct that enables the developer to validate the client input,data
: (Public) takes data as Props that will be attached to the children menu struct,default_error_message
:(Public) This the default error message shown on invalid input. default"Invalid Choice "
Functions
Render Function is used to create a ussd Menu.
Link to this section Types
Specs
t() :: %ExUssd.Menu{ callback: (... -> any()), data: any(), default_error_message: String.t(), display_style: String.t(), error: String.t(), handle: term(), handler: (... -> any()), home: term(), menu_list: [ %ExUssd.Menu{ callback: term(), data: term(), default_error_message: term(), display_style: term(), error: term(), handle: term(), handler: term(), home: term(), menu_list: term(), name: term(), next: term(), parent: term(), previous: term(), should_close: term(), show_navigation: term(), split: term(), success: term(), title: term(), validation_menu: term() } ], name: String.t(), next: String.t(), parent: %ExUssd.Menu{ callback: term(), data: term(), default_error_message: term(), display_style: term(), error: term(), handle: term(), handler: term(), home: term(), menu_list: term(), name: term(), next: term(), parent: term(), previous: term(), should_close: term(), show_navigation: term(), split: term(), success: term(), title: term(), validation_menu: term() }, previous: String.t(), should_close: boolean(), show_navigation: boolean(), split: integer(), success: term(), title: String.t(), validation_menu: %ExUssd.Menu{ callback: term(), data: term(), default_error_message: term(), display_style: term(), error: term(), handle: term(), handler: term(), home: term(), menu_list: term(), name: term(), next: term(), parent: term(), previous: term(), should_close: term(), show_navigation: term(), split: term(), success: term(), title: term(), validation_menu: term() } }
name
: (Public) This is the value display when Menu is rendered as menu_list. check more onmenu_list
,handler
: (Public) A callback that modifies the current menu struct. Implemented via ExUssd.Handlercallback
: (Internal) A callback function that takes thehandler
callback. This function is triggered when the client is at that menu position.title
: (Public) Outputs the ussd's title,menu_list
: (Public) Takes a list of Ussd Menu struct,error
: (Public) A custom validation error message forvalidation_menu
,show_navigation
: (Public) set to false to hide navigation menu,next
: (Public) navigate's the next menu chunk, default%{name: "MORE", input_match: "98", display_style: ":"}
,previous
: (Public) navigate's the previous menu chunk or the previous menu struct default%{name: "BACK", input_match: "0", display_style: ":"}
,,split
: (Public) This is used to set the chunk size value when rendering menu_list. default value size7
,should_close
: (Public) This triggers ExUssd to end the current registry session,display_style
: (Public) This is used to change default's display style, default ":"parent
: (Internal) saves the previous menu struct to the current menu in order to facilitate navigation,validation_menu
: (Public) Its a special Menu struct that enables the developer to validate the client input,data
: (Public) takes data as Props that will be attached to the children menu struct,default_error_message
:(Public) This the default error message shown on invalid input. default"Invalid Choice "
Link to this section Functions
Render Function is used to create a ussd Menu.
## Params
The function requires two keys as parameters
:name
- Name of the ussd component
:data
- Optional data prop that will be attached to the menu struct
:handler
- A callback handler ExUssd.Handler
Returns %ExUssd.Menu{} .
## Examples
iex> defmodule MyHomeHandler do
...> @behaviour ExUssd.Handler
...> def handle_menu(menu, api_parameters) do
...> menu |> Map.put(:title, "Welcome")
...> end
...> end
iex> ExUssd.Menu.render(name: "Home", handler: MyHomeHandler)
%ExUssd.Menu{
callback: #Function<1.49663807/1 in ExUssd.Menu.render/1>,
error: nil,
handle: false,
handler: #Function<43.97283095/2 in :erl_eval.expr/5>,
menu_list: [],
name: "Home",
next: %{name: "MORE", input_match: "98", display_style: ":"},
previous: %{name: "BACK", input_match: "0", display_style: ":"},
should_close: false,
show_options: true,
split: 7,
success: false,
title: nil
}
iex> defmodule MyHomeHandler do
...> @behaviour ExUssd.Handler
...> def handle_menu(menu, api_parameters) do
...> %{language: language} = Map.get(menu, data, nil)
...> case language do
...> "Swahili" -> menu |> Map.put(:title, "Karibu")
...> _-> menu |> Map.put(:title, "Welcome")
...> end
...> end
...> end
iex> ExUssd.Menu.render(name: "Home", data: %{language: "Swahili"}, handler: MyHomeHandler)
%ExUssd.Menu{
callback: #Function<2.57249658/2 in ExUssd.Menu.render/1>,
data: nil,
default_error_message: "Invalid Choice\n",
display_style: ":",
error: nil,
handler: MyHomeHandler,
menu_list: [],
name: "Home",
next: %{name: "MORE", input_match: "98", display_style: ":"},
parent: nil,
previous: %{name: "BACK", input_match: "0", display_style: ":"},
should_close: false,
show_navigation: true,
show_options: true,
split: 7,
title: nil,
validation_menu: nil
}