<?php
// Run once to configure Rubika webhook endpoints.
$config = require __DIR__ . '/config.php';
$token = trim((string)$config['tokens']['rubika']);

if ($token === '' || $token === 'PUT_RUBIKA_BOT_TOKEN_HERE') {
    die("Please set rubika token in config.php first.\n");
}

$targetUrl = "https://bridge.proprompter.ir/sync_bot.php?source=rubika";
$url = "https://botapi.rubika.ir/v3/" . $token . "/updateBotEndpoints";
$data = [
    "url" => $targetUrl,
    "type" => "ReceiveUpdate"
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);

echo "Rubika Webhook Result: " . $res . PHP_EOL;
?>
