private void addInputFile(MultipartEntityBuilder builder, InputFile file, String fileField, boolean addField) { if (file.isNew()) { if (file.getNewMediaFile() != null) { builder.addBinaryBody(file.getMediaName(), file.getNewMediaFile(), ContentType.APPLICATION_OCTET_STREAM, file.getMediaName()); } else if (file.getNewMediaStream() != null) { builder.addBinaryBody(file.getMediaName(), file.getNewMediaStream(), ContentType.APPLICATION_OCTET_STREAM, file.getMediaName()); } } if (addField) { builder.addTextBody(fileField, file.getAttachName(), TEXT_PLAIN_CONTENT_TYPE); } }
/** * Use this method to set the audio to an audio existing in Telegram system * * @param audio File_id of the audio to send * @note The file_id must have already been received or sent by your bot */ public SendAudio setAudio(String audio) { this.audio = new InputFile(audio); return this; }
/** * Constructor to set a new file * * @param mediaFile File to send * @param fileName Name of the file */ public InputFile(File mediaFile, String fileName) { this(); setMedia(mediaFile, fileName); }
@Override public void serialize(InputFile value, JsonGenerator gen, SerializerProvider serializers) throws IOException { gen.writeObject(value.getAttachName()); } }
@Override public void validate() throws TelegramApiValidationException { if (chatId == null) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (document == null) { throw new TelegramApiValidationException("Document parameter can't be empty", this); } document.validate(); if (thumb != null) { thumb.validate(); } if (replyMarkup != null) { replyMarkup.validate(); } }
InputMediaAudio audio = (InputMediaAudio) value; if (audio.getThumb() != null) { gen.writeStringField(InputMediaAudio.THUMB_FIELD, audio.getThumb().getAttachName()); InputMediaAnimation animation = (InputMediaAnimation) value; if (animation.getThumb() != null) { gen.writeStringField(InputMediaAnimation.THUMB_FIELD, animation.getThumb().getAttachName()); InputMediaDocument document = (InputMediaDocument) value; if (document.getThumb() != null) { gen.writeStringField(InputMediaDocument.THUMB_FIELD, document.getThumb().getAttachName()); gen.writeStringField(InputMediaVideo.THUMB_FIELD, video.getThumb().getAttachName());
@Override public void validate() throws TelegramApiValidationException { if (chatId == null) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (animation == null) { throw new TelegramApiValidationException("Animation parameter can't be empty", this); } animation.validate(); if (replyMarkup != null) { replyMarkup.validate(); } if (thumb != null) { thumb.validate(); } }
private void addInputFile(MultipartEntityBuilder builder, InputFile file, String fileField, boolean addField) { if (file.isNew()) { if (file.getNewMediaFile() != null) { builder.addBinaryBody(file.getMediaName(), file.getNewMediaFile(), ContentType.APPLICATION_OCTET_STREAM, file.getMediaName()); } else if (file.getNewMediaStream() != null) { builder.addBinaryBody(file.getMediaName(), file.getNewMediaStream(), ContentType.APPLICATION_OCTET_STREAM, file.getMediaName()); } } if (addField) { builder.addTextBody(fileField, file.getAttachName(), TEXT_PLAIN_CONTENT_TYPE); } }
public SendSticker setSticker(String sticker) { this.sticker = new InputFile(sticker); return this; }
builder.addTextBody(SendVideoNote.THUMB_FIELD, sendVideoNote.getThumb().getAttachName(), TEXT_PLAIN_CONTENT_TYPE);
@Override public void validate() throws TelegramApiValidationException { if (chatId == null) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (video == null) { throw new TelegramApiValidationException("Video parameter can't be empty", this); } video.validate(); if (thumb != null) { thumb.validate(); } if (replyMarkup != null) { replyMarkup.validate(); } }
/** * Constructor to set a new file as stream * * @param mediaStream File to send * @param fileName Name of the file */ public InputFile(InputStream mediaStream, String fileName) { this(); setMedia(mediaStream, fileName); }
public AddStickerToSet setPngSticker(String pngSticker) { this.pngSticker = new InputFile(pngSticker); return this; }
builder.addTextBody(SendVideo.THUMB_FIELD, sendVideo.getThumb().getAttachName(), TEXT_PLAIN_CONTENT_TYPE);
@Override public void validate() throws TelegramApiValidationException { if (chatId == null) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (audio == null) { throw new TelegramApiValidationException("Audio parameter can't be empty", this); } audio.validate(); if (thumb != null) { thumb.validate(); } if (replyMarkup != null) { replyMarkup.validate(); } }
public InputFile(String attachName) { this(); setMedia(attachName); }
/** * Use this method to set the document to an document existing in Telegram system * * @param document File_id of the document to send * @note The file_id must have already been received or sent by your bot */ public SendDocument setDocument(String document) { this.document = new InputFile(document); return this; }
builder.addTextBody(SendDocument.THUMB_FIELD, sendDocument.getThumb().getAttachName(), TEXT_PLAIN_CONTENT_TYPE);
@Override public void validate() throws TelegramApiValidationException { if (chatId == null) { throw new TelegramApiValidationException("ChatId parameter can't be empty", this); } if (videoNote == null) { throw new TelegramApiValidationException("VideoNote parameter can't be empty", this); } videoNote.validate(); if (thumb != null) { thumb.validate(); } if (replyMarkup != null) { replyMarkup.validate(); } }
/** * Constructor to set a new file * * @param mediaFile File to send * @param fileName Name of the file */ public InputFile(File mediaFile, String fileName) { this(); setMedia(mediaFile, fileName); }