I’m using this library: https://github.com/rubenlagus
I want to send multiple images in one message. How can I do it? I know about SendMediaGroup, but seems like I don’t understand how it works.
For example, I’ve URL of the image, and it works with single SendPhoto method, but I can’t configure it with MediaGroup. It requires List of InputMedia
.
public void handlePhoto(Update update) {
String image1 = "https://lh3.googleusercontent.com/af9mFH4XinZ7f6dx-Ygm9molYPAcMHhhZyQ0udDBd9S9-44v_VBdeA0rjSlQyJRpQg=w1920-h937-rw";
String image2 = "https://lh3.googleusercontent.com/mo0CZaV_aGflOPB8Tzo697l1WoZuoYUN9TiPMWq0zE29v_I99n1Qg185MfHrU-53nxAG=w1920-h937-rw";
String image3 = "https://lh3.googleusercontent.com/FEiHmVyoT1MU3rbAxSkE_aNDuXBuo3YHQOnqfMAfehS-d4k6CvxuyxpX6KKSbJp3Xv28=w1920-h937-rw";
List<InputMedia> media = new ArrayList<>();
InputMedia photo1 = new InputMediaPhoto();
photo1.setMedia(image1);
InputMedia photo2 = new InputMediaPhoto();
photo2.setMedia(image2);
InputMedia photo3 = new InputMediaPhoto();
photo3.setMedia(image3);
media.add(photo1);
media.add(photo2);
media.add(photo3);
SendMediaGroup mediaGroup = new SendMediaGroup();
mediaGroup.setChatId(update.getMessage().getChatId());
mediaGroup.setMedia(media);
try {
execute(mediaGroup);
}
catch (TelegramApiException e) {
e.printStackTrace();
}
}
I’m getting this error:
org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException: Error sending media group: [400] Bad Request: wrong type of the web page content
wrong type of the web page content
means that Telegram (or this API) can’t handle .webp images. Any tricks?
2
Answers
Telegram API supports .webp format. Maybe you violated one of these rules:
`The photo must be at most 10 MB in size. The photo’s width and height must not exceed 10000 in total. Width and height ratio must be at most 20.’
I’m using such dependencies:
SendMediaGroup can only send 2-10 items. So we need to process this case. I’m using this code:
If only 1 photo, we will send it with SendPhoto:
If we have 2-10 photos, send them with SendMediaGroup. In code below we are loading files from our server.