feat: notificación de vencimiento por Telegram
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
656b32c706
commit
dafe435e69
@@ -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!!' ;
|
||||
|
||||
Reference in New Issue
Block a user