requireAdmin(); $bot = new TelegramBot(); $message = ''; $messageType = ''; $webhookInfo = null; $botInfo = null; // Obtener información del bot $botMe = $bot->getMe(); if ($botMe && isset($botMe['ok']) && $botMe['ok']) { $botInfo = $botMe['result']; } // Verificar estado del webhook if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; if ($action === 'verificar') { $url = "https://api.telegram.org/bot{$config['telegram_bot_token']}/getWebhookInfo"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $result = json_decode($response, true); if ($result && isset($result['ok'])) { $webhookInfo = $result; $message = 'Información del webhook obtenida'; $messageType = 'success'; } else { $message = 'Error al obtener información del webhook'; $messageType = 'danger'; } } elseif ($action === 'borrar') { $url = "https://api.telegram.org/bot{$config['telegram_bot_token']}/deleteWebhook"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([])); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $result = json_decode($response, true); if ($result && isset($result['ok']) && $result['ok']) { $message = 'Webhook eliminado correctamente'; $messageType = 'success'; $webhookInfo = null; } else { $message = 'Error al eliminar webhook: ' . ($result['description'] ?? 'Desconocido'); $messageType = 'danger'; } } elseif ($action === 'configurar') { $webhookUrl = trim($_POST['webhook_url'] ?? ''); if (empty($webhookUrl)) { $message = 'Debes ingresar la URL del webhook'; $messageType = 'danger'; } elseif (!filter_var($webhookUrl, FILTER_VALIDATE_URL)) { $message = 'La URL ingresada no es válida'; $messageType = 'danger'; } else { $url = "https://api.telegram.org/bot{$config['telegram_bot_token']}/setWebhook"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ 'url' => $webhookUrl, 'allowed_updates' => ['message', 'callback_query'] ])); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $result = json_decode($response, true); if ($result && isset($result['ok']) && $result['ok']) { $message = "Webhook configurado correctamente en:\n" . htmlspecialchars($webhookUrl); $messageType = 'success'; } else { $message = 'Error al configurar webhook: ' . ($result['description'] ?? 'Desconocido'); $messageType = 'danger'; } } } } // Obtener estado actual del webhook $url = "https://api.telegram.org/bot{$config['telegram_bot_token']}/getWebhookInfo"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $webhookInfo = json_decode($response, true); $currentPage = 'webhook'; $pageTitle = 'Administración del Bot de Telegram'; ?>
Nombre: = htmlspecialchars($botInfo['first_name']) ?>
Username: @= htmlspecialchars($botInfo['username']) ?>
ID: = $botInfo['id'] ?>
Estado: Conectado
URL: = htmlspecialchars($webhookInfo['result']['url']) ?>
No hay webhook configurado para este bot.
| Comando | Descripción |
|---|---|
/start o /menu |
Muestra el menú interactivo con botones |
/turnos |
Muestra la tabla completa de asignaciones |
/semana o hoy |
Muestra quién tiene turno esta semana |
/ayudantes |
Lista de todos los ayudantes |
[Nombre] |
Busca los turnos de un ayudante específico |
= htmlspecialchars($config['site_url'] ?? 'https://tu-dominio.com') ?>/bot/webhook.php
= $site_url ?? 'https://tu-dominio.com' ?>/bot/test.php