Home > Back-end >  Java Telegram Bot: how to send photos having their file_id?
Java Telegram Bot: how to send photos having their file_id?

Time:01-07

A few years ago I created a bot with telegrambots version 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.

I've just found out how to update the version of telegrambots, but now I've another problem.

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).

It looks like that method doesn't accept String parameter anymore since telegrambots version 5.0.0.

Infact it worked until telegrambots version 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. Each of these photos has its file_id saved in a field of a MySql database.

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.

Now it looks like setPhoto(String) doesn't work anymore, so how can I solve this problem? I still need to use all the photo we saved in those years. How can i convert these file_id into InputFile argument?

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).

I've no idea how to convert String (fileID from database) to InputFile.

Thanks you very much.

CodePudding user response:

The documentation is not really documenting anything, but it looks like the FileInput constructor can take String called attach(ement).

  • Related