# USSD Sample Code

## Sample USSD Menu Code

Below is a sample 2-level USSD menu in PHP. \
\
This can be extended in the same format to an unlimited menu level within the session timeout period permitted on the USSDC.

```php
<?php

/*
* Read HTTP GET values
*/

$session_msisdn = $_GET['session_msisdn'];
$session_operation = $_GET['session_operation']; /* begin, continue, end */
$session_type = $_GET['session_type']; /* 1, 2, 3, 4 */
$session_msg = trim($_GET['session_msg']);
$session_id = $_GET['session_id'];
$session_from = $_GET['session_from']; /* shortcode */

/*
* Depending on the USSD operation category, send a corresponding 
* response message back to the subscriber.
*/

if (strcmp($session_operation, "begin") == 0) {
    $output['session_operation'] = "continue";
    $output['session_type'] = 1;
    $output['session_id'] = $session_id;
    $output['session_msg'] = "Welcome to eBanking.\nPlease select your payment channel.\n1) Card\n2) Bank Account\n3) Wallet";
} elseif (strcmp($session_operation, "continue") == 0) {
    $output['session_operation'] = "end";
    $output['session_type'] = 4;
    $output['session_id'] = $session_id;

    /*
    * Below is the business logic based on the response of the user.
    * You can pass this to your database, internal system etc.
    */

    switch ($session_msg) {
        case 1:
            $channel = "Card";

            break;
        case 2:
            $channel = "Bank Account";

            break;
        case 3:
            $channel = "Wallet";

            break;
        default:
            $channel = "NONE";
    }

    $output['session_msg'] = "You selected -$channel-. Have a great day.";
} else {
    $output['session_operation'] = "end";
    $output['session_type'] = 4;
    $output['session_id'] = $session_id;
    $output['session_msg'] = "Thank you.";
}

echo json_encode($output); /* this JSON output goes to the USSDC */

exit;

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hollatags.com/ussd/ussd-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
