PHP İle Telegram API Kullanarak Görsel Göndermek

24 Haziran 2023 413 Okuma süresi: 45 saniye
function sendPhotoToUser($chatId, $photoUrl, $botToken) {
    $url = "https://api.telegram.org/bot{$botToken}/sendPhoto";
    $data = array(
        'chat_id' => $chatId,
        'photo' => $photoUrl
    );

    $ch = curl_init()
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    $responseData = json_decode($response);

    if ($responseData->ok) {
        return true;
    } else {
        return false;
    }
}

Benzer makaleler