1

I'm building a Java telegram bot, and one of the features is to send a group of photos from local.

However, when executing the bot, it fails to upload the photos with error message:

org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException: 
Error sending media group: [400] Bad Request: wrong remote file identifier specified: Wrong string length 
at org.telegram.telegrambots.meta.api.methods.send.SendMediaGroup.deserializeResponse(SendMediaGroup.java:86)

I'm using 'org.telegram:telegrambots:5.7.1' by the way: https://github.com/rubenlagus/TelegramBots

My code


@Slf4j
@AllArgsConstructor
public class GetPhotosCommand implements BotCommand {

    private Bot bot;

    @Override
    public void execute(Update update) {
        final String chatId = String.valueOf(update.getMessage().getChatId());
        List<InputMedia> inputMediaList = new ArrayList<>();

        InputMediaPhoto inputMediaPhoto1 = InputMediaPhoto.builder()
                .caption("cat photos")
                .media("1")
                .mediaName("001")
                .isNewMedia(true)
                .newMediaFile(new File("~/Desktop/001.png"))
                .build();
        InputMediaPhoto inputMediaPhoto2 = InputMediaPhoto.builder()
                .media("2")
                .mediaName("002")
                .isNewMedia(true)
                .newMediaFile(new File("~/Desktop/002.png"))
                .build();

        inputMediaList.add(inputMediaPhoto1);
        inputMediaList.add(inputMediaPhoto2);
        SendMediaGroup sendMediaGroup = SendMediaGroup.builder()
                .chatId(chatId)
                .medias(inputMediaList)
                .protectContent(true)
                .build();
        SendMessage sendMessage = SendMessage.builder()
                .chatId(chatId)
                .text("Hello, here are my cats.")
                .build();
        try {
            bot.execute(sendMediaGroup);
            bot.execute(sendMessage);
        } catch (TelegramApiException e) {
            log.error("Exception is thrown: {}", e);
        }
    }
}
Yang Liu
  • 541
  • 9
  • 26

0 Answers0