com.pengrad.telegrambot.request.SendPhoto Java Examples

The following examples show how to use com.pengrad.telegrambot.request.SendPhoto. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TelegramBotTest.java    From java-telegram-bot-api with Apache License 2.0 6 votes vote down vote up
@Test
public void sendPhoto() {
    Message message = bot.execute(new SendPhoto(chatId, photoFileId)).message();
    MessageTest.checkMessage(message);
    PhotoSizeTest.checkPhotos(false, message.photo());

    message = bot.execute(new SendPhoto(chatId, imageFile)).message();
    MessageTest.checkMessage(message);
    PhotoSizeTest.checkPhotos(message.photo());

    String caption = "caption <b>bold</b>";
    message = bot.execute(new SendPhoto(channelName, imageBytes).caption(caption).parseMode(ParseMode.HTML)).message();
    MessageTest.checkMessage(message);
    assertEquals(caption.replace("<b>", "").replace("</b>", ""), message.caption());
    PhotoSizeTest.checkPhotos(message.photo());

    MessageEntity captionEntity = message.captionEntities()[0];
    assertEquals(MessageEntity.Type.bold, captionEntity.type());
    assertEquals((Integer) 8, captionEntity.offset());
    assertEquals((Integer) 4, captionEntity.length());
}
 
Example #2
Source File: UpdateHandlerImpl.java    From telegram-bot with Eclipse Public License 1.0 5 votes vote down vote up
private void sendDmiPhoto(Long chatId, Single<List<DmiCity>> dmiCities, String mode) {
	dmiCities.subscribe(cities -> cities.stream().findFirst().ifPresent(dmiCity -> {
		Single<ResponseBody> weatherImage = dmiApi.getWeatherImage(String.valueOf(dmiCity.getId()), mode);
		weatherImage.subscribe(rb -> {
			SendPhoto sendPhoto = new SendPhoto(chatId, rb.bytes());
			telegramBot.execute(sendPhoto);
		});
	}));
}
 
Example #3
Source File: TelegramService.java    From Telephoto with Apache License 2.0 5 votes vote down vote up
private void sendOnePhoto(Long id, byte[] photo, String caption) {
    SendPhoto request = new SendPhoto(id, photo);
    if (caption != null) {
        request.caption(caption);
    }
    bot.execute(request);
    L.i("Sent photo successful to " + id);
}
 
Example #4
Source File: TelegramBotTest.java    From java-telegram-bot-api with Apache License 2.0 5 votes vote down vote up
@Test
public void multipartNonAscii() {
    String caption = "хорошо";
    Message message = bot.execute(
            new SendPhoto(chatId, imageFile).fileName("файл.txt").caption(caption)
    ).message();
    assertEquals(caption, message.caption());
    MessageTest.checkMessage(message);
    PhotoSizeTest.checkPhotos(message.photo());
}