Last active
February 23, 2021 11:53
-
-
Save wagura-maurice/e248f81aa71e73ef5b18003cba019b2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use App\Sms; | |
use App\Traits\AT; | |
use Illuminate\Console\Command; | |
class SmsCron extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'sms:cron'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'send bulk sms via hooking to api for bulk sms processing'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
/* | |
Write your sms handle logic bellow: | |
*/ | |
Sms::where([ | |
'_status' => Sms::PROCESSING | |
])->chunk(100, function($SMS) { | |
foreach ($SMS as $key => $sms) { | |
/* | |
hook your sms sending logic bellow: | |
*/ | |
$message = AT::AT(['senderId' => $sms->from] ?? null)->sms()->send([ | |
// $message = AT::AT([])->sms()->send([ | |
'message' => $sms->message, | |
'to' => $sms->to, | |
'from' => $sms->from ?? null, | |
'enqueue' => 0 | |
]); | |
/* | |
save a report after running sms though the hook: | |
*/ | |
if ($message) { | |
Sms::find($sms->id)->update([ | |
'cost' => $message['data']->SMSMessageData->Recipients['0']->cost ?? null, | |
'messageId' => $message['data']->SMSMessageData->Recipients['0']->messageId ?? null, | |
'_status' => $message['data']->SMSMessageData->Recipients['0']->status ?? Sms::SUCCESS | |
]); | |
} | |
} | |
}); | |
$this->info('sms:Cron Command Run Successfully!'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment