0

Bad Request: wrong file_id or the file is temporarily unavailable

Sometimes when I request a file url from Telegram with the getFile method with a telegram bot api, I get this error that I did not find any explanation for it. If you have information, please benefit me. Thanks

smorz
  • 85
  • 6

2 Answers2

0

This is the result of contacting t.me/BotSupport:

I've asked our team to check, they confirmed there is no exact issues with the bot, when getting an error like that, the way to go is to retry after a moment, it should be transient and goes away on it's own.

Of course, this is while we were sure that the bot sent a file_id that belongs to itself. (and not a file_id of another bot)

smorz
  • 85
  • 6
0

You can download voice file in Java as:

 @Override
    public void onUpdateReceived(Update update) {
        var msg = update.getMessage();
        var voice = msg.getVoice();
        String fieldId = voice.getFileId();
        
        // Create a GetFile request with the provided file ID
        GetFile getFile = new GetFile();
        getFile.setFileId(fileId);

        // Execute the GetFile request
        File file = execute(getFile);

        // Get the file URL returned by the Telegram API
        String fileURL = file.getFileUrl(BOT_ID);

        //Downloading file from URL
        Files.copy(
                    new URL(fileURL).openStream(),
                    Paths.get("voice.oga"));
    ...
Viktor Sirotin
  • 169
  • 1
  • 8