ExUssd (ExUssd v0.1.2) View Source
USSD interation
Link to this section Summary
Functions
Example
iex> ExUssd.end_session(session_id: "session_01")
{:error, :not_found}
Navigation
This a helper function that helps simulate ussd call
Link to this section Functions
Example
iex> ExUssd.end_session(session_id: "session_01")
{:error, :not_found}
Specs
goto( internal_routing: ExUssd.Ussd.internal_routing(), menu: ExUssd.Ussd.menu(), api_parameters: ExUssd.Ussd.api_parameters() ) :: any()
Navigation
Configuration
Add below config to dev.exs / prod.exs files
config.exs
config :ex_ussd :provider, AfricasTalking
Example
iex> defmodule MyHomeHandler do
...> @behaviour ExUssd.Handler
...> def handle_menu(menu, _api_parameters) do
...> menu |> Map.put(:title, "Welcome")
...> end
...>end
iex> menu = ExUssd.Menu.render(name: "Home", handler: MyHomeHandler)
iex> ExUssd.goto(
...> internal_routing: %{text: "", session_id: "session_01", service_code: "*544#"},
...> menu: menu,
...> api_parameters: %{
...> "sessionId" => "session_01",
...> "phoneNumber" => "254722000000",
...> "networkCode" => "Safaricom",
...> "serviceCode" => "*544#",
...> "text" => ""
...> }
...> )
{:ok, "CON Welcome"}
This a helper function that helps simulate ussd call
Example
iex> defmodule MyHomeHandler do
...> @behaviour ExUssd.Handler
...> def handle_menu(menu, _api_parameters) do
...> menu |> Map.put(:title, "Welcome")
...> end
...> end
iex> menu = ExUssd.Menu.render(name: "Home", handler: MyHomeHandler)
iex> ExUssd.simulate(menu: menu, text: "", service_code: "*141#")
{:ok, %{menu_string: "Welcome", should_close: false}}