PHP code example of gantry-motion / ussd-monkey

1. Go to this page and download the library: Download gantry-motion/ussd-monkey library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gantry-motion / ussd-monkey example snippets


$config = [
    'environment' => 'development',
    'ussd_menu_file' => ROOTPATH . 'ussdMenu.json',
    'custom_class_namespace' => 'App\Controllers\USSD'
];

$ussd = new USSDMonkey($config);
$ussd->push($params, $menu);

$ussd = new USSDMonkey($config);
$current_config = $ussd->configInfo();
echo json_encode($current_config);

use GantryMotion\USSDMonkey\USSDMonkey;

$config = [
    'ussd_menu_file' => 'path/to/ussdMenu.json',
    'custom_class_namespace' => 'App\Controllers\USSD',
    // Override other configuration options as needed
];

$params = $_POST;
$ussd = new USSDMonkey($config);
$ussd->push($params, 'default_menu');

namespace App\Controllers;

class USSD
{
    public function say_hello($data)
    {
        $name = $data[1];
        $display = "Hello " . $name;
        return $display;
    }

    public function get_people_titles($data)
    {
        $titles = ["1" => "Mr", "2" => "Mrs", "3" => "Ms", "4" => "Dr"];

        $title_list = [];
        foreach ($titles as $key => $value) {
            $title_list[] = $key . ' ' . $value;
        }
        $display = "Select Title" . PHP_EOL;
        $display .= implode('|', $title_list);
        return $display;
    }

    public function say_goodbye($data)
    {
        $name = $data[1];
        $index = $data[2];

        $titles = ["1" => "Mr", "2" => "Mrs", "3" => "Ms", "4" => "Dr"];

        $display = "Goodbye " . $titles[$index] . " " . $name;
        return $display;
    }

    public function say_goodnight_sweet_dreams($data)
    {
        $name = $data[1];
        $display = "Good night " . $name . ", and sweet dreams";
        return $display;
    }

    public function say_goodnight_bedbugs_dont_bite($data)
    {
        $name = $data[1];
        $display = "Good night " . $name . ", and don't let the bedbugs bite";
        return $display;
    }
}