Fix: Solucionados problemas de permisos en Docker y agregada gestion de Webhook de Telegram

This commit is contained in:
2026-04-19 19:23:25 -06:00
parent 249c997257
commit c4bd4b62e3
13 changed files with 615 additions and 98 deletions

View File

@@ -37,7 +37,10 @@ class TelegramController extends Controller
$telegramAccount->update(['verification_code' => $verificationCode]);
}
return view('telegram.verify', compact('telegramAccount'));
return view('telegram.verify', [
'telegramAccount' => $telegramAccount,
'webhookInfo' => (new TelegramBotService())->getWebhookInfo()
]);
}
/**
@@ -98,8 +101,7 @@ class TelegramController extends Controller
Log::info('Telegram webhook received', $update);
if (empty($update)) {
return response()->json(['ok' => true, 'message' => 'No update
received']);
return response()->json(['ok' => true, 'message' => 'No update received']);
}
$botService = new TelegramBotService();
@@ -117,24 +119,32 @@ received']);
}
/**
* Configurar webhook (ruta temporal para configurar desde el navegador)
* Configurar webhook
*/
public function setupWebhook(Request $request)
{
$token = $request->get('token');
// Verificar token de seguridad simple
if ($token !== config('app.key')) {
abort(403, 'Token inválido');
}
$botService = new TelegramBotService();
$result = $botService->setWebhook();
if ($result) {
return response()->json(['success' => true, 'message' => 'Webhook configurado correctamente']);
return back()->with('success', 'Webhook configurado correctamente.');
}
return response()->json(['success' => false, 'error' => 'Error al configurar webhook'], 500);
return back()->with('error', 'Error al configurar webhook.');
}
/**
* Borrar webhook
*/
public function deleteWebhook(Request $request)
{
$botService = new TelegramBotService();
$result = $botService->deleteWebhook();
if ($result) {
return back()->with('success', 'Webhook borrado correctamente.');
}
return back()->with('error', 'Error al borrar el webhook.');
}
}

View File

@@ -297,4 +297,40 @@ class TelegramBotService
return false;
}
}
/**
* Obtener información del webhook
*/
public function getWebhookInfo(): array
{
if (!$this->botToken) {
return ['ok' => false, 'error' => 'Bot token not configured'];
}
try {
$response = Http::get("https://api.telegram.org/bot{$this->botToken}/getWebhookInfo");
return $response->json();
} catch (\Exception $e) {
Log::error('Telegram get webhook info error', ['error' => $e->getMessage()]);
return ['ok' => false, 'error' => $e->getMessage()];
}
}
/**
* Borrar webhook
*/
public function deleteWebhook(): bool
{
if (!$this->botToken) {
return false;
}
try {
$response = Http::post("https://api.telegram.org/bot{$this->botToken}/deleteWebhook");
return $response->json('ok', false);
} catch (\Exception $e) {
Log::error('Telegram delete webhook error', ['error' => $e->getMessage()]);
return false;
}
}
}