From 4562d00bd38f39c44d9724db676d7f4a5c536001 Mon Sep 17 00:00:00 2001 From: adonis Date: Mon, 24 Aug 2026 22:31:27 +0330 Subject: [PATCH] fix(automations): log skipped sends with cooldown/max reason Schedule runs that hit cooldown or max-send limits now write a skipped row to automation_sends so admins can see why no SMS was sent. Co-authored-by: Cursor --- app/Services/Automation/AutomationSender.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/Services/Automation/AutomationSender.php b/app/Services/Automation/AutomationSender.php index 383cda7..a8e3a4a 100644 --- a/app/Services/Automation/AutomationSender.php +++ b/app/Services/Automation/AutomationSender.php @@ -23,7 +23,10 @@ class AutomationSender public function send(Automation $auto, Customer $customer, string $channel, bool $force = false): bool { - if (! $this->maySend($auto, $customer, $channel, $force)) { + $skipReason = $this->skipReason($auto, $customer, $channel, $force); + if ($skipReason !== null) { + $this->log($auto, $customer, $channel, 'skipped', $skipReason); + return false; } @@ -72,13 +75,18 @@ class AutomationSender } public function maySend(Automation $auto, Customer $customer, string $channel, bool $force = false): bool + { + return $this->skipReason($auto, $customer, $channel, $force) === null; + } + + private function skipReason(Automation $auto, Customer $customer, string $channel, bool $force = false): ?string { if (! $auto->usesChannel($channel)) { - return false; + return 'کانال غیرفعال'; } if ($force) { - return true; + return null; } $max = $auto->max_sends; @@ -90,7 +98,7 @@ class AutomationSender ->where('status', 'sent') ->count(); if ($count >= (int) $max) { - return false; + return 'حداکثر ارسال برای این مشتری'; } } @@ -104,11 +112,11 @@ class AutomationSender ->where('created_at', '>=', now()->subHours($cooldown)) ->exists(); if ($recent) { - return false; + return "فاصلهٔ حداقل {$cooldown} ساعت از آخرین ارسال"; } } - return true; + return null; } private function ensureAppNameFooter(string $message): string