GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
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());
        }
    }
}