Merge branch 'antonu17-feature/improve_send_newfile' into dev
This commit is contained in:
commit
d8c2a1a22a
@ -2,6 +2,9 @@ package org.telegram.telegrambots.api.methods.send;
|
||||
|
||||
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -36,8 +39,11 @@ public class SendAudio {
|
||||
private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
|
||||
private String performer; ///< Optional. Performer of sent audio
|
||||
private String title; ///< Optional. Title of sent audio
|
||||
private boolean isNewAudio;
|
||||
|
||||
private boolean isNewAudio; ///< True to upload a new audio, false to use a fileId
|
||||
private String audioName;
|
||||
private File newAudioFile; ///< New audio file
|
||||
private InputStream newAudioStream; ///< New audio stream
|
||||
|
||||
public SendAudio() {
|
||||
super();
|
||||
@ -83,6 +89,7 @@ public class SendAudio {
|
||||
* @param audio Path to the new file in your server
|
||||
* @param audioName Name of the file itself
|
||||
*/
|
||||
@Deprecated
|
||||
public SendAudio setNewAudio(String audio, String audioName) {
|
||||
this.audio = audio;
|
||||
this.isNewAudio = true;
|
||||
@ -90,6 +97,24 @@ public class SendAudio {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to set the audio to a new file
|
||||
*
|
||||
* @param file New audio file
|
||||
*/
|
||||
public SendAudio setNewAudio(File file) {
|
||||
this.audio = file.getName();
|
||||
this.isNewAudio = true;
|
||||
this.newAudioFile = file;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendAudio setNewAudio(InputStream inputStream) {
|
||||
this.isNewAudio = true;
|
||||
this.newAudioStream = inputStream;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getReplayToMessageId() {
|
||||
return replayToMessageId;
|
||||
}
|
||||
@ -148,6 +173,14 @@ public class SendAudio {
|
||||
return audioName;
|
||||
}
|
||||
|
||||
public File getNewAudioFile() {
|
||||
return newAudioFile;
|
||||
}
|
||||
|
||||
public InputStream getNewAudioStream() {
|
||||
return newAudioStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SendAudio{" +
|
||||
@ -158,7 +191,6 @@ public class SendAudio {
|
||||
", performer='" + performer + '\'' +
|
||||
", title='" + title + '\'' +
|
||||
", isNewAudio=" + isNewAudio +
|
||||
", audioName='" + audioName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package org.telegram.telegrambots.api.methods.send;
|
||||
|
||||
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -28,8 +31,10 @@ public class SendDocument {
|
||||
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
|
||||
private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
|
||||
|
||||
private boolean isNewDocument;
|
||||
private boolean isNewDocument; ///< True to upload a new document, false to use a fileId
|
||||
private String documentName;
|
||||
private File newDocumentFile; ///< New document file
|
||||
private InputStream newDocumentStream; ///< New document stream
|
||||
|
||||
public SendDocument() {
|
||||
super();
|
||||
@ -54,6 +59,7 @@ public class SendDocument {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SendDocument setNewDocument(String document, String documentName) {
|
||||
this.document = document;
|
||||
this.isNewDocument = true;
|
||||
@ -61,6 +67,19 @@ public class SendDocument {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendDocument setNewDocument(File file) {
|
||||
this.document = file.getName();
|
||||
this.isNewDocument = true;
|
||||
this.newDocumentFile = file;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendDocument setNewDocument(InputStream inputStream) {
|
||||
this.isNewDocument = true;
|
||||
this.newDocumentStream = inputStream;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isNewDocument() {
|
||||
return isNewDocument;
|
||||
}
|
||||
@ -69,6 +88,14 @@ public class SendDocument {
|
||||
return documentName;
|
||||
}
|
||||
|
||||
public File getNewDocumentFile() {
|
||||
return newDocumentFile;
|
||||
}
|
||||
|
||||
public InputStream getNewDocumentStream() {
|
||||
return newDocumentStream;
|
||||
}
|
||||
|
||||
public Integer getReplayToMessageId() {
|
||||
return replayToMessageId;
|
||||
}
|
||||
@ -118,7 +145,6 @@ public class SendDocument {
|
||||
", replayToMessageId=" + replayToMessageId +
|
||||
", replayMarkup=" + replayMarkup +
|
||||
", isNewDocument=" + isNewDocument +
|
||||
", documentName='" + documentName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package org.telegram.telegrambots.api.methods.send;
|
||||
|
||||
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -30,7 +33,8 @@ public class SendPhoto {
|
||||
|
||||
private boolean isNewPhoto; ///< True if the photo must be uploaded from a file, file if it is a fileId
|
||||
private String photoName; ///< Name of the photo
|
||||
|
||||
private File newPhotoFile; // New photo file
|
||||
private InputStream newPhotoStream; // New photo stream
|
||||
|
||||
public SendPhoto() {
|
||||
super();
|
||||
@ -90,6 +94,14 @@ public class SendPhoto {
|
||||
return photoName;
|
||||
}
|
||||
|
||||
public File getNewPhotoFile() {
|
||||
return newPhotoFile;
|
||||
}
|
||||
|
||||
public InputStream getNewPhotoStream() {
|
||||
return newPhotoStream;
|
||||
}
|
||||
|
||||
public Boolean getDisableNotification() {
|
||||
return disableNotification;
|
||||
}
|
||||
@ -104,6 +116,7 @@ public class SendPhoto {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SendPhoto setNewPhoto(String photo, String photoName) {
|
||||
this.photo = photo;
|
||||
this.isNewPhoto = true;
|
||||
@ -111,6 +124,19 @@ public class SendPhoto {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendPhoto setNewPhoto(File file) {
|
||||
this.photo = file.getName();
|
||||
this.newPhotoFile = file;
|
||||
this.isNewPhoto = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendPhoto setNewPhoto(InputStream inputStream) {
|
||||
this.newPhotoStream = inputStream;
|
||||
this.isNewPhoto = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SendPhoto{" +
|
||||
@ -120,7 +146,6 @@ public class SendPhoto {
|
||||
", replayToMessageId=" + replayToMessageId +
|
||||
", replayMarkup=" + replayMarkup +
|
||||
", isNewPhoto=" + isNewPhoto +
|
||||
", photoName='" + photoName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package org.telegram.telegrambots.api.methods.send;
|
||||
|
||||
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -26,8 +29,10 @@ public class SendSticker {
|
||||
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
|
||||
private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
|
||||
|
||||
private boolean isNewSticker;
|
||||
private boolean isNewSticker; ///< True to upload a new sticker, false to use a fileId
|
||||
private String stickerName;
|
||||
private File newStickerFile; ///< New sticker file
|
||||
private InputStream newStickerStream; ///< New sticker stream
|
||||
|
||||
public SendSticker() {
|
||||
super();
|
||||
@ -70,6 +75,7 @@ public class SendSticker {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SendSticker setSticker(String sticker, String stickerName) {
|
||||
this.sticker = sticker;
|
||||
this.isNewSticker = true;
|
||||
@ -77,6 +83,19 @@ public class SendSticker {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendSticker setNewSticker(File file) {
|
||||
this.sticker = file.getName();
|
||||
this.isNewSticker = true;
|
||||
this.newStickerFile = file;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendSticker setNewSticker(InputStream inputStream) {
|
||||
this.isNewSticker = true;
|
||||
this.newStickerStream = inputStream;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getDisableNotification() {
|
||||
return disableNotification;
|
||||
}
|
||||
@ -99,6 +118,14 @@ public class SendSticker {
|
||||
return stickerName;
|
||||
}
|
||||
|
||||
public File getNewStickerFile() {
|
||||
return newStickerFile;
|
||||
}
|
||||
|
||||
public InputStream getNewStickerStream() {
|
||||
return newStickerStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SendSticker{" +
|
||||
@ -107,7 +134,6 @@ public class SendSticker {
|
||||
", replayToMessageId=" + replayToMessageId +
|
||||
", replayMarkup=" + replayMarkup +
|
||||
", isNewSticker=" + isNewSticker +
|
||||
", stickerName='" + stickerName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package org.telegram.telegrambots.api.methods.send;
|
||||
|
||||
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -37,6 +40,8 @@ public class SendVideo {
|
||||
|
||||
private boolean isNewVideo; ///< True to upload a new video, false to use a fileId
|
||||
private String videoName; ///< Name of the video
|
||||
private File newVideoFile; ///< New video file
|
||||
private InputStream newVideoStream; ///< New video stream
|
||||
|
||||
public SendVideo() {
|
||||
super();
|
||||
@ -105,6 +110,14 @@ public class SendVideo {
|
||||
return videoName;
|
||||
}
|
||||
|
||||
public File getNewVideoFile() {
|
||||
return newVideoFile;
|
||||
}
|
||||
|
||||
public InputStream getNewVideoStream() {
|
||||
return newVideoStream;
|
||||
}
|
||||
|
||||
public Boolean getDisableNotification() {
|
||||
return disableNotification;
|
||||
}
|
||||
@ -137,6 +150,7 @@ public class SendVideo {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SendVideo setNewVideo(String video, String videoName) {
|
||||
this.video = video;
|
||||
this.isNewVideo = true;
|
||||
@ -144,6 +158,19 @@ public class SendVideo {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendVideo setNewVideo(File file) {
|
||||
this.video = file.getName();
|
||||
this.isNewVideo = true;
|
||||
this.newVideoFile = file;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendVideo setNewVideo(InputStream inputStream) {
|
||||
this.isNewVideo = true;
|
||||
this.newVideoStream = inputStream;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SendVideo{" +
|
||||
@ -154,7 +181,6 @@ public class SendVideo {
|
||||
", replayToMessageId=" + replayToMessageId +
|
||||
", replayMarkup=" + replayMarkup +
|
||||
", isNewVideo=" + isNewVideo +
|
||||
", videoName='" + videoName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package org.telegram.telegrambots.api.methods.send;
|
||||
|
||||
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Ruben Bermudez
|
||||
* @version 1.0
|
||||
@ -32,6 +35,8 @@ public class SendVoice {
|
||||
|
||||
private boolean isNewVoice; ///< True to upload a new voice note, false to use a fileId
|
||||
private String voiceName; ///< Name of the voice note
|
||||
private File newVoiceFile; ///< New voice note file
|
||||
private InputStream newVoiceStream; ///< New voice note stream
|
||||
|
||||
public SendVoice() {
|
||||
super();
|
||||
@ -81,6 +86,7 @@ public class SendVoice {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SendVoice setNewAudio(String audio, String audioName) {
|
||||
this.audio = audio;
|
||||
this.isNewVoice = false;
|
||||
@ -88,6 +94,19 @@ public class SendVoice {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendVoice setNewAudio(File file) {
|
||||
this.audio = file.getName();
|
||||
this.isNewVoice = true;
|
||||
this.newVoiceFile = file;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendVoice setNewAudio(InputStream inputStream) {
|
||||
this.isNewVoice = true;
|
||||
this.newVoiceStream = inputStream;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getReplayToMessageId() {
|
||||
return replayToMessageId;
|
||||
}
|
||||
@ -122,4 +141,12 @@ public class SendVoice {
|
||||
public String getVoiceName() {
|
||||
return voiceName;
|
||||
}
|
||||
|
||||
public File getNewVoiceFile() {
|
||||
return newVoiceFile;
|
||||
}
|
||||
|
||||
public InputStream getNewVoiceStream() {
|
||||
return newVoiceStream;
|
||||
}
|
||||
}
|
||||
|
@ -504,7 +504,13 @@ public abstract class AbsSender {
|
||||
if (sendDocument.isNewDocument()) {
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
builder.addTextBody(SendDocument.CHATID_FIELD, sendDocument.getChatId());
|
||||
if (sendDocument.getNewDocumentFile() != null) {
|
||||
builder.addBinaryBody(SendDocument.DOCUMENT_FIELD, sendDocument.getNewDocumentFile());
|
||||
} else if (sendDocument.getNewDocumentStream() != null) {
|
||||
builder.addBinaryBody(SendDocument.DOCUMENT_FIELD, sendDocument.getNewDocumentStream());
|
||||
} else {
|
||||
builder.addBinaryBody(SendDocument.DOCUMENT_FIELD, new java.io.File(sendDocument.getDocument()), ContentType.APPLICATION_OCTET_STREAM, sendDocument.getDocumentName());
|
||||
}
|
||||
if (sendDocument.getReplayMarkup() != null) {
|
||||
builder.addTextBody(SendDocument.REPLYMARKUP_FIELD, sendDocument.getReplayMarkup().toJson().toString(), TEXT_PLAIN_CONTENT_TYPE);
|
||||
}
|
||||
@ -564,7 +570,13 @@ public abstract class AbsSender {
|
||||
if (sendPhoto.isNewPhoto()) {
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
builder.addTextBody(SendPhoto.CHATID_FIELD, sendPhoto.getChatId());
|
||||
if (sendPhoto.getNewPhotoFile() != null) {
|
||||
builder.addBinaryBody(SendPhoto.PHOTO_FIELD, sendPhoto.getNewPhotoFile());
|
||||
} else if (sendPhoto.getNewPhotoStream() != null) {
|
||||
builder.addBinaryBody(SendPhoto.PHOTO_FIELD, sendPhoto.getNewPhotoStream());
|
||||
} else {
|
||||
builder.addBinaryBody(SendPhoto.PHOTO_FIELD, new java.io.File(sendPhoto.getPhoto()), ContentType.APPLICATION_OCTET_STREAM, sendPhoto.getPhotoName());
|
||||
}
|
||||
if (sendPhoto.getReplayMarkup() != null) {
|
||||
builder.addTextBody(SendPhoto.REPLYMARKUP_FIELD, sendPhoto.getReplayMarkup().toJson().toString(), TEXT_PLAIN_CONTENT_TYPE);
|
||||
}
|
||||
@ -624,7 +636,13 @@ public abstract class AbsSender {
|
||||
if (sendVideo.isNewVideo()) {
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
builder.addTextBody(SendVideo.CHATID_FIELD, sendVideo.getChatId());
|
||||
if (sendVideo.getNewVideoFile() != null) {
|
||||
builder.addBinaryBody(SendVideo.VIDEO_FIELD, sendVideo.getNewVideoFile());
|
||||
} else if (sendVideo.getNewVideoStream() != null) {
|
||||
builder.addBinaryBody(SendVideo.VIDEO_FIELD, sendVideo.getNewVideoStream());
|
||||
} else {
|
||||
builder.addBinaryBody(SendVideo.VIDEO_FIELD, new java.io.File(sendVideo.getVideo()), ContentType.APPLICATION_OCTET_STREAM, sendVideo.getVideoName());
|
||||
}
|
||||
if (sendVideo.getReplayMarkup() != null) {
|
||||
builder.addTextBody(SendVideo.REPLYMARKUP_FIELD, sendVideo.getReplayMarkup().toJson().toString(), TEXT_PLAIN_CONTENT_TYPE);
|
||||
}
|
||||
@ -703,7 +721,13 @@ public abstract class AbsSender {
|
||||
if (sendSticker.isNewSticker()) {
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
builder.addTextBody(SendSticker.CHATID_FIELD, sendSticker.getChatId());
|
||||
if (sendSticker.getNewStickerFile() != null) {
|
||||
builder.addBinaryBody(SendSticker.STICKER_FIELD, sendSticker.getNewStickerFile());
|
||||
} else if (sendSticker.getNewStickerStream() != null) {
|
||||
builder.addBinaryBody(SendSticker.STICKER_FIELD, sendSticker.getNewStickerStream());
|
||||
} else {
|
||||
builder.addBinaryBody(SendSticker.STICKER_FIELD, new java.io.File(sendSticker.getSticker()), ContentType.APPLICATION_OCTET_STREAM, sendSticker.getStickerName());
|
||||
}
|
||||
if (sendSticker.getReplayMarkup() != null) {
|
||||
builder.addTextBody(SendSticker.REPLYMARKUP_FIELD, sendSticker.getReplayMarkup().toJson().toString(), TEXT_PLAIN_CONTENT_TYPE);
|
||||
}
|
||||
@ -765,7 +789,13 @@ public abstract class AbsSender {
|
||||
if (sendAudio.isNewAudio()) {
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
builder.addTextBody(SendAudio.CHATID_FIELD, sendAudio.getChatId());
|
||||
if (sendAudio.getNewAudioFile() != null) {
|
||||
builder.addBinaryBody(SendAudio.AUDIO_FIELD, sendAudio.getNewAudioFile());
|
||||
} else if (sendAudio.getNewAudioStream() != null) {
|
||||
builder.addBinaryBody(SendAudio.AUDIO_FIELD, sendAudio.getNewAudioStream());
|
||||
} else {
|
||||
builder.addBinaryBody(SendAudio.AUDIO_FIELD, new java.io.File(sendAudio.getAudio()), ContentType.create("audio/mpeg"), sendAudio.getAudioName());
|
||||
}
|
||||
if (sendAudio.getReplayMarkup() != null) {
|
||||
builder.addTextBody(SendAudio.REPLYMARKUP_FIELD, sendAudio.getReplayMarkup().toJson().toString(), TEXT_PLAIN_CONTENT_TYPE);
|
||||
}
|
||||
@ -833,6 +863,7 @@ public abstract class AbsSender {
|
||||
|
||||
/**
|
||||
* Sends a voice note using Send Voice method (https://core.telegram.org/bots/api#sendvoice)
|
||||
* For this to work, your audio must be in an .ogg file encoded with OPUS
|
||||
* @param sendVoice Information to send
|
||||
* @return If success, the sent Message is returned
|
||||
* @throws TelegramApiException If there is any error sending the audio
|
||||
@ -847,7 +878,13 @@ public abstract class AbsSender {
|
||||
if (sendVoice.isNewVoice()) {
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||
builder.addTextBody(SendVoice.CHATID_FIELD, sendVoice.getChatId());
|
||||
if (sendVoice.getNewVoiceFile() != null) {
|
||||
builder.addBinaryBody(SendVoice.AUDIO_FIELD, sendVoice.getNewVoiceFile());
|
||||
} else if (sendVoice.getNewVoiceStream() != null) {
|
||||
builder.addBinaryBody(SendVoice.AUDIO_FIELD, sendVoice.getNewVoiceStream());
|
||||
} else {
|
||||
builder.addBinaryBody(SendVoice.AUDIO_FIELD, new java.io.File(sendVoice.getAudio()), ContentType.create("audio/ogg"), sendVoice.getVoiceName());
|
||||
}
|
||||
if (sendVoice.getReplayMarkup() != null) {
|
||||
builder.addTextBody(SendVoice.REPLYMARKUP_FIELD, sendVoice.getReplayMarkup().toJson().toString(), TEXT_PLAIN_CONTENT_TYPE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user