PHP code example of nugsoft / signalbridge-laravel-sdk
1. Go to this page and download the library: Download nugsoft/signalbridge-laravel-sdk 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/ */
nugsoft / signalbridge-laravel-sdk example snippets
use Nugsoft\SignalBridge\Facades\SignalBridge;
// SMS
SignalBridge::sms()->send('256700000000', 'Hello from SignalBridge!');
// WhatsApp
SignalBridge::whatsapp()->send('256700000000', 'Hello on WhatsApp!');
// Mobile Money — collect payment
SignalBridge::mobileMoney()->initiate('256700000000', 5000);
// Mobile Money — send payout
SignalBridge::mobileMoney()->disburse('256700000000', 50000);
use Nugsoft\SignalBridge\SignalBridgeClient;
class NotificationService
{
public function __construct(private SignalBridgeClient $signalBridge) {}
public function sendWelcome(string $phone, string $name): void
{
$this->signalBridge->sms()->send($phone, "Welcome {$name}!");
}
}
$result = SignalBridge::sms()->send(
recipient: '256700000000',
message: 'Your OTP is 123456',
options: [
'sender_id' => 'MyApp', // Optional
'metadata' => ['user_id' => 42], // Optional: stored for your records
'is_test' => false, // Optional: test mode (no charge)
'scheduled_at' => '2026-06-01T09:00:00Z', // Optional: ISO 8601
]
);
// $result['data']['message_id'], $result['data']['cost'], $result['data']['status']
// Save messages to a file
$csv = SignalBridge::exportMessages(['start_date' => '2026-04-01']);
Storage::put('exports/messages.csv', $csv);
// Save transactions to a file
$csv = SignalBridge::exportTransactions(['type' => 'debit']);
Storage::put('exports/transactions.csv', $csv);
// Register a webhook
$webhook = SignalBridge::createWebhook(
url: 'https://yourapp.com/webhooks/signalbridge',
events: ['message.delivered', 'message.failed', 'payment.completed'],
isActive: true
);
$secret = $webhook['data']['secret']; // Store this — shown only once
// List, update, delete
$list = SignalBridge::listWebhooks();
SignalBridge::updateWebhook($webhookId, ['is_active' => false]);
SignalBridge::deleteWebhook($webhookId);
// Rotate secret
$new = SignalBridge::regenerateWebhookSecret($webhookId);
use Nugsoft\SignalBridge\Exceptions\InsufficientBalanceException;
use Nugsoft\SignalBridge\Exceptions\InsufficientPermissionsException;
use Nugsoft\SignalBridge\Exceptions\NoClientException;
use Nugsoft\SignalBridge\Exceptions\RateLimitedException;
use Nugsoft\SignalBridge\Exceptions\ServiceUnavailableException;
use Nugsoft\SignalBridge\Exceptions\SignalBridgeException;
use Nugsoft\SignalBridge\Exceptions\UnauthorizedException;
use Nugsoft\SignalBridge\Exceptions\ValidationException;
try {
SignalBridge::sms()->send('256700000000', 'Hello');
} catch (InsufficientBalanceException $e) {
$
use Nugsoft\SignalBridge\Facades\SignalBridge;
use Illuminate\Support\Facades\Cache;
public function sendOtp(Request $request): \Illuminate\Http\JsonResponse
{
$code = random_int(100000, 999999);
Cache::put("otp:{$request->phone}", $code, now()->addMinutes(5));
SignalBridge::sms()->send(
recipient: $request->phone,
message: "Your verification code is {$code}. Valid for 5 minutes.",
options: ['metadata' => ['action' => 'otp', 'ip' => $request->ip()]]
);
return response()->json(['success' => true]);
}
use App\Models\User;
use Nugsoft\SignalBridge\Facades\SignalBridge;
// Simple — send one message to all active users
User::where('is_active', true)
->select('phone', 'name')
->chunk(100, function ($users) {
$messages = $users->map(fn ($user) => [
'recipient' => $user->phone,
'message' => "Hi {$user->name}, your account has been updated.",
'metadata' => ['user_id' => $user->id],
])->toArray();
SignalBridge::sms()->sendBatch($messages);
});
// Personalised messages — different content per recipient
$notifications = Notification::with('user')
->where('status', 'pending')
->get()
->chunk(100);
foreach ($notifications as $batch) {
$messages = $batch->map(fn ($n) => [
'recipient' => $n->user->phone,
'message' => $n->body,
'metadata' => ['notification_id' => $n->id],
])->toArray();
$result = SignalBridge::sms()->sendBatch($messages);
// Mark sent
$batch->each->update(['status' => 'sent']);
}
// With balance check before sending
$phones = User::where('subscribed', true)->pluck('phone');
$balance = SignalBridge::getBalance('UGX');
$cost = $phones->count() * SignalBridge::sms()->calculateSegments($message) * $balance['segment_price'];
if ($balance['available_balance'] < $cost) {
throw new \RuntimeException("Insufficient balance. Need {$cost} UGX, have {$balance['available_balance']} UGX.");
}
$phones->chunk(100)->each(function ($chunk) use ($message) {
SignalBridge::sms()->sendBatch(
$chunk->map(fn ($phone) => ['recipient' => $phone, 'message' => $message])->toArray()
);
});