File: /var/www/console.fixgini.com/app/Jobs/SendDelayedSms.php
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class SendDelayedSms implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $phone;
protected $message;
public function __construct(string $phone, string $message)
{
$this->phone = $phone;
$this->message = $message;
}
public function handle()
{
// Format phone number
if (substr($this->phone, 0, 1) === '0') {
$this->phone = '234' . substr($this->phone, 1);
}
// Prepare SMS body
$body = [
'api_key' => config('services.termii.api'),
'to' => $this->phone,
'from' => 'N-Alert',
'sms' => \Illuminate\Support\Str::limit($this->message, 160),
'type' => 'plain',
'channel' => 'dnd',
];
// Send the SMS using Termii API
$response = Http::post('https://api.ng.termii.com/api/sms/send', $body);
info('SMS reminder sent successfuly');
if (!$response->successful()) {
Log::error('SMS sending failed: ' . $response->body());
}
}
}