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!!' ;