Support new disabled notifications

This commit is contained in:
Rubenlagus 2016-02-27 03:17:06 +01:00 committed by Rubenlagus
parent f5dcee5cb1
commit bc2db06327
16 changed files with 424 additions and 13 deletions

View File

@ -3,6 +3,7 @@ package org.telegram.telegrambots.api.methods;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import org.json.JSONObject;
import org.telegram.telegrambots.api.objects.Message;
@ -23,6 +24,14 @@ public class ForwardMessage extends BotApiMethod<Message> {
private Integer fromChatId; ///< Unique identifier for the chat where the original message was sent User or GroupChat id
public static final String MESSAGEID_FIELD = "message_id";
private Integer messageId; ///< Unique message identifier
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
/**
* Optional. Sends the message silently.
* iOS users will not receive a notification,
* Android users will receive a notification with no sound.
* Other apps coming soon
*/
private Boolean disableNotification;
public ForwardMessage() {
super();
@ -52,6 +61,18 @@ public class ForwardMessage extends BotApiMethod<Message> {
this.messageId = messageId;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public void enableNotification() {
this.disableNotification = false;
}
public void disableNotification() {
this.disableNotification = true;
}
@Override
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
@ -59,6 +80,9 @@ public class ForwardMessage extends BotApiMethod<Message> {
gen.writeStringField(CHATID_FIELD, chatId);
gen.writeNumberField(FROMCHATID_FIELD, fromChatId);
gen.writeNumberField(MESSAGEID_FIELD, messageId);
if (disableNotification != null) {
gen.writeBooleanField(DISABLENOTIFICATION_FIELD, disableNotification);
}
gen.writeEndObject();
gen.flush();
}
@ -74,6 +98,9 @@ public class ForwardMessage extends BotApiMethod<Message> {
jsonObject.put(CHATID_FIELD, chatId);
jsonObject.put(FROMCHATID_FIELD, fromChatId);
jsonObject.put(MESSAGEID_FIELD, messageId);
if (disableNotification != null) {
jsonObject.put(DISABLENOTIFICATION_FIELD, disableNotification);
}
return jsonObject;
}

View File

@ -15,9 +15,13 @@ public class GetUpdates implements IToJson {
public static final String OFFSET_FIELD = "offset";
/**
* Optional Identifier of the first update to be returned.
* Must be greater by one than the highest among the identifiers of previously received updates.
* By default, updates starting with the earliest unconfirmed update are returned.
* Optional. Identifier of the first update to be returned.
* Must be greater by one than the highest among the identifiers
* of previously received updates. By default, updates starting with the
* earliest unconfirmed update are returned. An update is considered confirmed as soon as
* getUpdates is called with an offset higher than its update_id. The negative offset can
* be specified to retrieve updates starting from -offset update from the end of
* the updates queue. All previous updates will forgotten.
*/
private Integer offset;
public static final String LIMIT_FIELD = "limit";

View File

@ -10,10 +10,7 @@ import org.telegram.telegrambots.api.objects.ReplyKeyboard;
* Your audio must be in an .mp3 format. On success, the sent Message is returned.
* Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
*
* @note For backward compatibility, when both fields title and description are empty and mime-type of the sent
* file is not audio/mpeg, file is sent as playable voice message.
* In this case, your audio must be in an .ogg file encoded with OPUS.
* This will be removed in the future. You need to use sendVoice method instead.
* @note For sending voice notes, use sendVoice method instead.
*
* @date 16 of July of 2015
*/
@ -26,6 +23,14 @@ public class SendAudio {
private String audio; ///< Audio file to send. file_id as String to resend an audio that is already on the Telegram servers
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
/**
* Optional. Sends the message silently.
* iOS users will not receive a notification,
* Android users will receive a notification with no sound.
* Other apps coming soon
*/
private Boolean disableNotification;
public static final String REPLYMARKUP_FIELD = "reply_markup";
private ReplyKeyboard replayMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard
public static final String PERFOMER_FIELD = "performer";
@ -105,6 +110,18 @@ public class SendAudio {
this.title = title;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public void enableNotification() {
this.disableNotification = false;
}
public void disableNotification() {
this.disableNotification = true;
}
public boolean isNewAudio() {
return isNewAudio;
}

View File

@ -15,6 +15,16 @@ public class SendDocument {
private String chatId; ///< Unique identifier for the chat to send the message to or Username for the channel to send the message to
public static final String DOCUMENT_FIELD = "document";
private String document; ///< File file to send. file_id as String to resend a file that is already on the Telegram servers
public static final String CAPTION_FIELD = "caption";
private String caption; ///< Optional. Document caption (may also be used when resending documents by file_id), 0-200 characters
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
/**
* Optional. Sends the message silently.
* iOS users will not receive a notification,
* Android users will receive a notification with no sound.
* Other apps coming soon
*/
private Boolean disableNotification;
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
public static final String REPLYMARKUP_FIELD = "reply_markup";
@ -66,6 +76,26 @@ public class SendDocument {
this.replayToMessageId = replayToMessageId;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public void enableNotification() {
this.disableNotification = false;
}
public void disableNotification() {
this.disableNotification = true;
}
public String getCaption() {
return caption;
}
public void setCaption(String caption) {
this.caption = caption;
}
public ReplyKeyboard getReplayMarkup() {
return replayMarkup;
}

View File

@ -3,6 +3,7 @@ package org.telegram.telegrambots.api.methods;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import org.json.JSONObject;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.ReplyKeyboard;
@ -24,6 +25,14 @@ public class SendLocation extends BotApiMethod<Message> {
private Float latitude; ///< Latitude of location
public static final String LONGITUDE_FIELD = "longitude";
private Float longitude; ///< Longitude of location
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
/**
* Optional. Sends the message silently.
* iOS users will not receive a notification,
* Android users will receive a notification with no sound.
* Other apps coming soon
*/
private Boolean disableNotification;
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
public static final String REPLYMARKUP_FIELD = "reply_markup";
@ -69,6 +78,18 @@ public class SendLocation extends BotApiMethod<Message> {
this.replayMarkup = replayMarkup;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public void enableNotification() {
this.disableNotification = false;
}
public void disableNotification() {
this.disableNotification = true;
}
@Override
public String getPath() {
return PATH;
@ -88,6 +109,9 @@ public class SendLocation extends BotApiMethod<Message> {
jsonObject.put(CHATID_FIELD, chatId);
jsonObject.put(LATITUDE_FIELD, latitude);
jsonObject.put(LONGITUDE_FIELD, longitude);
if (disableNotification != null) {
jsonObject.put(DISABLENOTIFICATION_FIELD, disableNotification);
}
if (replayToMessageId != null) {
jsonObject.put(REPLYTOMESSAGEID_FIELD, replayToMessageId);
}
@ -105,6 +129,9 @@ public class SendLocation extends BotApiMethod<Message> {
gen.writeStringField(CHATID_FIELD, chatId);
gen.writeNumberField(LATITUDE_FIELD, latitude);
gen.writeNumberField(LONGITUDE_FIELD, longitude);
if (disableNotification != null) {
gen.writeBooleanField(DISABLENOTIFICATION_FIELD, disableNotification);
}
if (replayToMessageId != null) {
gen.writeNumberField(REPLYTOMESSAGEID_FIELD, replayToMessageId);
}

View File

@ -3,6 +3,7 @@ package org.telegram.telegrambots.api.methods;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import org.json.JSONObject;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.ReplyKeyboard;
@ -26,6 +27,14 @@ public class SendMessage extends BotApiMethod<Message> {
private String parseMode; ///< Optional. Send Markdown, if you want Telegram apps to show bold, italic and URL text in your bot's message.
public static final String DISABLEWEBPAGEPREVIEW_FIELD = "disable_web_page_preview";
private Boolean disableWebPagePreview; ///< Optional. Disables link previews for links in this message
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
/**
* Optional. Sends the message silently.
* iOS users will not receive a notification,
* Android users will receive a notification with no sound.
* Other apps coming soon
*/
private Boolean disableNotification;
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
public static final String REPLYMARKUP_FIELD = "reply_markup";
@ -75,6 +84,18 @@ public class SendMessage extends BotApiMethod<Message> {
this.disableWebPagePreview = disableWebPagePreview;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public void enableNotification() {
this.disableNotification = false;
}
public void disableNotification() {
this.disableNotification = true;
}
public void enableMarkdown(boolean enable) {
if (enable) {
this.parseMode = "Markdown";
@ -102,6 +123,9 @@ public class SendMessage extends BotApiMethod<Message> {
if (disableWebPagePreview != null) {
jsonObject.put(DISABLEWEBPAGEPREVIEW_FIELD, disableWebPagePreview);
}
if (disableNotification != null) {
jsonObject.put(DISABLENOTIFICATION_FIELD, disableNotification);
}
if (replayToMessageId != null) {
jsonObject.put(REPLYTOMESSAGEID_FIELD, replayToMessageId);
}
@ -138,6 +162,9 @@ public class SendMessage extends BotApiMethod<Message> {
if (disableWebPagePreview != null) {
gen.writeBooleanField(DISABLEWEBPAGEPREVIEW_FIELD, disableWebPagePreview);
}
if (disableNotification != null) {
gen.writeBooleanField(DISABLENOTIFICATION_FIELD, disableNotification);
}
if (replayToMessageId != null) {
gen.writeNumberField(REPLYTOMESSAGEID_FIELD, replayToMessageId);
}

View File

@ -17,6 +17,14 @@ public class SendPhoto {
private String photo; ///< Photo to send. file_id as String to resend a photo that is already on the Telegram servers
public static final String CAPTION_FIELD = "photo";
private String caption; ///< Optional Photo caption (may also be used when resending photos by file_id).
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
/**
* Optional. Sends the message silently.
* iOS users will not receive a notification,
* Android users will receive a notification with no sound.
* Other apps coming soon
*/
private Boolean disableNotification;
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
public static final String REPLYMARKUP_FIELD = "reply_markup";
@ -74,6 +82,18 @@ public class SendPhoto {
return photoName;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public void enableNotification() {
this.disableNotification = false;
}
public void disableNotification() {
this.disableNotification = true;
}
public void setPhoto(String photo) {
this.photo = photo;
this.isNewPhoto = false;

View File

@ -15,6 +15,14 @@ public class SendSticker {
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
public static final String STICKER_FIELD = "sticker";
private String sticker; ///< Sticker file to send. file_id as String to resend a sticker that is already on the Telegram servers
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
/**
* Optional. Sends the message silently.
* iOS users will not receive a notification,
* Android users will receive a notification with no sound.
* Other apps coming soon
*/
private Boolean disableNotification;
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
public static final String REPLYMARKUP_FIELD = "reply_markup";
@ -66,6 +74,18 @@ public class SendSticker {
this.stickerName = stickerName;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public void enableNotification() {
this.disableNotification = false;
}
public void disableNotification() {
this.disableNotification = true;
}
public boolean isNewSticker() {
return isNewSticker;
}

View File

@ -21,6 +21,18 @@ public class SendVideo {
private Integer duration; ///< Optional. Duration of sent video in seconds
public static final String CAPTION_FIELD = "caption";
private String caption; ///< OptionaL. Video caption (may also be used when resending videos by file_id).
public static final String WIDTH_FIELD = "width";
private Integer width; ///< Optional. Video width
public static final String HEIGHT_FIELD = "height";
private Integer height; ///< OptionaL. Video height
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
/**
* Optional. Sends the message silently.
* iOS users will not receive a notification,
* Android users will receive a notification with no sound.
* Other apps coming soon
*/
private Boolean disableNotification;
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
public static final String REPLYMARKUP_FIELD = "reply_markup";
@ -85,6 +97,34 @@ public class SendVideo {
return videoName;
}
public Boolean getDisableNotification() {
return disableNotification;
}
public void enableNotification() {
this.disableNotification = false;
}
public void disableNotification() {
this.disableNotification = true;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
public void setVideo(String video) {
this.video = video;
this.isNewVideo = false;

View File

@ -17,7 +17,15 @@ public class SendVoice {
public static final String CHATID_FIELD = "chat_id";
private String chatId; ///< Unique identifier for the chat sent message to (Or username for channels)
public static final String AUDIO_FIELD = "audio";
private String audio; ///< Audio file to send. file_id as String to resend an audio that is already on the Telegram servers
private String audio; ///< Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
public static final String DISABLENOTIFICATION_FIELD = "disable_notification";
/**
* Optional. Sends the message silently.
* iOS users will not receive a notification,
* Android users will receive a notification with no sound.
* Other apps coming soon
*/
private Boolean disableNotification;
public static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id";
private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message
public static final String REPLYMARKUP_FIELD = "reply_markup";
@ -25,7 +33,77 @@ public class SendVoice {
public static final String DURATION_FIELD = "duration";
private Integer duration; ///< Optional. Duration of sent audio in seconds
private boolean isNewVoice; ///< True to upload a new voice note, false to use a fileId
private String voiceName; ///< Name of the voice note
public SendVoice() {
super();
}
public Boolean getDisableNotification() {
return disableNotification;
}
public void enableNotification() {
this.disableNotification = false;
}
public void disableNotification() {
this.disableNotification = true;
}
public String getChatId() {
return chatId;
}
public void setChatId(String chatId) {
this.chatId = chatId;
}
public String getAudio() {
return audio;
}
public void setAudio(String audio) {
this.audio = audio;
this.isNewVoice = false;
}
public void setNewAudio(String audio, String audioName) {
this.audio = audio;
this.isNewVoice = false;
this.voiceName = audioName;
}
public Integer getReplayToMessageId() {
return replayToMessageId;
}
public void setReplayToMessageId(Integer replayToMessageId) {
this.replayToMessageId = replayToMessageId;
}
public ReplyKeyboard getReplayMarkup() {
return replayMarkup;
}
public void setReplayMarkup(ReplyKeyboard replayMarkup) {
this.replayMarkup = replayMarkup;
}
public Integer getDuration() {
return duration;
}
public void setDuration(Integer duration) {
this.duration = duration;
}
public boolean isNewVoice() {
return isNewVoice;
}
public String getVoiceName() {
return voiceName;
}
}

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import org.json.JSONObject;
import java.io.IOException;
@ -27,7 +28,7 @@ public class InlineQueryResultArticle implements InlineQueryResult {
private String title; ///< Title of the result
public static final String MESSAGETEXT_FIELD = "message_text";
@JsonProperty(MESSAGETEXT_FIELD)
private String messageText; ///< Text of a message to be sent
private String messageText; ///< Text of a message to be sent, 1-4096 characters
public static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Optional. Send Markdown, if you want Telegram apps to show bold, italic and inline URLs in your bot's message.

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import org.json.JSONObject;
import java.io.IOException;
@ -43,7 +44,7 @@ public class InlineQueryResultGif implements InlineQueryResult {
private String caption; ///< Optional. Caption of the GIF file to be sent
public static final String MESSAGETEXT_FIELD = "message_text";
@JsonProperty(MESSAGETEXT_FIELD)
private String messageText; ///< Optional. Text of a message to be sent instead of the animation
private String messageText; ///< Optional. Text of a message to be sent instead of the animation, 1-4096 characters
public static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Optional. Send Markdown, if you want Telegram apps to show bold, italic and inline URLs in your bot's message.

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import org.json.JSONObject;
import java.io.IOException;
@ -44,7 +45,7 @@ public class InlineQueryResultMpeg4Gif implements InlineQueryResult {
private String caption; ///< Optional. Caption of the MPEG-4 file to be sent
public static final String MESSAGETEXT_FIELD = "message_text";
@JsonProperty(MESSAGETEXT_FIELD)
private String messageText; ///< Optional. Text of a message to be sent instead of the animation
private String messageText; ///< Optional. Text of a message to be sent instead of the animation, 1-4096 characters
public static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Optional. Send Markdown, if you want Telegram apps to show bold, italic and inline URLs in your bot's message.

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import org.json.JSONObject;
import java.io.IOException;
@ -49,7 +50,7 @@ public class InlineQueryResultPhoto implements InlineQueryResult {
private String caption; ///< Optional. Caption of the photo to be sent
public static final String MESSAGETEXT_FIELD = "message_text";
@JsonProperty(MESSAGETEXT_FIELD)
private String messageText; ///< Optional. Text of a message to be sent instead of the photo
private String messageText; ///< Optional. Text of a message to be sent instead of the photo, 1-4096 characters
public static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Optional. Send Markdown, if you want Telegram apps to show bold, italic and inline URLs in your bot's message.

View File

@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import org.json.JSONObject;
import java.io.IOException;
@ -48,7 +49,7 @@ public class InlineQueryResultVideo implements InlineQueryResult {
private String description; ///< Optional. Short description of the result
public static final String MESSAGETEXT_FIELD = "message_text";
@JsonProperty(MESSAGETEXT_FIELD)
private String messageText; ///< Optional. Text of a message to be sent instead of the video
private String messageText; ///< Optional. Text of a message to be sent instead of the video, 1-4096 characters
public static final String PARSEMODE_FIELD = "parse_mode";
@JsonProperty(PARSEMODE_FIELD)
private String parseMode; ///< Optional. Send Markdown, if you want Telegram apps to show bold, italic and inline URLs in your bot's message.

View File

@ -31,6 +31,7 @@ import org.telegram.telegrambots.api.methods.SendMessage;
import org.telegram.telegrambots.api.methods.SendPhoto;
import org.telegram.telegrambots.api.methods.SendSticker;
import org.telegram.telegrambots.api.methods.SendVideo;
import org.telegram.telegrambots.api.methods.SendVoice;
import org.telegram.telegrambots.api.objects.File;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.User;
@ -212,6 +213,12 @@ public abstract class AbsSender {
if (sendDocument.getReplayToMessageId() != null) {
builder.addTextBody(SendDocument.REPLYTOMESSAGEID_FIELD, sendDocument.getReplayToMessageId().toString());
}
if (sendDocument.getCaption() != null) {
builder.addTextBody(SendDocument.CAPTION_FIELD, sendDocument.getCaption());
}
if (sendDocument.getDisableNotification() != null) {
builder.addTextBody(SendDocument.DISABLENOTIFICATION_FIELD, sendDocument.getDisableNotification().toString());
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
} else {
@ -224,6 +231,12 @@ public abstract class AbsSender {
if (sendDocument.getReplayToMessageId() != null) {
nameValuePairs.add(new BasicNameValuePair(SendDocument.REPLYTOMESSAGEID_FIELD, sendDocument.getReplayToMessageId().toString()));
}
if (sendDocument.getCaption() != null) {
nameValuePairs.add(new BasicNameValuePair(SendDocument.CAPTION_FIELD, sendDocument.getCaption()));
}
if (sendDocument.getReplayToMessageId() != null) {
nameValuePairs.add(new BasicNameValuePair(SendDocument.DISABLENOTIFICATION_FIELD, sendDocument.getDisableNotification().toString()));
}
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
}
@ -263,6 +276,9 @@ public abstract class AbsSender {
if (sendPhoto.getCaption() != null) {
builder.addTextBody(SendPhoto.CAPTION_FIELD, sendPhoto.getCaption());
}
if (sendPhoto.getDisableNotification() != null) {
builder.addTextBody(SendPhoto.DISABLENOTIFICATION_FIELD, sendPhoto.getDisableNotification().toString());
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
} else {
@ -278,6 +294,9 @@ public abstract class AbsSender {
if (sendPhoto.getCaption() != null) {
nameValuePairs.add(new BasicNameValuePair(SendPhoto.CAPTION_FIELD, sendPhoto.getCaption()));
}
if (sendPhoto.getDisableNotification() != null) {
nameValuePairs.add(new BasicNameValuePair(SendPhoto.DISABLENOTIFICATION_FIELD, sendPhoto.getDisableNotification().toString()));
}
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
}
@ -320,6 +339,15 @@ public abstract class AbsSender {
if (sendVideo.getDuration() != null) {
builder.addTextBody(SendVideo.DURATION_FIELD, sendVideo.getDuration().toString());
}
if (sendVideo.getWidth() != null) {
builder.addTextBody(SendVideo.WIDTH_FIELD, sendVideo.getWidth().toString());
}
if (sendVideo.getHeight() != null) {
builder.addTextBody(SendVideo.HEIGHT_FIELD, sendVideo.getHeight().toString());
}
if (sendVideo.getDisableNotification() != null) {
builder.addTextBody(SendVideo.DISABLENOTIFICATION_FIELD, sendVideo.getDisableNotification().toString());
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
} else {
@ -338,6 +366,15 @@ public abstract class AbsSender {
if (sendVideo.getDuration() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVideo.DURATION_FIELD, sendVideo.getDuration().toString()));
}
if (sendVideo.getWidth() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVideo.WIDTH_FIELD, sendVideo.getWidth().toString()));
}
if (sendVideo.getHeight() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVideo.HEIGHT_FIELD, sendVideo.getHeight().toString()));
}
if (sendVideo.getDisableNotification() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVideo.DISABLENOTIFICATION_FIELD, sendVideo.getDisableNotification().toString()));
}
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
}
@ -375,6 +412,9 @@ public abstract class AbsSender {
if (sendSticker.getReplayToMessageId() != null) {
builder.addTextBody(SendSticker.REPLYTOMESSAGEID_FIELD, sendSticker.getReplayToMessageId().toString());
}
if (sendSticker.getDisableNotification() != null) {
builder.addTextBody(SendSticker.DISABLENOTIFICATION_FIELD, sendSticker.getDisableNotification().toString());
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
} else {
@ -387,6 +427,9 @@ public abstract class AbsSender {
if (sendSticker.getReplayToMessageId() != null) {
nameValuePairs.add(new BasicNameValuePair(SendSticker.REPLYTOMESSAGEID_FIELD, sendSticker.getReplayToMessageId().toString()));
}
if (sendSticker.getDisableNotification() != null) {
nameValuePairs.add(new BasicNameValuePair(SendSticker.DISABLENOTIFICATION_FIELD, sendSticker.getDisableNotification().toString()));
}
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
}
@ -436,6 +479,9 @@ public abstract class AbsSender {
if (sendAudio.getTitle() != null) {
builder.addTextBody(SendAudio.TITLE_FIELD, sendAudio.getTitle());
}
if (sendAudio.getDisableNotification() != null) {
builder.addTextBody(SendAudio.DISABLENOTIFICATION_FIELD, sendAudio.getDisableNotification().toString());
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
} else {
@ -454,6 +500,9 @@ public abstract class AbsSender {
if (sendAudio.getTitle() != null) {
nameValuePairs.add(new BasicNameValuePair(SendAudio.TITLE_FIELD, sendAudio.getTitle()));
}
if (sendAudio.getDisableNotification() != null) {
nameValuePairs.add(new BasicNameValuePair(SendAudio.DISABLENOTIFICATION_FIELD, sendAudio.getDisableNotification().toString()));
}
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
}
@ -473,6 +522,73 @@ public abstract class AbsSender {
return new Message(jsonObject);
}
/**
* Sends a voice note using Send Voice method (https://core.telegram.org/bots/api#sendvoice)
* @param sendVoice Information to send
* @return If success, the sent Message is returned
* @throws TelegramApiException If there is any error sending the audio
*/
public Message sendVoice(SendVoice sendVoice) throws TelegramApiException {
String responseContent;
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
String url = getBaseUrl() + SendVoice.PATH;
HttpPost httppost = new HttpPost(url);
if (sendVoice.isNewVoice()) {
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody(SendVoice.CHATID_FIELD, sendVoice.getChatId());
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());
}
if (sendVoice.getReplayToMessageId() != null) {
builder.addTextBody(SendVoice.REPLYTOMESSAGEID_FIELD, sendVoice.getReplayToMessageId().toString());
}
if (sendVoice.getDisableNotification() != null) {
builder.addTextBody(SendVoice.DISABLENOTIFICATION_FIELD, sendVoice.getDisableNotification().toString());
}
if (sendVoice.getDuration() != null) {
builder.addTextBody(SendVoice.DURATION_FIELD, sendVoice.getDuration().toString());
}
HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
} else {
List<NameValuePair> nameValuePairs = new ArrayList<>();
nameValuePairs.add(new BasicNameValuePair(SendVoice.CHATID_FIELD, sendVoice.getChatId()));
nameValuePairs.add(new BasicNameValuePair(SendVoice.AUDIO_FIELD, sendVoice.getAudio()));
if (sendVoice.getReplayMarkup() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVoice.REPLYMARKUP_FIELD, sendVoice.getReplayMarkup().toString()));
}
if (sendVoice.getReplayToMessageId() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVoice.REPLYTOMESSAGEID_FIELD, sendVoice.getReplayToMessageId().toString()));
}
if (sendVoice.getDisableNotification() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVoice.DISABLENOTIFICATION_FIELD, sendVoice.getDisableNotification().toString()));
}
if (sendVoice.getDuration() != null) {
nameValuePairs.add(new BasicNameValuePair(SendVoice.DURATION_FIELD, sendVoice.getDuration().toString()));
}
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
}
CloseableHttpResponse response = httpClient.execute(httppost);
HttpEntity ht = response.getEntity();
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
responseContent = EntityUtils.toString(buf, "UTF-8");
} catch (IOException e) {
throw new TelegramApiException("Unable to send sticker", e);
}
JSONObject jsonObject = new JSONObject(responseContent);
if (!jsonObject.getBoolean("ok")) {
throw new TelegramApiException("Error at sendVoice", jsonObject.getString("description"));
}
return new Message(jsonObject);
}
private void sendApiMethodAsync(BotApiMethod method, SentCallback callback) {
exe.submit(() -> {
try {