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 <cursoragent@cursor.com>
This commit is contained in:
2026-08-24 22:31:27 +03:30
co-authored by Cursor
parent 1c8ab4b725
commit 4562d00bd3
+14 -6
View File
@@ -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