When a user send an image via Telegram bot it there any way to get the image URL? or I just need to save the image somewhere?
From telegram's docs: On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot/, where is taken from the response. It is guaranteed that the link will be valid for at least 1 hour.
Introduction to the Telegram Bot API The first part of the URL indicates that you want to communicate with the Telegram API ( api.telegram.org ).
In the message array you receive you can find the key photo
.
There you will find multiple arrays with the following format
"file_id" : "XXXX",
"file_size" : 1107,
"width" : 90,
"height" : 51
From one of those array you need to take the file_id
. You can then request the file_path
with a simple get get on the url https://api.telegram.org/bot<token>/getFile?file_id=<file_id>
You will receive an array that looks as following
"ok" : true,
"result" : {
"file_id" : "XXXX",
"file_size" : 27935,
"file_path" : "photo\/file_1.jpg"
}
From the result you need the file_path
and you then got the image location https://api.telegram.org/file/bot<token>/<file_path>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With