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