0
votes

I want to sent documents and photos with the Telegram API. Problem is, that once it's sent, it's cached in on there servers. But if my document changes, I send old versions. For the documentation says:

Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data

But I'm not sure how to implement this. I tried with the following, sending HTTPHEADER, but it's still sending the cached version :/

function sendPhoto($bot_id,$chat_id,$caption,$disable_notification,$photo_url)
{
    $ch = curl_init('https://api.telegram.org/bot'.$bot_id.'/sendPhoto');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $param = array(
        'chat_id' => $chat_id,
        'caption' => $caption,
        'parse_mode' => 'html',
        'disable_notification' => $disable_notification,
        'photo' => $photo_url
    );

    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));

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

    return $result;
}

Can someone help me please ? :)

1

1 Answers

0
votes

As you are sending the file/image by its url, telegram would use its cache and will not fetch the image from that particular given url again (same behaviour may happen when you use your browser to see that image or any resource in internet).

If you want to force telegram to not use the cache, you should change the url by giving some query parameters. In that case, the url would be different than your previous url and telegram will fetch the image again. For example use:

$param = array(
  //...
 'photo' => $photo_url . '?timestamp=' . time()
);