简体   繁体   English

Java Telegram Bot:如何发送具有 file_id 的照片?

[英]Java Telegram Bot: how to send photos having their file_id?

A few years ago I created a bot with telegrambots version 3.6.1.几年前,我用telegrambots 3.6.1 版创建了一个机器人。 Unfortunately there was a problem: every time that a user with user_ID>2147483647 joined the group, the bot crashed, as described here .不幸的是,出现了一个问题:每次 user_ID>2147483647 的用户加入群组时,机器人都会崩溃,如此所述。

I've just found out how to update the version of telegrambots , but now I've another problem.我刚刚发现如何更新telegrambots的版本,但现在我遇到了另一个问题。

I need to use the setPhoto(String file_id) method as described here in Telegram ot JAVA API page (Pass a file_id as String to send a photo that exists on the Telegram servers).我需要使用 Telegram ot JAVA API 页面中描述setPhoto(String file_id) 方法(将 file_id 作为字符串传递以发送存在于 Telegram 服务器上的照片)。

It looks like that method doesn't accept String parameter anymore since telegrambots version 5.0.0 .telegrambots版本5.0.0以来,该方法似乎不再接受 String 参数。

Infact it worked until telegrambots version 4.9.2 .事实上,它在telegrambots版本4.9.2之前一直有效。

So my bot pins a message in the group with a list of many places, each one can have up till 2 photos.所以我的机器人在群里发了一条消息,里面有很多地方的列表,每个地方最多可以有 2 张照片。 Each of these photos has its file_id saved in a field of a MySql database.这些照片中的每一张都有其 file_id 保存在 MySql 数据库的一个字段中。

So basically when we use the command to see a pic associated to a place, my code uses setPhoto(file_id) getting the file_id string from the database.所以基本上当我们使用命令查看与某个地方相关联的图片时,我的代码使用 setPhoto(file_id) 从数据库中获取 file_id 字符串。

Now it looks like setPhoto(String) doesn't work anymore, so how can I solve this problem?现在看起来 setPhoto(String) 不再起作用了,那么我该如何解决这个问题呢? I still need to use all the photo we saved in those years.我仍然需要使用那些年我们保存的所有照片。 How can i convert these file_id into InputFile argument?如何将这些 file_id 转换为 InputFile 参数?

I've tried to use version 4.9.2 of telegrambots and setPhoto(String) works, but I don't know if in that version, my original problem (numeric value out of range) was already solved and anyway I would like to use the latest version (6.4.0).我试过使用 4.9.2 版本的电报机器人并且 setPhoto(String) 有效,但我不知道在那个版本中,我原来的问题(数值超出范围)是否已经解决,无论如何我想使用最新版本 (6.4.0)。

I've no idea how to convert String (fileID from database) to InputFile.我不知道如何将字符串(来自数据库的文件 ID)转换为 InputFile。

Thanks you very much.非常感谢你。

The documentation is not really documenting anything, but it looks like the FileInput constructor can take String called attach(ement).该文档并没有真正记录任何内容,但看起来FileInput构造函数可以采用名为 attach(ement) 的String

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM