PHP code example of helliosolutions / helliosms

1. Go to this page and download the library: Download helliosolutions/helliosms 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/ */

    

helliosolutions / helliosms example snippets


use Hellio\HellioMessaging\Facades\HellioMessaging;

// Account
HellioMessaging::balance();            // ['data' => ['balance' => '195.0000', 'available' => '194.65', ...]]
HellioMessaging::pricing('GH');        // optional ISO-2 country filter

// SMS (recipients: string, comma list, or array)
HellioMessaging::sms('233241234567', 'Hello!');
HellioMessaging::sms(['233241234567', '233201234567'], 'Hi all', 'HellioSMS');
HellioMessaging::message(1024);        // delivery status
HellioMessaging::campaign(1024);       // campaign summary

// OTP — sender (Sender ID) is REQUIRED for sms/voice and must be approved on your account.
// Optional length (4–10 digits) and expiry (minutes). Returns status "queued".
HellioMessaging::otp('233241234567', 'HellioSMS');                          // SMS
HellioMessaging::otp('233241234567', 'HellioSMS', 'voice');                 // Voice (TTS reads the code)
HellioMessaging::otp('233241234567', channel: 'whatsapp');                  // WhatsApp (no sender)
HellioMessaging::otp('233241234567', 'HellioSMS', length: 6, expiry: 10);   // custom length / expiry
HellioMessaging::otp('[email protected]', channel: 'email');                 // Email (no sender)
HellioMessaging::verify('233241234567', '123456');                          // bool
HellioMessaging::verifyOtp('[email protected]', '123456', 'email');          // full response

// Voice broadcast — text (we TTS it) or a hosted audio_url
HellioMessaging::voice('233241234567', 'HELLIO', text: 'Your code is 1 2 3 4');
HellioMessaging::voice(['233241234567'], 'HELLIO', audioUrl: 'https://cdn.example.com/promo.mp3');

// Number lookup (HLR) — async; poll results
HellioMessaging::lookup(['233241234567']);
HellioMessaging::lookups();
HellioMessaging::lookupResult(5);

// Email verification
HellioMessaging::verifyEmail(['[email protected]', '[email protected]']);

// Webhooks (receive delivery reports)
HellioMessaging::createWebhook('https://your-app.com/hooks/hellio', ['message.delivered', 'message.failed']);
HellioMessaging::webhooks();
HellioMessaging::deleteWebhook(1);

// Pricing and availability
HellioMessaging::ussd()->pricing();               // short code + session/extension prices
HellioMessaging::ussd()->availability(100);       // ['data' => ['valid' => true, 'available' => true, ...]]

// Apps (your callback endpoints) - new apps start in "test" mode
$app = HellioMessaging::ussd()->createApp('Airtime top-up', 'https://your-app.com/ussd');
$id = $app['data']['id'];                          // UUID string
$testSecret = $app['data']['test_secret'];         // ussk_test_...  (verify sandbox callbacks)
$liveSecret = $app['data']['live_secret'];         // ussk_live_...  (verify live callbacks)
HellioMessaging::ussd()->apps();
HellioMessaging::ussd()->updateApp($id, 'Airtime top-up', 'https://your-app.com/ussd', true);
HellioMessaging::ussd()->deleteApp($id);

// Simulate a dial against your callback (always sandbox/test mode, by app_id).
// No real handset, no charge, no extension needed. serviceCode is optional and
// defaults to the shared short code.
$step = HellioMessaging::ussd()->simulate($id, 'sess-1', '233241234567', '', newSession: true);
// $step['data'] => ['message' => 'Welcome', 'action' => 'continue', 'continue' => true]

// Extensions (rent a dialer code from your USSD balance, optionally bound to an app)
$ext = HellioMessaging::ussd()->rentExtension(100, $id);
HellioMessaging::ussd()->extensions();
HellioMessaging::ussd()->releaseExtension($ext['data']['id']);

// Go live once the app has an extension, and rotate a secret when needed
HellioMessaging::ussd()->setMode($id, 'live');
HellioMessaging::ussd()->rotateSecret($id, 'live');   // "test" or "live"

// Sessions (audit trail)
HellioMessaging::ussd()->sessions('ended');
HellioMessaging::ussd()->session($id);

public function handle(\Illuminate\Http\Request $request)
{
    $secret = $request->input('mode') === 'live'
        ? config('services.hellio.ussd_live_secret')
        : config('services.hellio.ussd_test_secret');
    $expected = hash_hmac('sha256', $request->getContent(), $secret);
    abort_unless(hash_equals($expected, $request->header('X-Hellio-Signature', '')), 403);

    return response()->json([
        'message' => 'Welcome to Airtime top-up',
        'action' => 'continue',
    ]);
}

use Hellio\HellioMessaging\Message\HellioMessagingSms;

class OrderShipped extends \Illuminate\Notifications\Notification
{
    public function via($notifiable): array { return ['helliomessaging']; }

    public function toHellioMessaging($notifiable): HellioMessagingSms
    {
        return (new HellioMessagingSms())
            ->message('Your order has shipped!')
            ->sender('HellioSMS');
    }
}

public function routeNotificationForHelliomessaging($notification) { return $this->phone; }

$request->validate([
    'mobile_number' => 'ber',
]);

use Hellio\HellioMessaging\Exceptions\InsufficientBalanceException;

try {
    HellioMessaging::sms('233241234567', 'Hi');
} catch (InsufficientBalanceException $e) {
    // top up
}
bash
php artisan vendor:publish --tag=helliomessaging