<?php
// ============================================================
// setup_webhook.php — Register Telegram Webhook
// ============================================================
// Open this file ONCE in browser to activate the bot webhook.
// URL: https://yourdomain.com/php/setup_webhook.php

require_once __DIR__ . '/config.php';

// Your bot.php webhook URL — change domain to your actual domain
$webhookUrl = 'https://yourdomain.com/php/bot.php';

// Override via query param: ?url=https://...
if (!empty($_GET['url'])) {
    $webhookUrl = trim($_GET['url']);
}

$apiUrl = BOT_API . "/setWebhook?url=" . urlencode($webhookUrl);
$result = @file_get_contents($apiUrl);
$json   = json_decode($result, true);
?>
<!DOCTYPE html>
<html>
<head><title>Webhook Setup</title>
<style>body{font-family:monospace;background:#0a0a12;color:#e2e8f0;padding:40px;} pre{background:#111120;padding:20px;border-radius:10px;border:1px solid rgba(255,255,255,.1)}</style>
</head>
<body>
<h2>🔗 Webhook Setup</h2>
<p>Webhook URL: <code><?= htmlspecialchars($webhookUrl) ?></code></p>
<pre><?= htmlspecialchars(json_encode($json, JSON_PRETTY_PRINT)) ?></pre>
<?php if ($json['ok'] ?? false): ?>
<p style="color:#22d3a5">✅ Webhook registered successfully!</p>
<?php else: ?>
<p style="color:#f87171">❌ Failed. Check the URL and try again.</p>
<p>Usage: <code>setup_webhook.php?url=https://yourdomain.com/php/bot.php</code></p>
<?php endif; ?>
</body>
</html>
