fix: notificación de vencimiento por todos los canales del cliente

Si el cliente tiene Telegram → mensaje por Telegram.
Si el cliente tiene chat web activo → mensaje en la conversación.
Ambos canales pueden coexistir.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro
2026-07-19 02:18:57 +00:00
co-authored by Claude Sonnet 4.6
parent dafe435e69
commit a134ad54a6
+30 -16
View File
@@ -74,23 +74,37 @@ class Kernel extends ConsoleKernel
Notification::sendNow($user, new Vencimiento($notificacion)); Notification::sendNow($user, new Vencimiento($notificacion));
// Notificación por Telegram si el cliente tiene el bot vinculado // Notificación por el canal de chat que tenga el cliente
$contactoTg = ChatContact::where('user_id', $user->id) $fechaFmt = Carbon::parse($item->fecha_final)->format('d/m/Y');
->where('canal', 'telegram') $msgCanal = "⚠️ Aviso de vencimiento\n\n"
->first(); . "Hola {$item->cliente->name}, tu servicio de {$nombre} vence el {$fechaFmt}.\n\n"
. "¿Quieres renovarlo? Escríbeme aquí y te ayudo 👇";
if ($contactoTg && $contactoTg->canal_id) { $contactos = ChatContact::where('user_id', $user->id)->get();
$tokenTg = ChatConfig::get('telegram_token');
if ($tokenTg) { foreach ($contactos as $contacto) {
$fechaFmt = Carbon::parse($item->fecha_final)->format('d/m/Y'); if ($contacto->canal === 'telegram' && $contacto->canal_id) {
$msgTg = "⚠️ *Aviso de vencimiento*\n\n" $tokenTg = ChatConfig::get('telegram_token');
. "Hola {$item->cliente->name}, tu servicio de *{$nombre}* vence el *{$fechaFmt}*.\n\n" if ($tokenTg) {
. "¿Quieres renovarlo? Escríbeme aquí y te ayudo 👇"; Http::get("https://api.telegram.org/bot{$tokenTg}/sendMessage", [
Http::get("https://api.telegram.org/bot{$tokenTg}/sendMessage", [ 'chat_id' => $contacto->canal_id,
'chat_id' => $contactoTg->canal_id, 'text' => "⚠️ *Aviso de vencimiento*\n\n"
'text' => $msgTg, . "Hola {$item->cliente->name}, tu servicio de *{$nombre}* vence el *{$fechaFmt}*.\n\n"
'parse_mode' => 'Markdown', . "¿Quieres renovarlo? Escríbeme aquí y te ayudo 👇",
]); 'parse_mode' => 'Markdown',
]);
}
} elseif ($contacto->canal === 'web') {
$conv = $contacto->activeConversation();
if ($conv) {
\App\Models\ChatMessage::create([
'conversation_id' => $conv->id,
'tipo' => 'bot',
'tipo_ui' => 'text',
'contenido' => $msgCanal,
'leido' => false,
]);
}
} }
} }