Skip to content

Docs ‐ Response

papamarfo edited this page Jul 30, 2026 · 2 revisions

Introduction to response

Various USSD providers have different APIs to communicate with them. Responses provider you with the flexibility to write your application without worry about the response as part of the core of your application.

Built-in Responses

Laravel USSD ships Response implementations for common gateways, so most applications don't need to write their own:

Class Shape
Speso\Ussd\Responses\AfricasTalkingResponse Plain text, prefixed CON /END
Speso\Ussd\Responses\NsanoResponse {"USSDResp": {"action": "input"|"prompt", "menus": "", "title": ...}}
Speso\Ussd\Responses\NaloResponse {"USERID", "MSISDN", "USERDATA", "MSG", "MSGTYPE"}
Speso\Ussd\Responses\MoolreResponse {"message", "reply"}
Speso\Ussd\Responses\ArkeselResponse {"sessionID", "userID", "msisdn", "message", "continueSession"}
<?php

use Speso\Ussd\Responses\AfricasTalkingResponse;
use Speso\Ussd\Ussd;

Ussd::build($context)
    ->useInitialState(WelcomeState::class)
    ->useResponse(AfricasTalkingResponse::class)
    ->run();

ArkeselResponse echoes back a userID, which Arkesel issues per USSD subscription rather than per request — set it via config('services.arkesel.ussd_user_id').

Creating your own response

Targeting a gateway that isn't listed above? Scaffold your own:

php artisan ussd:response YourGatewayResponse

Construct the response your provider is expecting.

<?php

namespace App\Ussd\Responses;

use Speso\Ussd\Contracts\Response;

class YourGatewayResponse implements Response
{
    public function respond(string $message, bool $terminating): mixed
    {
        return [
            'message' => $message,
            'terminating' => $terminating,
        ];
    }
}

Clone this wiki locally