Fix: Corregida verificacion de Telegram y configurado TrustProxies para HTTPS
This commit is contained in:
@@ -14,10 +14,8 @@ class TelegramBotService
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->botToken = config('services.telegram.bot_token', env('TELEGRAM_BOT_TOKEN'));
|
||||
|
||||
$appUrl = config('app.url', env('APP_URL', 'http://nomina-pegaso.casa'));
|
||||
$this->webhookUrl = rtrim($appUrl, '/') . '/telegram/webhook';
|
||||
$this->botToken = config('services.telegram.bot_token');
|
||||
$this->webhookUrl = rtrim(config('app.url'), '/') . '/telegram/webhook';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,30 +54,33 @@ class TelegramBotService
|
||||
*/
|
||||
private function handleUnverifiedUser(string $chatId, string $text): array
|
||||
{
|
||||
// Si es un código de verificación
|
||||
// Si es un código de verificación (6 dígitos numéricos)
|
||||
if (strlen($text) === 6 && is_numeric($text)) {
|
||||
$telegramAccount = TelegramAccount::where('chat_id', $chatId)
|
||||
->where('verification_code', $text)
|
||||
// Buscamos la cuenta que tiene este código de verificación y no está verificada
|
||||
$telegramAccount = TelegramAccount::where('verification_code', $text)
|
||||
->where('is_verified', false)
|
||||
->first();
|
||||
|
||||
if ($telegramAccount) {
|
||||
// Actualizar la cuenta con el chat_id del usuario que mandó el código
|
||||
$telegramAccount->update([
|
||||
'chat_id' => $chatId,
|
||||
'is_verified' => true,
|
||||
'verification_code' => null
|
||||
]);
|
||||
|
||||
$user = $telegramAccount->user;
|
||||
$this->sendMessage($chatId, "¡Verificación exitosa! Tu cuenta de Telegram está vinculada a {$user->name}. Ahora recibirás notificaciones de tus comisiones.");
|
||||
$this->sendMessage($chatId, "¡Hola {$user->name}! 👋\n\nVerificación exitosa. Tu cuenta de Telegram ha sido vinculada correctamente. Ahora puedes usar comandos como /resumen para ver tu estado.");
|
||||
|
||||
return ['ok' => true, 'verified' => true];
|
||||
} else {
|
||||
$this->sendMessage($chatId, "Código de verificación inválido. Por favor intenta con el código correcto.");
|
||||
$this->sendMessage($chatId, "❌ El código $text es inválido o ya ha sido usado. Por favor, genera un código nuevo en tu panel de usuario.");
|
||||
return ['ok' => true, 'verified' => false];
|
||||
}
|
||||
}
|
||||
|
||||
// Mensaje de bienvenida para usuarios no verificados
|
||||
$this->sendMessage($chatId, "¡Hola! Para usar este bot necesitas verificar tu cuenta.\n\nPor favor ingresa el código de verificación de 6 dígitos que encontrarás en la sección de Telegram de tu panel de usuario.");
|
||||
$this->sendMessage($chatId, "👋 ¡Hola! Soy el bot de Nómina Pegaso.\n\nPara usar este bot, primero debes vincular tu cuenta:\n\n1️⃣ Ve a tu panel web\n2️⃣ Sección Telegram -> Vincular\n3️⃣ Envía aquí el código de 6 dígitos que veas allá.");
|
||||
|
||||
return ['ok' => true, 'verified' => false];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user