Skip to content
Advertisement

Telegram sendPhoto method don’t refresh

I’m using a simple bot code which takes an Image from a php page created using:

header("Content-type: image/png");

and

imagepng();

Here is the bot code:

if ($text == "/photo") {
  $reply_markup = [
    "inline_keyboard" => [
      [
        [
          "text" => "Url",
          "url" => "https://google.com",
        ],
      ],
    ],
  ];
  sendPhoto($chat_id, "https://url.com/image.php?x=".urlencode($string), "Text", "HTML", false, $message_id, $reply_markup);
}



function sendPhoto($chat_id, $photo, $caption, $parse_mode = "default", $disable_notification = "default", $reply_to_message_id, $reply_markup) {

  global $config;

  if ($parse_mode == "default") $parse_mode = $config['parse_mode'];
  if ($disable_notification === "default") $disable_notification = $config['disable_notification'];

  $args = [
    "chat_id" => $chat_id,
    "photo" => $photo,
    "caption" => $caption,
    "parse_mode" => $parse_mode,
    "disable_notification" => $disable_notification,
  ];

  if (isset($reply_to_message_id)) $args["reply_to_message_id"] = $reply_to_message_id;
  if (isset($reply_markup)) $args["reply_markup"] = $reply_markup;

  return json_decode(http_request("sendPhoto", $args), true);
}

The code works fine and it sends the image correctly. But if I use the same url twice, it sends me the older version sent before.

For example i request ?x=photo and it prints photo.png correctly, after a while i request again photo(now the php page gives me another image) but bot sends me the older photo. It seems like it’s cached on Telegram

Advertisement

Answer

Telegram might be caching it because it is receiving the same filename twice, Instead of sending the photo with the original name, you could generate a random filename so telegram doesn’t cache it.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement