<?php
// Telegram Bot Token (از BotFather بگیر)
$botToken = "8545250481:AAEmnOdPusKE9CHmTOGd-cJX7GuO15NRXhk";
$apiUrl = "https://api.telegram.org/bot$botToken/";

// دریافت داده‌های ارسال‌شده از تلگرام
$content = file_get_contents("php://input");
$update = json_decode($content, true);

// اگر داده‌ای نرسید، خروج
if (!$update) {
    exit;
}

// استخراج اطلاعات پیام
if (isset($update["message"])) {
    $message = $update["message"];
    $chatId = $message["chat"]["id"];
    $text = $message["text"] ?? "";
    
    // اگر کاربر دستور /start رو فرستاده بود
    if ($text === "/start") {
        sendMessage($chatId, "سلام! 👋 به بات خوش اومدی!");
    }
}

// تابع ارسال پیام به تلگرام
function sendMessage($chatId, $message) {
    global $apiUrl;
    
    $data = [
        "chat_id" => $chatId,
        "text" => $message,
        "parse_mode" => "HTML"
    ];
    
    $options = [
        "http" => [
            "header" => "Content-Type: application/x-www-form-urlencoded\r\n",
            "method" => "POST",
            "content" => http_build_query($data)
        ]
    ];
    
    $context = stream_context_create($options);
    file_get_contents($apiUrl . "sendMessage", false, $context);
}
?>