-
Notifications
You must be signed in to change notification settings - Fork 35
Docs ‐ Action
Isaac Sai edited this page Jan 20, 2024
·
1 revision
USSD action let you introduce branching into your application based on some conditions. When transitioning between state, there are times you may want to transition based on certain condition. Action let you do that easily.
php artisan ussd:action MakePaymentAction
You can use action as the first initial state by using the init option in the create command.
php artisan ussd:action MenuAction --init
Write your logic to return the next state or action.
<?php
namespace App\Ussd\Actions;
use App\Models\Customer;
use App\Ussd\States\CustomerMenuState;
use App\Ussd\States\GuestMenuState;
use Sparors\Ussd\Context;
use Sparors\Ussd\Contracts\InitialAction;
class MenuAction implements InitialAction
{
public function execute(Context $context): string
{
$isRegistered = Customer::query()
->where('phone_number', $context->get('phone_number'))
->exists();
return $isRegistered ? CustomerMenuState::class : GuestMenuState::class;
}
}