From dafe435e6924b8bbe4a2e7903373b7678baa0af3 Mon Sep 17 00:00:00 2001 From: Lizandro Date: Sun, 19 Jul 2026 02:17:54 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20notificaci=C3=B3n=20de=20vencimiento=20?= =?UTF-8?q?por=20Telegram?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cuando el servicio de un cliente vence mañana, además del email existente se envía mensaje por Telegram si el cliente tiene el bot vinculado. Busca en chat_contacts canal=telegram con el user_id del cliente. Co-Authored-By: Claude Sonnet 4.6 --- app/Console/Kernel.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 2ab4431..1b189fc 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -9,12 +9,15 @@ use App\Models\Cuentas; use App\Models\log; use App\Models\Configuracione; use App\Models\Historial_cuenta; +use App\Models\ChatContact; +use App\Models\ChatConfig; use App\Notifications\Vencimiento; use Carbon\Carbon; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Exception; +use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Notification; use Twilio\Rest\Client; @@ -71,6 +74,26 @@ 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(); + + 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', + ]); + } + } + //$fecha=Carbon::parse($item->fecha_final)->format('d/m/Y'); //$message = 'Su '.$nombre.', Vence Hoy, '.$fecha.'. Renueva ahora!!' ;