Skip to content

Looping Menus

David Bwire edited this page Aug 22, 2017 · 10 revisions

What are looping menus?

Looping menus are USSD screens that should be shown severally depending on a condition. Let's assume we have a USSD flow that goes through these steps :-

  1. [SCREEN 1] Select Register Clients
  2. [SCREEN 2] How many clients would you like to register?
  3. [SCREEN 3] Enter Client's First Name and Last Name

Our condition in this case is the number of clients we would like to register. If we register 1 client, there will be no need to repeat/loop SCREEN 3. If we register 2 clients we will need to repeat/loop SCREEN 3 two times

Here is how the ussd_menus config looks like

$ussdMenus = [
    "home_screen_one" => [
        "title" => "Welcome to InstantUssd",
        "menu_items" => [
            [
                "next_screen" => "screen_two",
                "description" => "Register Clients"
            ]
        ]
    ],
    "screen_two" => [
        "title" => "How many clients would you like to register?",
        "body" => "(Enter a value between 1 and 5)",
        // --- BEGIN LOOPING KEY
        // target_loopset sets the number of loops required for register_client
        // loopset
        "target_loopset" => "register_client",
        // --- END LOOPING KEY
        "menu_items" => [
            [
                "next_screen" => "screen_three"
            ]
        ]
    ],
    "screen_three" => [
        "title" => "Enter Client's First Name and Last Name",
        // --- BEGIN LOOPING KEYS
        "loopset_name" => "register_client",
        // is_loop_end - indicates it's the last screen of a given loopset
        "is_loop_end" => true,
        // loop_start - may point to itself or to a previous menu_id in history with the
        // same loopset_name
        "loop_start" => "screen_three",
        // --- END LO0PING KEYS
        "menu_items" => [
            [
                // it will automatically exit
                "next_screen" => ""
            ]
        ]
    ]
];

target_loopset

String. It points to a looping set of menus. This screen will be used to set the number of loops that will have to be completed by the looping set referenced.

loopset_name

String. It's a unique name given to a looping set of menus.

is_loop_end

Boolean, default false. It is a status key that indicates whether the current screen is the last one within its looping set.

loop_start

MUST be provided if is_loop_end == true. It points back to the first menu within its looping set.

⇐ Configuration | Capturing Incoming Data ⇒

Clone this wiki locally