telegram bot image from url - undesired cache

python telegram bot send message
python-telegram-bot examples
python-telegram-bot messagehandler
telegram bot api
telegram bot reply to message
python-telegram bot documentation
telegram bot send file
telegram bot send photo

I am working on a telegram bot that displays images from several webcams upon request. I fetch the images from urls and then send to the user (using bot.sendPhoto() ) My problem is that for any given webcam the filename does not change and it seems that the photo is sent from telegram's cache. So it will display the image from the first time that image was requested.

I have thought about downloading the image from the url, saving with a variable name (like a name with a timestamp in it) then sending it to the chat, this seems like an inelegant solution and was hoping for something better. Like forcing the image not to be cached on the telegram server.

I am using the python-telegram-bot wrapper, but I am not sure that it's specific to that.

Any ideas? I have tried searching but so far am turning up little. Thanks in advance.

I had the same problem. I wanted to create a bot which sends an image taken by a webcam of a ski slope (webcam.example.com/image.jpg). Unfortunately, the filename and so the url never updates and telegram always sends the cached image. So I decided to alter the url passed to the api. In order to achieve this, I wrote a simple php site (example.com/photo.php) which redirects to the original url of the photo. After that, I created a folder (example.com/getphoto/) on my webspace with a .htaccess file inside. The .htaccess redirects all request in this folder to the photo.php site which redirects to the image (webcam.example.com/image.jpg). So you could add everything to the url of the folder and still get the picture (e. g. example.com/getphoto/42 or example.com/getphoto/hrte8437g). The telegram api seems to cache photos by url, so if you add always another ending to the url passed to the api, telegram doesnt use the cached version and sends the current image instead. The easiest way to always change the url is by adding the current date to it.

example.com/photo.php

<?php
header("Location: http://webcam.example.com/image.jpg");
die();
?>

example.com/getphoto/.htaccess

RewriteEngine on
RewriteRule ^(.*)$ http://example.com/photo.php

in python:

bot.sendPhoto(chat_id, 'example.com/getphoto/' + strftime("%Y-%m-%d_%H-%M-%S", gmtime()))

This workaround should also work in other languages like java or php. You just need to change the way to get the current date.

python - telegram bot image from url - undesired cache, I had the same problem. I wanted to create a bot which sends an image taken by a webcam of a ski slope (webcam.example.com/image.jpg). I want to send some photos with telegram bot with using below code.E.g.i want to send 5 image with different URL and i write below code 5 times with different URL.my problem is that when one of the URLs is wrong or not respond my code stop their for example if first URL has problem the other 4 sendPhoto doesn't run and i want my code continue

I had the same problem too, but i've found the simplest solution.

When you call the image, you have to add a parameter with timestamp to the image link. Example:

http://www.example.com/img/img.jpg?a=TIMESTAMP

Where TIMESTAMP is the timestamp function based on the language you are using.

Simple but tricky ;)

GitHub API images not getting updated · Issue #7 · aashutoshrathi , telegram bot image from url - undesired cache. I am working on a telegram bot that displays images from several webcams upon request. Stack Overflow Public questions and Sending photo from URL with Telegram Bot - php. The only way to upload photo to bot API is to send there image's content

I think the best way is to do the same as we do in React where also, same URL calls are first checked in the cache.

If you are using Python the best way is:

timestamp = datetime.datetime.now().isoformat()
# Above statement returns like: '2013-11-18T08:18:31.809000'
pic_url = '{0}?a={1}'.format(img_url, timestamp)

Hope that helps!

Code snippets · python-telegram-bot/python-telegram-bot , Cached Telegram group administrator check; Simple way of restarting the bot; Store in BBCode. urled parameter determines if URLs in text are to be processed as links or left as text. Get image with dimensions closest to a desired size. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, TRUE is returned. Usage answerCallbackQuery(callback_query_id, text = NULL, show_alert = FALSE, url = NULL, cache_time = NULL) Arguments callback_query_id Unique identifier for the query to be answered.

Uploading and Downloading Files, If the bot is using getUpdates, will return an object with the url field empty. total_count, Integer, Total number of profile pictures the target user has Telegram apps will support caching starting in version 3.14. Defaults why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram bot constructor from command-line. Contribute to msoap/shell2telegram development by creating an account on GitHub.

Telegram Bot API, This object represents a Telegram Bot. The png_sticker and tgs_sticker argument can be either a file_id, an URL or a file from disk open(filename, 'rb') optional) – Png image with the sticker, must be up to 512 kilobytes in size, dimensions must InlineQueryResult ) – A list of results for the inline query. cache_time ( int  telegram_bot This is a personalized telegram bot with the following commands available to users: /scan: Performs a port scan on the specified address passed as a parameter For example: /scan <target ip address> /arp: Performs a network scan for all the devices connected to the script hosts network /prev: Calls the previously received command

telegram.Bot, Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get  Develop a Telegram Bot with R. Contribute to ebeneditos/telegram.bot development by creating an account on GitHub.

Comments
  • Seems that you have no choice but to use that inelegant way. But I'm afraid Telegram bots were not designed for such tasks :) If I were you I would make a web server with a page with a regularly refreshing image from the webcam.
  • it works, but do not add it to thumbnail when using inline query, leave thumbnail unchanged