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:
co-authored by
Claude Sonnet 4.6
parent
dafe435e69
commit
a134ad54a6
+30
-16
@@ -74,23 +74,37 @@ class Kernel extends ConsoleKernel
|
||||
|
||||
Notification::sendNow($user, new Vencimiento($notificacion));
|
||||
|
||||
// Notificación por Telegram si el cliente tiene el bot vinculado
|
||||
$contactoTg = ChatContact::where('user_id', $user->id)
|
||||
->where('canal', 'telegram')
|
||||
->first();
|
||||
// Notificación por el canal de chat que tenga el cliente
|
||||
$fechaFmt = Carbon::parse($item->fecha_final)->format('d/m/Y');
|
||||
$msgCanal = "⚠️ Aviso de vencimiento\n\n"
|
||||
. "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) {
|
||||
$tokenTg = ChatConfig::get('telegram_token');
|
||||
if ($tokenTg) {
|
||||
$fechaFmt = Carbon::parse($item->fecha_final)->format('d/m/Y');
|
||||
$msgTg = "⚠️ *Aviso de vencimiento*\n\n"
|
||||
. "Hola {$item->cliente->name}, tu servicio de *{$nombre}* vence el *{$fechaFmt}*.\n\n"
|
||||
. "¿Quieres renovarlo? Escríbeme aquí y te ayudo 👇";
|
||||
Http::get("https://api.telegram.org/bot{$tokenTg}/sendMessage", [
|
||||
'chat_id' => $contactoTg->canal_id,
|
||||
'text' => $msgTg,
|
||||
'parse_mode' => 'Markdown',
|
||||
]);
|
||||
$contactos = ChatContact::where('user_id', $user->id)->get();
|
||||
|
||||
foreach ($contactos as $contacto) {
|
||||
if ($contacto->canal === 'telegram' && $contacto->canal_id) {
|
||||
$tokenTg = ChatConfig::get('telegram_token');
|
||||
if ($tokenTg) {
|
||||
Http::get("https://api.telegram.org/bot{$tokenTg}/sendMessage", [
|
||||
'chat_id' => $contacto->canal_id,
|
||||
'text' => "⚠️ *Aviso de vencimiento*\n\n"
|
||||
. "Hola {$item->cliente->name}, tu servicio de *{$nombre}* vence el *{$fechaFmt}*.\n\n"
|
||||
. "¿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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user