WIP
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Jobs\StartSmsCampaignJob;
|
||||
use App\Models\Coupon;
|
||||
use App\Services\SmsBroadcastService;
|
||||
use App\Services\SmsMessageAnalyzer;
|
||||
@@ -156,9 +155,10 @@ class SendSms extends Page
|
||||
$excludedIds = array_map('intval', $data['excluded_coupon_ids'] ?? []);
|
||||
|
||||
$service = app(SmsBroadcastService::class);
|
||||
$willReceive = $service->resolveRecipients($sendToAll, $selectedIds, $excludedIds)
|
||||
->filter(fn (Coupon $coupon): bool => is_valid_coupon_phone($coupon->phone))
|
||||
->count();
|
||||
$recipients = $service->resolveRecipients($sendToAll, $selectedIds, $excludedIds)
|
||||
->filter(fn (Coupon $coupon): bool => is_valid_coupon_phone($coupon->phone));
|
||||
|
||||
$willReceive = $recipients->count();
|
||||
|
||||
if ($willReceive === 0) {
|
||||
Notification::make()
|
||||
@@ -170,19 +170,26 @@ class SendSms extends Page
|
||||
return;
|
||||
}
|
||||
|
||||
StartSmsCampaignJob::dispatch(
|
||||
adminId: auth()->id(),
|
||||
message: $data['message'],
|
||||
sendToAll: $sendToAll,
|
||||
selectedIds: $selectedIds,
|
||||
excludedIds: $excludedIds,
|
||||
);
|
||||
$messages = $recipients->map(fn (Coupon $coupon): array => [
|
||||
'phone' => '+993'.$coupon->phone,
|
||||
'message' => $data['message'],
|
||||
])->values()->all();
|
||||
|
||||
Notification::make()
|
||||
->title(__('filament.send_sms.notifications.submitted'))
|
||||
->body(__('filament.send_sms.notifications.submitted_body', ['count' => $willReceive]))
|
||||
->success()
|
||||
->send();
|
||||
$success = sendBulkSMS($messages);
|
||||
|
||||
if ($success) {
|
||||
Notification::make()
|
||||
->title(__('filament.send_sms.notifications.submitted'))
|
||||
->body(__('filament.send_sms.notifications.submitted_body', ['count' => $willReceive]))
|
||||
->success()
|
||||
->send();
|
||||
} else {
|
||||
Notification::make()
|
||||
->title(__('filament.send_sms.notifications.failed'))
|
||||
->body(__('filament.send_sms.notifications.failed_body'))
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
|
||||
protected function confirmationDescription(): string
|
||||
|
||||
Reference in New Issue
Block a user