<?php
require_once 'config.php';

$data = json_decode(file_get_contents("php://input"), true);
$message = $data['message'] ?? '';
$specificChatId = $data['chat_id'] ?? null;

if ($message) {
    $targetChatIds = $specificChatId ? [$specificChatId] : $chatIds;

    foreach($targetChatIds as $chatId) {
        $url = "https://api.telegram.org/bot$botToken/sendMessage";
        
        $postFields = [
            'chat_id' => $chatId,
            'text' => $message,
            'parse_mode' => 'HTML',
            'disable_web_page_preview' => true
        ];

        $ch = curl_init();
        curl_setopt_array($ch, [
            CURLOPT_URL => $url,
            CURLOPT_POST => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POSTFIELDS => $postFields
        ]);
        
        $response = curl_exec($ch);
        $curlError = curl_error($ch);
        curl_close($ch);
    }
}
?>