WIP
This commit is contained in:
@@ -56,6 +56,57 @@ if (! function_exists('sendSMS')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('sendBulkSMS')) {
|
||||
/**
|
||||
* Send bulk SMS
|
||||
*
|
||||
* @param array<int, array{phone: string, message: string}> $messages
|
||||
*/
|
||||
function sendBulkSMS(array $messages): bool
|
||||
{
|
||||
try {
|
||||
$response = Http::timeout(config('services.sms.timeout'))
|
||||
->connectTimeout(config('services.sms.connect_timeout'))
|
||||
->retry(
|
||||
times: 3,
|
||||
sleepMilliseconds: 50,
|
||||
throw: false,
|
||||
when: function (Throwable $exception, PendingRequest $request): bool {
|
||||
if ($exception instanceof ConnectionException) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($exception instanceof RequestException) {
|
||||
return $exception->response->serverError();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
)
|
||||
->post(config('services.sms.url').'/bulk', [
|
||||
'messages' => $messages,
|
||||
]);
|
||||
|
||||
if (! $response->successful()) {
|
||||
Log::error('Bulk SMS API request failed', [
|
||||
'status' => $response->status(),
|
||||
'body' => $response->body(),
|
||||
]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Throwable $exception) {
|
||||
Log::error('Bulk SMS API exception', [
|
||||
'message' => $exception->getMessage(),
|
||||
]);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('unmask_phone')) {
|
||||
/**
|
||||
* Unmask Turkmenistan phone number from TM code +993 6X XX XX XX to 6xxxxxxx
|
||||
|
||||
Reference in New Issue
Block a user