You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
InputFile class have javadoc described "Input file used to upload a file to Telegram server and use it afterwards".
But how i can get file_id for uploaded file and use it afterwards for send user?
The text was updated successfully, but these errors were encountered:
If you're using the bot to upload (literally send) Document (general file, as opposed to photos, voice messages and audio files), you will receive the Message object that holding the mentioned Document object after successful execution. You can get the file_id, Identifier for this file, which can be used to download or reuse the file from that object.
// bot tokenfinalStringBOT_TOKEN = "123456xxxxxy";
// assign the clientTelegramClienttelegramClient = newOkHttpTelegramClient(BOT_TOKEN);
// target chat id that file should be sent (String/Long)finalStringCHAT_ID = "123456xxxxx";
// java.io.File (solid file) or String (URL to the target file) or String (file_id of the target file - your question)finaljava.io.FileFILE = newFile("location");
// final String FILE = "https://example.com/targetFile";SendDocumentdoc = SendDocument.builder()
.chatId(CHAT_ID)
.document(newInputFile(FILE))
.build();
// other doc settingsMessagemessage = null;
try {
message = telegramClient.execute(doc);
} catch (TelegramApiExceptione) {
// handle the exception
}
if (message != null) {
StringfileId = message.getDocument().getFileId();
// other operations
}
Or, you can send your target file to the bot and get the update using the consume(Update update) method by invoking String fileId = update.getMessage().getDocument().getFileId();.
Now you have the fileId. Use it in the SendDocument builder as .document(new InputFile(fileId)) to send it. 👍 See also InputFile.
Maybe this is out of the question, but you can use bots like Telegram Bot Raw to get the Message object details (in JSON format) without configuring your own bot.
InputFile class have javadoc described "Input file used to upload a file to Telegram server and use it afterwards".
But how i can get file_id for uploaded file and use it afterwards for send user?
The text was updated successfully, but these errors were encountered: