#!/usr/bin/env php * * Ejemplo: php setup_webhook.php https://contenedor-test.local:82/bot/webhook.php * * Requiere: TELEGRAM_BOT_TOKEN configurado en .env */ require_once __DIR__ . '/../config/config.php'; $config = require __DIR__ . '/../config/config.php'; $token = $config['telegram_bot_token']; if (empty($token)) { echo "ERROR: TELEGRAM_BOT_TOKEN no configurado en .env\n"; exit(1); } $urlWebhook = $argv[1] ?? "https://contenedor-test.local:82/bot/webhook.php"; echo "Configurando webhook...\n"; echo "URL: {$urlWebhook}\n\n"; $url = "https://api.telegram.org/bot{$token}/setWebhook"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ 'url' => $urlWebhook, '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 && $result['ok']) { echo "Webhook configurado correctamente!\n\n"; echo "Ahora ve a Telegram y envia /start al bot\n"; } else { echo "Error al configurar webhook:\n"; print_r($result); exit(1); }