Telegram bot - 接收照片 URL [英] Telegram bot - receive photo URL
问题描述
当用户通过 Telegram bot 发送图像时,有什么方法可以获取图像 URL?或者我只需要将图像保存在某处?
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?
推荐答案
在您收到的消息数组中,您可以找到键 photo
.在那里你会发现多个具有以下格式的数组
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
您需要从其中一个数组中获取 file_id
.然后,您可以通过 url https://api.telegram.org/bot<token>/getFile?file_id=<file_id>
file_path>
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"
}
从结果中你需要file_path
,然后你得到图像位置https://api.telegram.org/file/bot
From the result you need the file_path
and you then got the image location https://api.telegram.org/file/bot<token>/<file_path>
这篇关于Telegram bot - 接收照片 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!