From 49ff79f0cd7f32e3a59fcb7e3b6c245f22a24a39 Mon Sep 17 00:00:00 2001 From: Rubenlagu Date: Sun, 24 Jan 2016 03:20:54 +0100 Subject: [PATCH 01/19] Added sendAudio support to AbsSender Close #2 --- .../telegrambots/api/methods/SendAudio.java | 11 +++ .../telegram/telegrambots/bots/AbsSender.java | 73 ++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java b/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java index 93eb237e..53239f2e 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java @@ -51,11 +51,22 @@ public class SendAudio { return audio; } + /** + * 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 void setAudio(String audio) { this.audio = audio; this.isNewAudio = false; } + /** + * Use this method to set the audio to a new file + * @param audio Path to the new file in your server + * @param audioName Name of the file itself + */ public void setNewAudio(String audio, String audioName) { this.audio = audio; this.isNewAudio = true; diff --git a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java index 0779642c..3b8c65de 100644 --- a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java +++ b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java @@ -35,12 +35,16 @@ import java.util.concurrent.Executors; /** * @author Ruben Bermudez * @version 1.0 - * @brief TODO + * @brief Implementation of all the methods needed to interact with Telegram Servers * @date 14 of January of 2016 */ public abstract class AbsSender { private final ExecutorService exe = Executors.newSingleThreadExecutor(); + /** + * Returns the token of the bot to be able to perform Telegram Api Requests + * @return Token of the bot + */ public abstract String getBotToken(); public Message sendMessage(SendMessage sendMessage) throws TelegramApiException { @@ -390,6 +394,73 @@ public abstract class AbsSender { return new Message(jsonObject); } + /** + * Sends a file using Send Audio method (https://core.telegram.org/bots/api#sendaudio) + * @param sendAudio Information to send + * @return If success, the sent Message is returned + * @throws TelegramApiException If there is any error sending the audio + */ + public Message sendAudio(SendAudio sendAudio) throws TelegramApiException { + String responseContent; + + try { + CloseableHttpClient httpClient = HttpClients.createDefault(); + String url = getBaseUrl() + SendAudio.PATH; + HttpPost httppost = new HttpPost(url); + + if (sendAudio.isNewAudio()) { + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.addTextBody(SendAudio.CHATID_FIELD, sendAudio.getChatId()); + builder.addBinaryBody(SendAudio.AUDIO_FIELD, new java.io.File(sendAudio.getAudio()), ContentType.APPLICATION_OCTET_STREAM, sendAudio.getAudioName()); + if (sendAudio.getReplayMarkup() != null) { + builder.addTextBody(SendAudio.REPLYMARKUP_FIELD, sendAudio.getReplayMarkup().toJson().toString()); + } + if (sendAudio.getReplayToMessageId() != null) { + builder.addTextBody(SendAudio.REPLYTOMESSAGEID_FIELD, sendAudio.getReplayToMessageId().toString()); + } + if (sendAudio.getPerformer() != null) { + builder.addTextBody(SendAudio.PERFOMER_FIELD, sendAudio.getPerformer()); + } + if (sendAudio.getTitle() != null) { + builder.addTextBody(SendAudio.TITLE_FIELD, sendAudio.getTitle()); + } + HttpEntity multipart = builder.build(); + httppost.setEntity(multipart); + } else { + List nameValuePairs = new ArrayList<>(); + nameValuePairs.add(new BasicNameValuePair(SendAudio.CHATID_FIELD, sendAudio.getChatId())); + nameValuePairs.add(new BasicNameValuePair(SendAudio.AUDIO_FIELD, sendAudio.getAudio())); + if (sendAudio.getReplayMarkup() != null) { + nameValuePairs.add(new BasicNameValuePair(SendAudio.REPLYMARKUP_FIELD, sendAudio.getReplayMarkup().toString())); + } + if (sendAudio.getReplayToMessageId() != null) { + nameValuePairs.add(new BasicNameValuePair(SendAudio.REPLYTOMESSAGEID_FIELD, sendAudio.getReplayToMessageId().toString())); + } + if (sendAudio.getPerformer() != null) { + nameValuePairs.add(new BasicNameValuePair(SendAudio.PERFOMER_FIELD, sendAudio.getPerformer())); + } + if (sendAudio.getTitle() != null) { + nameValuePairs.add(new BasicNameValuePair(SendAudio.TITLE_FIELD, sendAudio.getTitle())); + } + 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 sendAudio", jsonObject.getString("description")); + } + + return new Message(jsonObject); + } + private void sendApiMethodAsync(BotApiMethod method, SentCallback callback) { exe.submit(() -> { try { From f5dcee5cb10fd4ee1668d40b30b6193a67a0ef19 Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Tue, 16 Feb 2016 00:24:32 +0100 Subject: [PATCH 02/19] Added undocumented field Updated sendaudio method --- .../telegrambots/api/objects/PhotoSize.java | 18 ++++++++++++++++++ .../telegram/telegrambots/bots/AbsSender.java | 16 ++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/telegram/telegrambots/api/objects/PhotoSize.java b/src/main/java/org/telegram/telegrambots/api/objects/PhotoSize.java index b7869434..c60a3b77 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/PhotoSize.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/PhotoSize.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -29,6 +30,9 @@ public class PhotoSize implements IBotApiObject { public static final String FILESIZE_FIELD = "file_size"; @JsonProperty(FILESIZE_FIELD) private Integer fileSize; ///< Optional. File size + private static final String FILEPATH_FIELD = "file_path"; + @JsonProperty(FILEPATH_FIELD) + private String filePath; ///< Undocumented field. Optional. Can contain the path to download the file direclty without calling to getFile public PhotoSize() { super(); @@ -42,6 +46,9 @@ public class PhotoSize implements IBotApiObject { if (jsonObject.has(FILESIZE_FIELD)) { this.fileSize = jsonObject.getInt(FILESIZE_FIELD); } + if (jsonObject.has(FILEPATH_FIELD)) { + this.filePath = jsonObject.getString(FILEPATH_FIELD); + } } public String getFileId() { @@ -76,6 +83,14 @@ public class PhotoSize implements IBotApiObject { this.fileSize = fileSize; } + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + @Override public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException { gen.writeStartObject(); @@ -85,6 +100,9 @@ public class PhotoSize implements IBotApiObject { if (fileSize != null) { gen.writeNumberField(FILESIZE_FIELD, fileSize); } + if (filePath != null) { + gen.writeStringField(FILEPATH_FIELD, filePath); + } gen.writeEndObject(); gen.flush(); } diff --git a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java index 3b8c65de..a35300cb 100644 --- a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java +++ b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java @@ -18,7 +18,19 @@ import org.apache.http.util.EntityUtils; import org.json.JSONObject; import org.telegram.telegrambots.TelegramApiException; import org.telegram.telegrambots.api.Constants; -import org.telegram.telegrambots.api.methods.*; +import org.telegram.telegrambots.api.methods.AnswerInlineQuery; +import org.telegram.telegrambots.api.methods.BotApiMethod; +import org.telegram.telegrambots.api.methods.ForwardMessage; +import org.telegram.telegrambots.api.methods.GetMe; +import org.telegram.telegrambots.api.methods.GetUserProfilePhotos; +import org.telegram.telegrambots.api.methods.SendAudio; +import org.telegram.telegrambots.api.methods.SendChatAction; +import org.telegram.telegrambots.api.methods.SendDocument; +import org.telegram.telegrambots.api.methods.SendLocation; +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.objects.File; import org.telegram.telegrambots.api.objects.Message; import org.telegram.telegrambots.api.objects.User; @@ -411,7 +423,7 @@ public abstract class AbsSender { if (sendAudio.isNewAudio()) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody(SendAudio.CHATID_FIELD, sendAudio.getChatId()); - builder.addBinaryBody(SendAudio.AUDIO_FIELD, new java.io.File(sendAudio.getAudio()), ContentType.APPLICATION_OCTET_STREAM, sendAudio.getAudioName()); + 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()); } From bc2db063273f677edc409737c1ff4b3611cdf5ad Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Sat, 27 Feb 2016 03:17:06 +0100 Subject: [PATCH 03/19] Support new disabled notifications --- .../api/methods/ForwardMessage.java | 27 ++++ .../telegrambots/api/methods/GetUpdates.java | 10 +- .../telegrambots/api/methods/SendAudio.java | 25 +++- .../api/methods/SendDocument.java | 30 +++++ .../api/methods/SendLocation.java | 27 ++++ .../telegrambots/api/methods/SendMessage.java | 27 ++++ .../telegrambots/api/methods/SendPhoto.java | 20 +++ .../telegrambots/api/methods/SendSticker.java | 20 +++ .../telegrambots/api/methods/SendVideo.java | 40 ++++++ .../telegrambots/api/methods/SendVoice.java | 80 +++++++++++- .../api/objects/InlineQueryResultArticle.java | 3 +- .../api/objects/InlineQueryResultGif.java | 3 +- .../objects/InlineQueryResultMpeg4Gif.java | 3 +- .../api/objects/InlineQueryResultPhoto.java | 3 +- .../api/objects/InlineQueryResultVideo.java | 3 +- .../telegram/telegrambots/bots/AbsSender.java | 116 ++++++++++++++++++ 16 files changed, 424 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java b/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java index 24e8b67f..24883d44 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java @@ -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 { 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 { 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 { 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 { 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; } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/GetUpdates.java b/src/main/java/org/telegram/telegrambots/api/methods/GetUpdates.java index 80908460..8b40a8f7 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/GetUpdates.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/GetUpdates.java @@ -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"; diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java b/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java index 53239f2e..04e050ff 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java @@ -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; } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendDocument.java b/src/main/java/org/telegram/telegrambots/api/methods/SendDocument.java index 32a7a7a8..d1ae50a5 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendDocument.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendDocument.java @@ -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; } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendLocation.java b/src/main/java/org/telegram/telegrambots/api/methods/SendLocation.java index d2ecd057..9bf26f8d 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendLocation.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendLocation.java @@ -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 { 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 { 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 { 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 { 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); } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendMessage.java b/src/main/java/org/telegram/telegrambots/api/methods/SendMessage.java index 74261cea..acba1990 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendMessage.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendMessage.java @@ -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 { 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 { 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 { 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 { if (disableWebPagePreview != null) { gen.writeBooleanField(DISABLEWEBPAGEPREVIEW_FIELD, disableWebPagePreview); } + if (disableNotification != null) { + gen.writeBooleanField(DISABLENOTIFICATION_FIELD, disableNotification); + } if (replayToMessageId != null) { gen.writeNumberField(REPLYTOMESSAGEID_FIELD, replayToMessageId); } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendPhoto.java b/src/main/java/org/telegram/telegrambots/api/methods/SendPhoto.java index 8e2388f4..6dfafbe8 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendPhoto.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendPhoto.java @@ -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; diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendSticker.java b/src/main/java/org/telegram/telegrambots/api/methods/SendSticker.java index 987eeca1..351561a9 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendSticker.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendSticker.java @@ -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; } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendVideo.java b/src/main/java/org/telegram/telegrambots/api/methods/SendVideo.java index ed573603..f6fdf630 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendVideo.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendVideo.java @@ -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; diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendVoice.java b/src/main/java/org/telegram/telegrambots/api/methods/SendVoice.java index 2dfca578..2e26fa29 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendVoice.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendVoice.java @@ -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; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultArticle.java b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultArticle.java index e3ec0503..7d21bb50 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultArticle.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultArticle.java @@ -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. diff --git a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultGif.java b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultGif.java index 168ae778..8d887f7a 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultGif.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultGif.java @@ -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. diff --git a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultMpeg4Gif.java b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultMpeg4Gif.java index f7fd2f36..4e71c2e5 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultMpeg4Gif.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultMpeg4Gif.java @@ -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. diff --git a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultPhoto.java b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultPhoto.java index 835dfd7c..861208d4 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultPhoto.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultPhoto.java @@ -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. diff --git a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultVideo.java b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultVideo.java index 28cc7461..a62bf6de 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultVideo.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultVideo.java @@ -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. diff --git a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java index a35300cb..3e8b0fb1 100644 --- a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java +++ b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java @@ -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 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 { From 5db2f3ddeb7f4b1bf36c8abf8963d195a5b86f1c Mon Sep 17 00:00:00 2001 From: schors Date: Tue, 8 Mar 2016 22:17:07 +0300 Subject: [PATCH 04/19] added toString() method for all serializable classes --- .../api/methods/AnswerInlineQuery.java | 11 +++++++ .../api/methods/ForwardMessage.java | 9 ++++++ .../telegrambots/api/methods/GetFile.java | 7 ++++ .../telegrambots/api/methods/GetMe.java | 2 ++ .../telegrambots/api/methods/GetUpdates.java | 9 ++++++ .../api/methods/GetUserProfilePhotos.java | 9 ++++++ .../telegrambots/api/methods/SendAudio.java | 14 ++++++++ .../api/methods/SendChatAction.java | 8 +++++ .../api/methods/SendDocument.java | 12 +++++++ .../api/methods/SendLocation.java | 11 +++++++ .../telegrambots/api/methods/SendMessage.java | 12 +++++++ .../telegrambots/api/methods/SendPhoto.java | 13 ++++++++ .../telegrambots/api/methods/SendSticker.java | 12 +++++++ .../telegrambots/api/methods/SendVideo.java | 14 ++++++++ .../telegrambots/api/methods/SendVoice.java | 11 +++++++ .../telegrambots/api/methods/SetWebhook.java | 8 +++++ .../telegrambots/api/objects/Audio.java | 12 +++++++ .../telegrambots/api/objects/Chat.java | 12 +++++++ .../api/objects/ChosenInlineQuery.java | 9 ++++++ .../telegrambots/api/objects/Contact.java | 10 ++++++ .../telegrambots/api/objects/Document.java | 11 +++++++ .../telegrambots/api/objects/File.java | 9 ++++++ .../api/objects/ForceReplyKeyboard.java | 8 +++++ .../telegrambots/api/objects/InlineQuery.java | 11 +++++++ .../api/objects/InlineQueryResultArticle.java | 18 +++++++++++ .../api/objects/InlineQueryResultGif.java | 17 ++++++++++ .../objects/InlineQueryResultMpeg4Gif.java | 17 ++++++++++ .../api/objects/InlineQueryResultPhoto.java | 19 +++++++++++ .../api/objects/InlineQueryResultVideo.java | 19 +++++++++++ .../telegrambots/api/objects/Location.java | 8 +++++ .../telegrambots/api/objects/Message.java | 32 +++++++++++++++++++ .../telegrambots/api/objects/PhotoSize.java | 10 ++++++ .../api/objects/ReplyKeyboardHide.java | 8 +++++ .../api/objects/ReplyKeyboardMarkup.java | 10 ++++++ .../telegrambots/api/objects/Sticker.java | 11 +++++++ .../telegrambots/api/objects/Update.java | 10 ++++++ .../telegrambots/api/objects/User.java | 10 ++++++ .../api/objects/UserProfilePhotos.java | 8 +++++ .../telegrambots/api/objects/Video.java | 13 ++++++++ .../telegrambots/api/objects/Voice.java | 10 ++++++ 40 files changed, 464 insertions(+) diff --git a/src/main/java/org/telegram/telegrambots/api/methods/AnswerInlineQuery.java b/src/main/java/org/telegram/telegrambots/api/methods/AnswerInlineQuery.java index 37ec2757..8d37d3f5 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/AnswerInlineQuery.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/AnswerInlineQuery.java @@ -135,4 +135,15 @@ public class AnswerInlineQuery extends BotApiMethod { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "AnswerInlineQuery{" + + "inlineQueryId='" + inlineQueryId + '\'' + + ", results=" + results + + ", cacheTime=" + cacheTime + + ", isPersonal=" + isPersonal + + ", nextOffset='" + nextOffset + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java b/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java index 24e8b67f..bda92cf1 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java @@ -89,4 +89,13 @@ public class ForwardMessage extends BotApiMethod { } return null; } + + @Override + public String toString() { + return "ForwardMessage{" + + "chatId='" + chatId + '\'' + + ", fromChatId=" + fromChatId + + ", messageId=" + messageId + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/GetFile.java b/src/main/java/org/telegram/telegrambots/api/methods/GetFile.java index db81a712..ddcf3acf 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/GetFile.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/GetFile.java @@ -71,4 +71,11 @@ public class GetFile extends BotApiMethod { } return null; } + + @Override + public String toString() { + return "GetFile{" + + "fileId='" + fileId + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/GetMe.java b/src/main/java/org/telegram/telegrambots/api/methods/GetMe.java index 46ec62bd..a9f025b1 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/GetMe.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/GetMe.java @@ -47,4 +47,6 @@ public class GetMe extends BotApiMethod { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/GetUpdates.java b/src/main/java/org/telegram/telegrambots/api/methods/GetUpdates.java index 80908460..69def6b0 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/GetUpdates.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/GetUpdates.java @@ -74,4 +74,13 @@ public class GetUpdates implements IToJson { } return jsonObject; } + + @Override + public String toString() { + return "GetUpdates{" + + "offset=" + offset + + ", limit=" + limit + + ", timeout=" + timeout + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/GetUserProfilePhotos.java b/src/main/java/org/telegram/telegrambots/api/methods/GetUserProfilePhotos.java index d29828ee..45490c74 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/GetUserProfilePhotos.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/GetUserProfilePhotos.java @@ -99,4 +99,13 @@ public class GetUserProfilePhotos extends BotApiMethod { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "GetUserProfilePhotos{" + + "userId=" + userId + + ", offset=" + offset + + ", limit=" + limit + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java b/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java index 93eb237e..22038823 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java @@ -101,4 +101,18 @@ public class SendAudio { public String getAudioName() { return audioName; } + + @Override + public String toString() { + return "SendAudio{" + + "chatId='" + chatId + '\'' + + ", audio='" + audio + '\'' + + ", replayToMessageId=" + replayToMessageId + + ", replayMarkup=" + replayMarkup + + ", performer='" + performer + '\'' + + ", title='" + title + '\'' + + ", isNewAudio=" + isNewAudio + + ", audioName='" + audioName + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendChatAction.java b/src/main/java/org/telegram/telegrambots/api/methods/SendChatAction.java index 98f63500..ac168d81 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendChatAction.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendChatAction.java @@ -83,4 +83,12 @@ public class SendChatAction extends BotApiMethod{ public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "SendChatAction{" + + "chatId='" + chatId + '\'' + + ", action='" + action + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendDocument.java b/src/main/java/org/telegram/telegrambots/api/methods/SendDocument.java index 32a7a7a8..723185fa 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendDocument.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendDocument.java @@ -73,4 +73,16 @@ public class SendDocument { public void setReplayMarkup(ReplyKeyboard replayMarkup) { this.replayMarkup = replayMarkup; } + + @Override + public String toString() { + return "SendDocument{" + + "chatId='" + chatId + '\'' + + ", document='" + document + '\'' + + ", replayToMessageId=" + replayToMessageId + + ", replayMarkup=" + replayMarkup + + ", isNewDocument=" + isNewDocument + + ", documentName='" + documentName + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendLocation.java b/src/main/java/org/telegram/telegrambots/api/methods/SendLocation.java index d2ecd057..8fba16d8 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendLocation.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendLocation.java @@ -120,4 +120,15 @@ public class SendLocation extends BotApiMethod { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "SendLocation{" + + "chatId='" + chatId + '\'' + + ", latitude=" + latitude + + ", longitude=" + longitude + + ", replayToMessageId=" + replayToMessageId + + ", replayMarkup=" + replayMarkup + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendMessage.java b/src/main/java/org/telegram/telegrambots/api/methods/SendMessage.java index 74261cea..a16cbe71 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendMessage.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendMessage.java @@ -153,4 +153,16 @@ public class SendMessage extends BotApiMethod { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "SendMessage{" + + "chatId='" + chatId + '\'' + + ", text='" + text + '\'' + + ", parseMode='" + parseMode + '\'' + + ", disableWebPagePreview=" + disableWebPagePreview + + ", replayToMessageId=" + replayToMessageId + + ", replayMarkup=" + replayMarkup + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendPhoto.java b/src/main/java/org/telegram/telegrambots/api/methods/SendPhoto.java index 8e2388f4..2983d2d5 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendPhoto.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendPhoto.java @@ -84,4 +84,17 @@ public class SendPhoto { this.isNewPhoto = true; this.photoName = photoName; } + + @Override + public String toString() { + return "SendPhoto{" + + "chatId='" + chatId + '\'' + + ", photo='" + photo + '\'' + + ", caption='" + caption + '\'' + + ", replayToMessageId=" + replayToMessageId + + ", replayMarkup=" + replayMarkup + + ", isNewPhoto=" + isNewPhoto + + ", photoName='" + photoName + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendSticker.java b/src/main/java/org/telegram/telegrambots/api/methods/SendSticker.java index 987eeca1..fe24a616 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendSticker.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendSticker.java @@ -73,4 +73,16 @@ public class SendSticker { public String getStickerName() { return stickerName; } + + @Override + public String toString() { + return "SendSticker{" + + "chatId='" + chatId + '\'' + + ", sticker='" + sticker + '\'' + + ", replayToMessageId=" + replayToMessageId + + ", replayMarkup=" + replayMarkup + + ", isNewSticker=" + isNewSticker + + ", stickerName='" + stickerName + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendVideo.java b/src/main/java/org/telegram/telegrambots/api/methods/SendVideo.java index ed573603..5b629426 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendVideo.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendVideo.java @@ -95,4 +95,18 @@ public class SendVideo { this.isNewVideo = true; this.videoName = videoName; } + + @Override + public String toString() { + return "SendVideo{" + + "chatId='" + chatId + '\'' + + ", video='" + video + '\'' + + ", duration=" + duration + + ", caption='" + caption + '\'' + + ", replayToMessageId=" + replayToMessageId + + ", replayMarkup=" + replayMarkup + + ", isNewVideo=" + isNewVideo + + ", videoName='" + videoName + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendVoice.java b/src/main/java/org/telegram/telegrambots/api/methods/SendVoice.java index 2dfca578..c8d0aafc 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendVoice.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendVoice.java @@ -28,4 +28,15 @@ public class SendVoice { public SendVoice() { super(); } + + @Override + public String toString() { + return "SendVoice{" + + "chatId='" + chatId + '\'' + + ", audio='" + audio + '\'' + + ", replayToMessageId=" + replayToMessageId + + ", replayMarkup=" + replayMarkup + + ", duration=" + duration + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SetWebhook.java b/src/main/java/org/telegram/telegrambots/api/methods/SetWebhook.java index 5cba2975..46f05549 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SetWebhook.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SetWebhook.java @@ -36,4 +36,12 @@ public class SetWebhook { public void setCertificateFile(String certificateFile) { this.certificateFile = certificateFile; } + + @Override + public String toString() { + return "SetWebhook{" + + "url='" + url + '\'' + + ", certificateFile='" + certificateFile + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Audio.java b/src/main/java/org/telegram/telegrambots/api/objects/Audio.java index a21adaed..bdafd217 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Audio.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Audio.java @@ -131,4 +131,16 @@ public class Audio implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "Audio{" + + "fileId='" + fileId + '\'' + + ", duration=" + duration + + ", mimeType='" + mimeType + '\'' + + ", fileSize=" + fileSize + + ", title='" + title + '\'' + + ", performer='" + performer + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Chat.java b/src/main/java/org/telegram/telegrambots/api/objects/Chat.java index dbf68921..6776b0b2 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Chat.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Chat.java @@ -126,4 +126,16 @@ public class Chat implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "Chat{" + + "id=" + id + + ", type='" + type + '\'' + + ", title='" + title + '\'' + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + ", userName='" + userName + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/ChosenInlineQuery.java b/src/main/java/org/telegram/telegrambots/api/objects/ChosenInlineQuery.java index aecca51a..8ea998e9 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/ChosenInlineQuery.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/ChosenInlineQuery.java @@ -63,4 +63,13 @@ public class ChosenInlineQuery implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "ChosenInlineQuery{" + + "resultId='" + resultId + '\'' + + ", from=" + from + + ", query='" + query + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Contact.java b/src/main/java/org/telegram/telegrambots/api/objects/Contact.java index 7fc381a6..1636be34 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Contact.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Contact.java @@ -65,4 +65,14 @@ public class Contact implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "Contact{" + + "phoneNumber='" + phoneNumber + '\'' + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + ", userID=" + userID + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Document.java b/src/main/java/org/telegram/telegrambots/api/objects/Document.java index b562fd4d..78a21b33 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Document.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Document.java @@ -116,4 +116,15 @@ public class Document implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "Document{" + + "fileId='" + fileId + '\'' + + ", thumb=" + thumb + + ", fileName='" + fileName + '\'' + + ", mimeType='" + mimeType + '\'' + + ", fileSize=" + fileSize + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/File.java b/src/main/java/org/telegram/telegrambots/api/objects/File.java index 367f71f4..9176b143 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/File.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/File.java @@ -83,4 +83,13 @@ public class File implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "File{" + + "fileId='" + fileId + '\'' + + ", fileSize=" + fileSize + + ", filePath='" + filePath + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/ForceReplyKeyboard.java b/src/main/java/org/telegram/telegrambots/api/objects/ForceReplyKeyboard.java index ced0d9c5..18149d9a 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/ForceReplyKeyboard.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/ForceReplyKeyboard.java @@ -91,4 +91,12 @@ public class ForceReplyKeyboard implements ReplyKeyboard { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "ForceReplyKeyboard{" + + "forceReply=" + forceReply + + ", selective=" + selective + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/InlineQuery.java b/src/main/java/org/telegram/telegrambots/api/objects/InlineQuery.java index b0d44a69..afd5a693 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/InlineQuery.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/InlineQuery.java @@ -73,4 +73,15 @@ public class InlineQuery implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "InlineQuery{" + + "id='" + id + '\'' + + ", from=" + from + + ", query='" + query + '\'' + + ", offset='" + offset + '\'' + + '}'; + } } + diff --git a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultArticle.java b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultArticle.java index e3ec0503..efdd61bf 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultArticle.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultArticle.java @@ -238,4 +238,22 @@ public class InlineQueryResultArticle implements InlineQueryResult { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "InlineQueryResultArticle{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", title='" + title + '\'' + + ", messageText='" + messageText + '\'' + + ", parseMode='" + parseMode + '\'' + + ", disableWebPagePreview=" + disableWebPagePreview + + ", url='" + url + '\'' + + ", hideUrl=" + hideUrl + + ", description='" + description + '\'' + + ", thumbUrl='" + thumbUrl + '\'' + + ", thumbWidth=" + thumbWidth + + ", thumbHeight=" + thumbHeight + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultGif.java b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultGif.java index 168ae778..3e8b7849 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultGif.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultGif.java @@ -222,4 +222,21 @@ public class InlineQueryResultGif implements InlineQueryResult { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "InlineQueryResultGif{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", gifUrl='" + gifUrl + '\'' + + ", gifWidth=" + gifWidth + + ", gifHeight=" + gifHeight + + ", thumbUrl='" + thumbUrl + '\'' + + ", title='" + title + '\'' + + ", caption='" + caption + '\'' + + ", messageText='" + messageText + '\'' + + ", parseMode='" + parseMode + '\'' + + ", disableWebPagePreview=" + disableWebPagePreview + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultMpeg4Gif.java b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultMpeg4Gif.java index f7fd2f36..5edd936d 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultMpeg4Gif.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultMpeg4Gif.java @@ -223,4 +223,21 @@ public class InlineQueryResultMpeg4Gif implements InlineQueryResult { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "InlineQueryResultMpeg4Gif{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", mpeg4Url='" + mpeg4Url + '\'' + + ", mpeg4Width=" + mpeg4Width + + ", mpeg4Height=" + mpeg4Height + + ", thumbUrl='" + thumbUrl + '\'' + + ", title='" + title + '\'' + + ", caption='" + caption + '\'' + + ", messageText='" + messageText + '\'' + + ", parseMode='" + parseMode + '\'' + + ", disableWebPagePreview=" + disableWebPagePreview + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultPhoto.java b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultPhoto.java index 835dfd7c..4c9b7418 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultPhoto.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultPhoto.java @@ -258,4 +258,23 @@ public class InlineQueryResultPhoto implements InlineQueryResult { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "InlineQueryResultPhoto{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", photoUrl='" + photoUrl + '\'' + + ", mimeType='" + mimeType + '\'' + + ", photoWidth=" + photoWidth + + ", photoHeight=" + photoHeight + + ", thumbUrl='" + thumbUrl + '\'' + + ", title='" + title + '\'' + + ", description='" + description + '\'' + + ", caption='" + caption + '\'' + + ", messageText='" + messageText + '\'' + + ", parseMode='" + parseMode + '\'' + + ", disableWebPagePreview=" + disableWebPagePreview + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultVideo.java b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultVideo.java index 28cc7461..7da6f79c 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultVideo.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/InlineQueryResultVideo.java @@ -254,4 +254,23 @@ public class InlineQueryResultVideo implements InlineQueryResult { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "InlineQueryResultVideo{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", mimeType='" + mimeType + '\'' + + ", videoUrl='" + videoUrl + '\'' + + ", videoWidth=" + videoWidth + + ", videoHeight=" + videoHeight + + ", videoDuration=" + videoDuration + + ", thumbUrl='" + thumbUrl + '\'' + + ", title='" + title + '\'' + + ", description='" + description + '\'' + + ", messageText='" + messageText + '\'' + + ", parseMode='" + parseMode + '\'' + + ", disableWebPagePreview=" + disableWebPagePreview + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Location.java b/src/main/java/org/telegram/telegrambots/api/objects/Location.java index 14d1b3b1..c59f963d 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Location.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Location.java @@ -63,4 +63,12 @@ public class Location implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "Location{" + + "longitude=" + longitude + + ", latitude=" + latitude + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Message.java b/src/main/java/org/telegram/telegrambots/api/objects/Message.java index 8fa6f5d8..443bcabf 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Message.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Message.java @@ -525,4 +525,36 @@ public class Message implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "Message{" + + "messageId=" + messageId + + ", from=" + from + + ", date=" + date + + ", chat=" + chat + + ", forwardFrom=" + forwardFrom + + ", forwardDate=" + forwardDate + + ", text='" + text + '\'' + + ", audio=" + audio + + ", document=" + document + + ", photo=" + photo + + ", sticker=" + sticker + + ", video=" + video + + ", contact=" + contact + + ", location=" + location + + ", newChatParticipant=" + newChatParticipant + + ", leftChatParticipant=" + leftChatParticipant + + ", newChatTitle='" + newChatTitle + '\'' + + ", newChatPhoto=" + newChatPhoto + + ", deleteChatPhoto=" + deleteChatPhoto + + ", groupchatCreated=" + groupchatCreated + + ", replyToMessage=" + replyToMessage + + ", voice=" + voice + + ", superGroupCreated=" + superGroupCreated + + ", channelChatCreated=" + channelChatCreated + + ", migrateToChatId=" + migrateToChatId + + ", migrateFromChatId=" + migrateFromChatId + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/PhotoSize.java b/src/main/java/org/telegram/telegrambots/api/objects/PhotoSize.java index b7869434..5f2be519 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/PhotoSize.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/PhotoSize.java @@ -93,4 +93,14 @@ public class PhotoSize implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "PhotoSize{" + + "fileId='" + fileId + '\'' + + ", width=" + width + + ", height=" + height + + ", fileSize=" + fileSize + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardHide.java b/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardHide.java index dd7b81c0..9b370618 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardHide.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardHide.java @@ -85,4 +85,12 @@ public class ReplyKeyboardHide implements ReplyKeyboard { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "ReplyKeyboardHide{" + + "hideKeyboard=" + hideKeyboard + + ", selective=" + selective + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardMarkup.java b/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardMarkup.java index 4277d159..e268566e 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardMarkup.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardMarkup.java @@ -153,4 +153,14 @@ public class ReplyKeyboardMarkup implements ReplyKeyboard { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "ReplyKeyboardMarkup{" + + "keyboard=" + keyboard + + ", resizeKeyboard=" + resizeKeyboard + + ", oneTimeKeyboad=" + oneTimeKeyboad + + ", selective=" + selective + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Sticker.java b/src/main/java/org/telegram/telegrambots/api/objects/Sticker.java index 0505fc95..2a76a5de 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Sticker.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Sticker.java @@ -70,4 +70,15 @@ public class Sticker implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "Sticker{" + + "fileId='" + fileId + '\'' + + ", width=" + width + + ", height=" + height + + ", thumb=" + thumb + + ", fileSize=" + fileSize + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Update.java b/src/main/java/org/telegram/telegrambots/api/objects/Update.java index 3c111d14..a3992945 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Update.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Update.java @@ -101,4 +101,14 @@ public class Update implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "Update{" + + "updateId=" + updateId + + ", message=" + message + + ", inlineQuery=" + inlineQuery + + ", chosenInlineQuery=" + chosenInlineQuery + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/User.java b/src/main/java/org/telegram/telegrambots/api/objects/User.java index 6a5a3918..c7920f4d 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/User.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/User.java @@ -81,4 +81,14 @@ public class User implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + ", userName='" + userName + '\'' + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/UserProfilePhotos.java b/src/main/java/org/telegram/telegrambots/api/objects/UserProfilePhotos.java index 541900aa..5d680abb 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/UserProfilePhotos.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/UserProfilePhotos.java @@ -87,4 +87,12 @@ public class UserProfilePhotos implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "UserProfilePhotos{" + + "totalCount=" + totalCount + + ", photos=" + photos + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Video.java b/src/main/java/org/telegram/telegrambots/api/objects/Video.java index 34816083..0a741909 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Video.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Video.java @@ -139,4 +139,17 @@ public class Video implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "Video{" + + "fileId='" + fileId + '\'' + + ", width=" + width + + ", height=" + height + + ", duration=" + duration + + ", thumb=" + thumb + + ", mimeType='" + mimeType + '\'' + + ", fileSize=" + fileSize + + '}'; + } } diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Voice.java b/src/main/java/org/telegram/telegrambots/api/objects/Voice.java index bb5af2ef..4d695356 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Voice.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Voice.java @@ -96,4 +96,14 @@ public class Voice implements IBotApiObject { public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws IOException { serialize(gen, serializers); } + + @Override + public String toString() { + return "Voice{" + + "fileId='" + fileId + '\'' + + ", duration=" + duration + + ", mimeType='" + mimeType + '\'' + + ", fileSize=" + fileSize + + '}'; + } } From 5950bbd94ba928351a95398c92444324e3cda49d Mon Sep 17 00:00:00 2001 From: flicus Date: Fri, 11 Mar 2016 14:27:24 +0300 Subject: [PATCH 05/19] added possibility to work via HTTP proxy --- .../telegrambots/TelegramBotsApi.java | 10 +++++ .../api/TelegramApiConfiguration.java | 32 ++++++++++++++++ .../telegram/telegrambots/bots/AbsSender.java | 38 +++++++++++++++++++ .../updatesreceivers/UpdatesThread.java | 9 +++++ 4 files changed, 89 insertions(+) create mode 100644 src/main/java/org/telegram/telegrambots/api/TelegramApiConfiguration.java diff --git a/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java b/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java index e0aeef53..7d20995d 100644 --- a/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java +++ b/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java @@ -1,6 +1,8 @@ package org.telegram.telegrambots; import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.NoopHostnameVerifier; @@ -13,6 +15,7 @@ import org.apache.http.util.EntityUtils; import org.json.JSONException; import org.json.JSONObject; import org.telegram.telegrambots.api.Constants; +import org.telegram.telegrambots.api.TelegramApiConfiguration; import org.telegram.telegrambots.api.methods.SetWebhook; import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.bots.TelegramWebhookBot; @@ -137,6 +140,13 @@ public class TelegramBotsApi { String url = Constants.BASEURL + botToken + "/" + SetWebhook.PATH; HttpPost httppost = new HttpPost(url); + if (TelegramApiConfiguration.getInstance().getProxy() != null) { + RequestConfig requestConfig = RequestConfig.custom() + .setProxy(TelegramApiConfiguration.getInstance().getProxy()) + .build(); + httppost.setConfig(requestConfig); + } + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody(SetWebhook.URL_FIELD, webHookURL); if (publicCertificatePath != null) { diff --git a/src/main/java/org/telegram/telegrambots/api/TelegramApiConfiguration.java b/src/main/java/org/telegram/telegrambots/api/TelegramApiConfiguration.java new file mode 100644 index 00000000..51ddcd33 --- /dev/null +++ b/src/main/java/org/telegram/telegrambots/api/TelegramApiConfiguration.java @@ -0,0 +1,32 @@ +package org.telegram.telegrambots.api; + +import org.apache.http.HttpHost; + +/** + * Created by Sergey Skoptsov (flicus@gmail.com) on 11.03.2016. + */ + +public class TelegramApiConfiguration { + + private HttpHost proxy = null; + + public static TelegramApiConfiguration getInstance() { + return Singleton.instance; + } + + public HttpHost getProxy() { + return proxy; + } + + public void setProxy(HttpHost proxy) { + this.proxy = proxy; + } + + public void setProxy(String host, int port, String scheme) { + this.proxy = new HttpHost(host, port, scheme); + } + + private static class Singleton { + public static TelegramApiConfiguration instance = new TelegramApiConfiguration(); + } +} diff --git a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java index 0779642c..55a07947 100644 --- a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java +++ b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java @@ -2,6 +2,7 @@ package org.telegram.telegrambots.bots; import org.apache.http.HttpEntity; import org.apache.http.NameValuePair; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; @@ -18,6 +19,7 @@ import org.apache.http.util.EntityUtils; import org.json.JSONObject; import org.telegram.telegrambots.TelegramApiException; import org.telegram.telegrambots.api.Constants; +import org.telegram.telegrambots.api.TelegramApiConfiguration; import org.telegram.telegrambots.api.methods.*; import org.telegram.telegrambots.api.objects.File; import org.telegram.telegrambots.api.objects.Message; @@ -185,6 +187,12 @@ public abstract class AbsSender { CloseableHttpClient httpClient = HttpClients.createDefault(); String url = getBaseUrl() + SendDocument.PATH; HttpPost httppost = new HttpPost(url); + if (TelegramApiConfiguration.getInstance().getProxy() != null) { + RequestConfig requestConfig = RequestConfig.custom() + .setProxy(TelegramApiConfiguration.getInstance().getProxy()) + .build(); + httppost.setConfig(requestConfig); + } if (sendDocument.isNewDocument()) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); @@ -233,6 +241,12 @@ public abstract class AbsSender { CloseableHttpClient httpClient = HttpClients.createDefault(); String url = getBaseUrl() + SendPhoto.PATH; HttpPost httppost = new HttpPost(url); + if (TelegramApiConfiguration.getInstance().getProxy() != null) { + RequestConfig requestConfig = RequestConfig.custom() + .setProxy(TelegramApiConfiguration.getInstance().getProxy()) + .build(); + httppost.setConfig(requestConfig); + } if (sendPhoto.isNewPhoto()) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); @@ -287,6 +301,12 @@ public abstract class AbsSender { CloseableHttpClient httpClient = HttpClients.createDefault(); String url = getBaseUrl() + SendVideo.PATH; HttpPost httppost = new HttpPost(url); + if (TelegramApiConfiguration.getInstance().getProxy() != null) { + RequestConfig requestConfig = RequestConfig.custom() + .setProxy(TelegramApiConfiguration.getInstance().getProxy()) + .build(); + httppost.setConfig(requestConfig); + } if (sendVideo.isNewVideo()) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); @@ -348,6 +368,12 @@ public abstract class AbsSender { CloseableHttpClient httpClient = HttpClients.createDefault(); String url = getBaseUrl() + SendSticker.PATH; HttpPost httppost = new HttpPost(url); + if (TelegramApiConfiguration.getInstance().getProxy() != null) { + RequestConfig requestConfig = RequestConfig.custom() + .setProxy(TelegramApiConfiguration.getInstance().getProxy()) + .build(); + httppost.setConfig(requestConfig); + } if (sendSticker.isNewSticker()) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); @@ -396,6 +422,12 @@ public abstract class AbsSender { CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); String url = getBaseUrl() + method.getPath(); HttpPost httppost = new HttpPost(url); + if (TelegramApiConfiguration.getInstance().getProxy() != null) { + RequestConfig requestConfig = RequestConfig.custom() + .setProxy(TelegramApiConfiguration.getInstance().getProxy()) + .build(); + httppost.setConfig(requestConfig); + } httppost.addHeader("charset", "UTF-8"); httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON)); CloseableHttpResponse response = httpclient.execute(httppost); @@ -420,6 +452,12 @@ public abstract class AbsSender { CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); String url = getBaseUrl() + method.getPath(); HttpPost httppost = new HttpPost(url); + if (TelegramApiConfiguration.getInstance().getProxy() != null) { + RequestConfig requestConfig = RequestConfig.custom() + .setProxy(TelegramApiConfiguration.getInstance().getProxy()) + .build(); + httppost.setConfig(requestConfig); + } httppost.addHeader("charset", "UTF-8"); httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON)); CloseableHttpResponse response = httpclient.execute(httppost); diff --git a/src/main/java/org/telegram/telegrambots/updatesreceivers/UpdatesThread.java b/src/main/java/org/telegram/telegrambots/updatesreceivers/UpdatesThread.java index 968a64ff..cd5ef184 100644 --- a/src/main/java/org/telegram/telegrambots/updatesreceivers/UpdatesThread.java +++ b/src/main/java/org/telegram/telegrambots/updatesreceivers/UpdatesThread.java @@ -1,7 +1,9 @@ package org.telegram.telegrambots.updatesreceivers; import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; import org.apache.http.HttpResponse; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.entity.BufferedHttpEntity; @@ -14,6 +16,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.telegram.telegrambots.api.Constants; +import org.telegram.telegrambots.api.TelegramApiConfiguration; import org.telegram.telegrambots.api.methods.GetUpdates; import org.telegram.telegrambots.api.objects.Update; import org.telegram.telegrambots.bots.ITelegramLongPollingBot; @@ -58,6 +61,12 @@ public class UpdatesThread { CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionTimeToLive(20, TimeUnit.SECONDS).build(); String url = Constants.BASEURL + token + "/" + GetUpdates.PATH; HttpPost httpPost = new HttpPost(url); + if (TelegramApiConfiguration.getInstance().getProxy() != null) { + RequestConfig requestConfig = RequestConfig.custom() + .setProxy(TelegramApiConfiguration.getInstance().getProxy()) + .build(); + httpPost.setConfig(requestConfig); + } try { httpPost.addHeader("charset", "UTF-8"); httpPost.setEntity(new StringEntity(request.toJson().toString(), ContentType.APPLICATION_JSON)); From dd4522d2fb2323b829572afed2e171e4ae3a51b0 Mon Sep 17 00:00:00 2001 From: flicus Date: Fri, 11 Mar 2016 14:38:52 +0300 Subject: [PATCH 06/19] added possibility to work via HTTP proxy --- .idea/compiler.xml | 8 ++++++++ .idea/misc.xml | 3 +++ TelegramBots.iml | 2 +- pom.xml | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 434b83aa..89d6b111 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -24,9 +24,17 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 3bb9901e..f46d96ae 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -50,6 +50,9 @@ \ No newline at end of file From 885791b9271a8d13c044f85073e342b0d69a5f0a Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Sat, 2 Apr 2016 18:20:49 +0200 Subject: [PATCH 16/19] Reformat and Rearrange --- .../telegrambots/TelegramBotsApi.java | 64 +++++++++---------- .../api/methods/AnswerInlineQuery.java | 9 +-- .../telegrambots/api/methods/GetFile.java | 1 + .../telegrambots/api/methods/GetMe.java | 1 + .../api/methods/GetUserProfilePhotos.java | 5 +- .../api/methods/SendChatAction.java | 3 +- .../telegrambots/api/objects/Audio.java | 11 ++-- .../telegrambots/api/objects/Chat.java | 14 ++-- .../api/objects/ChosenInlineQuery.java | 5 +- .../telegrambots/api/objects/Contact.java | 7 +- .../telegrambots/api/objects/Document.java | 9 +-- .../telegrambots/api/objects/File.java | 5 +- .../api/objects/ForceReplyKeyboard.java | 3 +- .../telegrambots/api/objects/InlineQuery.java | 7 +- .../telegrambots/api/objects/Location.java | 3 +- .../telegrambots/api/objects/Message.java | 51 +++++++-------- .../api/objects/ReplyKeyboardHide.java | 3 +- .../api/objects/ReplyKeyboardMarkup.java | 7 +- .../telegrambots/api/objects/Sticker.java | 9 +-- .../telegrambots/api/objects/Update.java | 7 +- .../telegrambots/api/objects/User.java | 7 +- .../api/objects/UserProfilePhotos.java | 3 +- .../telegrambots/api/objects/Video.java | 13 ++-- .../telegrambots/api/objects/Voice.java | 7 +- .../telegram/telegrambots/bots/AbsSender.java | 2 +- 25 files changed, 138 insertions(+), 118 deletions(-) diff --git a/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java b/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java index f9569ec4..1a2bd37b 100644 --- a/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java +++ b/src/main/java/org/telegram/telegrambots/TelegramBotsApi.java @@ -1,8 +1,6 @@ package org.telegram.telegrambots; import org.apache.http.HttpEntity; -import org.apache.http.HttpHost; -import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.NoopHostnameVerifier; @@ -82,37 +80,6 @@ public class TelegramBotsApi { webhook.startServer(); } - /** - * - * @param bot - */ - public void registerBot(TelegramLongPollingBot bot) throws TelegramApiException { - setWebhook(bot.getBotToken()); - new UpdatesThread(bot.getBotToken(), bot); - } - - /** - * - * @param bot - */ - public void registerBot(TelegramWebhookBot bot) throws TelegramApiException { - if (useWebhook) { - webhook.registerWebhook(bot); - setWebhook(bot.getBotToken()); - } - } - - /** - * - * @param botToken - */ - private void setWebhook(String botToken) throws TelegramApiException { - if (botToken == null) { - throw new TelegramApiException("Parameter botToken can not be null"); - } - setWebhook(extrenalUrl == null ? "" : extrenalUrl, botToken, pathToCertificate, publicCertificateName); - } - /** * * @param externalUrl @@ -160,4 +127,35 @@ public class TelegramBotsApi { throw new TelegramApiException("Error executing setWebook method", e); } } + + /** + * + * @param bot + */ + public void registerBot(TelegramLongPollingBot bot) throws TelegramApiException { + setWebhook(bot.getBotToken()); + new UpdatesThread(bot.getBotToken(), bot); + } + + /** + * + * @param bot + */ + public void registerBot(TelegramWebhookBot bot) throws TelegramApiException { + if (useWebhook) { + webhook.registerWebhook(bot); + setWebhook(bot.getBotToken()); + } + } + + /** + * + * @param botToken + */ + private void setWebhook(String botToken) throws TelegramApiException { + if (botToken == null) { + throw new TelegramApiException("Parameter botToken can not be null"); + } + setWebhook(extrenalUrl == null ? "" : extrenalUrl, botToken, pathToCertificate, publicCertificateName); + } } diff --git a/src/main/java/org/telegram/telegrambots/api/methods/AnswerInlineQuery.java b/src/main/java/org/telegram/telegrambots/api/methods/AnswerInlineQuery.java index 8d37d3f5..865e64c1 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/AnswerInlineQuery.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/AnswerInlineQuery.java @@ -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.JSONArray; import org.json.JSONObject; import org.telegram.telegrambots.api.objects.InlineQueryResult; @@ -20,14 +21,14 @@ public class AnswerInlineQuery extends BotApiMethod { public static final String PATH = "answerInlineQuery"; public static final String INLINEQUERYID_FIELD = "inline_query_id"; - private String inlineQueryId; ///< Unique identifier for answered query public static final String RESULTS_FIELD = "results"; - private List results; ///< A JSON-serialized array of results for the inline query public static final String CACHETIME_FIELD = "cache_time"; - private Integer cacheTime; ///< Optional The maximum amount of time the result of the inline query may be cached on the server public static final String ISPERSONAL_FIELD = "is_personal"; - private Boolean isPersonal; ///< Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query public static final String NEXTOFFSET_FIELD = "next_offset"; + private String inlineQueryId; ///< Unique identifier for answered query + private List results; ///< A JSON-serialized array of results for the inline query + private Integer cacheTime; ///< Optional The maximum amount of time the result of the inline query may be cached on the server + private Boolean isPersonal; ///< Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query private String nextOffset; ///< Optional Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes. public AnswerInlineQuery() { diff --git a/src/main/java/org/telegram/telegrambots/api/methods/GetFile.java b/src/main/java/org/telegram/telegrambots/api/methods/GetFile.java index 3c2df8ef..53520a0d 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/GetFile.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/GetFile.java @@ -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.File; diff --git a/src/main/java/org/telegram/telegrambots/api/methods/GetMe.java b/src/main/java/org/telegram/telegrambots/api/methods/GetMe.java index a9f025b1..1fe159a0 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/GetMe.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/GetMe.java @@ -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.User; diff --git a/src/main/java/org/telegram/telegrambots/api/methods/GetUserProfilePhotos.java b/src/main/java/org/telegram/telegrambots/api/methods/GetUserProfilePhotos.java index 45490c74..c626a266 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/GetUserProfilePhotos.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/GetUserProfilePhotos.java @@ -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.UserProfilePhotos; @@ -18,13 +19,13 @@ public class GetUserProfilePhotos extends BotApiMethod { public static final String PATH = "getuserprofilephotos"; public static final String USERID_FIELD = "user_id"; - private Integer userId; ///< Unique identifier of the target user public static final String OFFSET_FIELD = "offset"; + public static final String LIMIT_FIELD = "limit"; + private Integer userId; ///< Unique identifier of the target user /** * Sequential number of the first photo to be returned. By default, all photos are returned. */ private Integer offset; - public static final String LIMIT_FIELD = "limit"; /** * Optional. Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100. */ diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendChatAction.java b/src/main/java/org/telegram/telegrambots/api/methods/SendChatAction.java index ac168d81..e78dec18 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendChatAction.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendChatAction.java @@ -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 java.io.IOException; @@ -20,8 +21,8 @@ public class SendChatAction extends BotApiMethod{ public static final String PATH = "sendChatAction"; public static final String CHATID_FIELD = "chat_id"; - private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) public static final String ACTION_FIELD = "action"; + private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels) /** * Type of action to broadcast. * Choose one, depending on what the user is about to receive: diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Audio.java b/src/main/java/org/telegram/telegrambots/api/objects/Audio.java index bdafd217..d596f5f4 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Audio.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Audio.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -18,21 +19,21 @@ import java.io.IOException; public class Audio implements IBotApiObject { public static final String FILEID_FIELD = "file_id"; + public static final String DURATION_FIELD = "duration"; + public static final String MIMETYPE_FIELD = "mime_type"; + public static final String FILESIZE_FIELD = "file_size"; + public static final String TITLE_FIELD = "title"; + public static final String PERFORMER_FIELD = "performer"; @JsonProperty(FILEID_FIELD) private String fileId; ///< Unique identifier for this file - public static final String DURATION_FIELD = "duration"; @JsonProperty(DURATION_FIELD) private Integer duration; ///< Integer Duration of the audio in seconds as defined by sender - public static final String MIMETYPE_FIELD = "mime_type"; @JsonProperty(MIMETYPE_FIELD) private String mimeType; ///< Optional. MIME type of the file as defined by sender - public static final String FILESIZE_FIELD = "file_size"; @JsonProperty(FILESIZE_FIELD) private Integer fileSize; ///< Optional. File size - public static final String TITLE_FIELD = "title"; @JsonProperty(TITLE_FIELD) private String title; ///< Optional. Title of the audio as defined by sender or by audio tags - public static final String PERFORMER_FIELD = "performer"; @JsonProperty(PERFORMER_FIELD) private String performer; ///< Optional. Performer of the audio as defined by sender or by audio tags diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Chat.java b/src/main/java/org/telegram/telegrambots/api/objects/Chat.java index 6776b0b2..c969f24f 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Chat.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Chat.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -16,27 +17,26 @@ import java.io.IOException; * @date 24 of June of 2015 */ public class Chat implements IBotApiObject { + public static final String ID_FIELD = "id"; + public static final String TYPE_FIELD = "type"; + public static final String TITLE_FIELD = "title"; + public static final String FIRSTNAME_FIELD = "first_name"; + public static final String LASTNAME_FIELD = "last_name"; + public static final String USERNAME_FIELD = "username"; private static final String USERCHATTYPE = "private"; private static final String GROUPCHATTYPE = "group"; private static final String CHANNELCHATTYPE = "channel"; private static final String SUPERGROUPCHATTYPE = "supergroup"; - - public static final String ID_FIELD = "id"; @JsonProperty(ID_FIELD) private Long id; ///< Unique identifier for this chat, not exciding 1e13 by absolute value - public static final String TYPE_FIELD = "type"; @JsonProperty(TYPE_FIELD) private String type; ///< Type of the chat, one of “private”, “group” or “channel” - public static final String TITLE_FIELD = "title"; @JsonProperty(TITLE_FIELD) private String title; ///< Optional. Title of the chat, only for channels and group chat - public static final String FIRSTNAME_FIELD = "first_name"; @JsonProperty(FIRSTNAME_FIELD) private String firstName; ///< Optional. Username of the chat, only for private chats and channels if available - public static final String LASTNAME_FIELD = "last_name"; @JsonProperty(LASTNAME_FIELD) private String lastName; ///< Optional. Interlocutor's first name for private chats - public static final String USERNAME_FIELD = "username"; @JsonProperty(USERNAME_FIELD) private String userName; ///< Optional. Interlocutor's last name for private chats diff --git a/src/main/java/org/telegram/telegrambots/api/objects/ChosenInlineQuery.java b/src/main/java/org/telegram/telegrambots/api/objects/ChosenInlineQuery.java index 8ea998e9..0265e533 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/ChosenInlineQuery.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/ChosenInlineQuery.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -17,12 +18,12 @@ import java.io.IOException; */ public class ChosenInlineQuery implements IBotApiObject { public static final String RESULTID_FIELD = "id"; + public static final String FROM_FIELD = "from"; + public static final String QUERY_FIELD = "query"; @JsonProperty(RESULTID_FIELD) private String resultId; ///< The unique identifier for the result that was chosen. - public static final String FROM_FIELD = "from"; @JsonProperty(FROM_FIELD) private User from; ///< The user that chose the result. - public static final String QUERY_FIELD = "query"; @JsonProperty(QUERY_FIELD) private String query; ///< The query that was used to obtain the result. diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Contact.java b/src/main/java/org/telegram/telegrambots/api/objects/Contact.java index 1636be34..bee4d1c8 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Contact.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Contact.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -18,15 +19,15 @@ import java.io.IOException; public class Contact implements IBotApiObject { public static final String PHONENUMBER_FIELD = "phone_number"; + public static final String FIRSTNAME_FIELD = "first_name"; + public static final String LASTNAME_FIELD = "last_name"; + public static final String USERID_FIELD = "user_id"; @JsonProperty(PHONENUMBER_FIELD) private String phoneNumber; ///< Contact's phone number - public static final String FIRSTNAME_FIELD = "first_name"; @JsonProperty(FIRSTNAME_FIELD) private String firstName; ///< Contact's first name - public static final String LASTNAME_FIELD = "last_name"; @JsonProperty(LASTNAME_FIELD) private String lastName; ///< Optional. Contact's last name - public static final String USERID_FIELD = "user_id"; @JsonProperty(USERID_FIELD) private Integer userID; ///< Optional. Contact's user identifier in Telegram diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Document.java b/src/main/java/org/telegram/telegrambots/api/objects/Document.java index 78a21b33..ac99134e 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Document.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Document.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -19,18 +20,18 @@ import java.io.IOException; public class Document implements IBotApiObject { public static final String FILEID_FIELD = "file_id"; + public static final String THUMB_FIELD = "thumb"; + public static final String FILENAME_FIELD = "file_name"; + public static final String MIMETYPE_FIELD = "mime_type"; + public static final String FILESIZE_FIELD = "file_size"; @JsonProperty(FILEID_FIELD) private String fileId; ///< Unique identifier for this file - public static final String THUMB_FIELD = "thumb"; @JsonProperty(THUMB_FIELD) private PhotoSize thumb; ///< Document thumbnail as defined by sender - public static final String FILENAME_FIELD = "file_name"; @JsonProperty(FILENAME_FIELD) private String fileName; ///< Optional. Original filename as defined by sender - public static final String MIMETYPE_FIELD = "mime_type"; @JsonProperty(MIMETYPE_FIELD) private String mimeType; ///< Optional. Mime type of a file as defined by sender - public static final String FILESIZE_FIELD = "file_size"; @JsonProperty(FILESIZE_FIELD) private Integer fileSize; ///< Optional. File size diff --git a/src/main/java/org/telegram/telegrambots/api/objects/File.java b/src/main/java/org/telegram/telegrambots/api/objects/File.java index 5440b0ce..8fb48f37 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/File.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/File.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -17,12 +18,12 @@ import java.io.IOException; */ public class File implements IBotApiObject { public static final String FILE_ID = "file_id"; + public static final String FILE_SIZE_FIELD = "file_size"; + public static final String FILE_PATH_FIELD = "file_path"; @JsonProperty(FILE_ID) private String fileId; ///< Unique identifier for this file - public static final String FILE_SIZE_FIELD = "file_size"; @JsonProperty(FILE_SIZE_FIELD) private Integer fileSize; ///< Optional. File size, if known - public static final String FILE_PATH_FIELD = "file_path"; @JsonProperty(FILE_PATH_FIELD) private String filePath; ///< Optional. File path. Use https://api.telegram.org/file/bot/ to get the file. diff --git a/src/main/java/org/telegram/telegrambots/api/objects/ForceReplyKeyboard.java b/src/main/java/org/telegram/telegrambots/api/objects/ForceReplyKeyboard.java index 18149d9a..442c84d6 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/ForceReplyKeyboard.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/ForceReplyKeyboard.java @@ -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; @@ -20,12 +21,12 @@ import java.io.IOException; public class ForceReplyKeyboard implements ReplyKeyboard { public static final String FORCEREPLY_FIELD = "force_reply"; + public static final String SELECTIVE_FIELD = "selective"; /** * Shows reply interface to the user, as if they manually selected the bot‘s message and tapped ’Reply' */ @JsonProperty(FORCEREPLY_FIELD) private Boolean forceReply; - public static final String SELECTIVE_FIELD = "selective"; /** * Use this parameter if you want to force reply from specific users only. * Targets: diff --git a/src/main/java/org/telegram/telegrambots/api/objects/InlineQuery.java b/src/main/java/org/telegram/telegrambots/api/objects/InlineQuery.java index afd5a693..13fe16ae 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/InlineQuery.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/InlineQuery.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -18,15 +19,15 @@ import java.io.IOException; */ public class InlineQuery implements IBotApiObject { public static final String ID_FIELD = "id"; + public static final String FROM_FIELD = "from"; + public static final String QUERY_FIELD = "query"; + public static final String OFFSET_FIELD = "offset"; @JsonProperty(ID_FIELD) private String id; ///< Unique identifier for this query - public static final String FROM_FIELD = "from"; @JsonProperty(FROM_FIELD) private User from; ///< Sender - public static final String QUERY_FIELD = "query"; @JsonProperty(QUERY_FIELD) private String query; ///< Text of the query - public static final String OFFSET_FIELD = "offset"; @JsonProperty(OFFSET_FIELD) private String offset; ///< Offset of the results to be returned, can be controlled by the bot diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Location.java b/src/main/java/org/telegram/telegrambots/api/objects/Location.java index c59f963d..a8944999 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Location.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Location.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -18,9 +19,9 @@ import java.io.IOException; public class Location implements IBotApiObject { public static final String LONGITUDE_FIELD = "longitude"; + public static final String LATITUDE_FIELD = "latitude"; @JsonProperty(LONGITUDE_FIELD) private Double longitude; ///< Longitude as defined by sender - public static final String LATITUDE_FIELD = "latitude"; @JsonProperty(LATITUDE_FIELD) private Double latitude; ///< Latitude as defined by sender diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Message.java b/src/main/java/org/telegram/telegrambots/api/objects/Message.java index 443bcabf..59f2e571 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Message.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Message.java @@ -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.JSONArray; import org.json.JSONObject; import org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -20,81 +21,81 @@ import java.util.List; */ public class Message implements IBotApiObject { public static final String MESSAGEID_FIELD = "message_id"; + public static final String FROM_FIELD = "from"; + public static final String DATE_FIELD = "date"; + public static final String CHAT_FIELD = "chat"; + public static final String FORWARDFROM_FIELD = "forward_from"; + public static final String FORWARDDATE_FIELD = "forward_date"; + public static final String TEXT_FIELD = "text"; + public static final String AUDIO_FIELD = "audio"; + public static final String DOCUMENT_FIELD = "document"; + public static final String PHOTO_FIELD = "photo"; + public static final String STICKER_FIELD = "sticker"; + public static final String VIDEO_FIELD = "video"; + public static final String CONTACT_FIELD = "contact"; + public static final String LOCATION_FIELD = "location"; + public static final String NEWCHATPARTICIPANT_FIELD = "new_chat_participant"; + public static final String LEFTCHATPARTICIPANT_FIELD = "left_chat_participant"; + public static final String NEWCHATTITLE_FIELD = "new_chat_title"; + public static final String NEWCHATPHOTO_FIELD = "new_chat_photo"; + public static final String DELETECHATPHOTO_FIELD = "delete_chat_photo"; + public static final String GROUPCHATCREATED_FIELD = "group_chat_created"; + public static final String REPLYTOMESSAGE_FIELD = "reply_to_message"; + public static final String VOICE_FIELD = "voice"; + public static final String SUPERGROUPCREATED_FIELD = "supergroup_chat_created"; + public static final String CHANNELCHATCREATED_FIELD = "channel_chat_created"; + public static final String MIGRATETOCHAT_FIELD = "migrate_to_chat_id"; + public static final String MIGRATEFROMCHAT_FIELD = "migrate_from_chat_id"; @JsonProperty(MESSAGEID_FIELD) private Integer messageId; ///< Integer Unique message identifier - public static final String FROM_FIELD = "from"; @JsonProperty(FROM_FIELD) private User from; ///< Optional. Sender, can be empty for messages sent to channels - public static final String DATE_FIELD = "date"; @JsonProperty(DATE_FIELD) private Integer date; ///< Date the message was sent in Unix time - public static final String CHAT_FIELD = "chat"; @JsonProperty(CHAT_FIELD) private Chat chat; ///< Conversation the message belongs to - public static final String FORWARDFROM_FIELD = "forward_from"; @JsonProperty(FORWARDFROM_FIELD) private User forwardFrom; ///< Optional. For forwarded messages, sender of the original message - public static final String FORWARDDATE_FIELD = "forward_date"; @JsonProperty(FORWARDDATE_FIELD) private Integer forwardDate; ///< Optional. For forwarded messages, date the original message was sent - public static final String TEXT_FIELD = "text"; @JsonProperty(TEXT_FIELD) private String text; ///< Optional. For text messages, the actual UTF-8 text of the message - public static final String AUDIO_FIELD = "audio"; @JsonProperty(AUDIO_FIELD) private Audio audio; ///< Optional. Message is an audio file, information about the file - public static final String DOCUMENT_FIELD = "document"; @JsonProperty(DOCUMENT_FIELD) private Document document; ///< Optional. Message is a general file, information about the file - public static final String PHOTO_FIELD = "photo"; @JsonProperty(PHOTO_FIELD) private List photo; ///< Optional. Message is a photo, available sizes of the photo - public static final String STICKER_FIELD = "sticker"; @JsonProperty(STICKER_FIELD) private Sticker sticker; ///< Optional. Message is a sticker, information about the sticker - public static final String VIDEO_FIELD = "video"; @JsonProperty(VIDEO_FIELD) private Video video; ///< Optional. Message is a video, information about the video - public static final String CONTACT_FIELD = "contact"; @JsonProperty(CONTACT_FIELD) private Contact contact; ///< Optional. Message is a shared contact, information about the contact - public static final String LOCATION_FIELD = "location"; @JsonProperty(LOCATION_FIELD) private Location location; ///< Optional. Message is a shared location, information about the location - public static final String NEWCHATPARTICIPANT_FIELD = "new_chat_participant"; @JsonProperty(NEWCHATPARTICIPANT_FIELD) private User newChatParticipant; ///< Optional. A new member was added to the group, information about them (this member may be bot itself) - public static final String LEFTCHATPARTICIPANT_FIELD = "left_chat_participant"; @JsonProperty(LEFTCHATPARTICIPANT_FIELD) private User leftChatParticipant; ///< Optional. A member was removed from the group, information about them (this member may be bot itself) - public static final String NEWCHATTITLE_FIELD = "new_chat_title"; @JsonProperty(NEWCHATTITLE_FIELD) private String newChatTitle; ///< Optional. A chat title was changed to this value - public static final String NEWCHATPHOTO_FIELD = "new_chat_photo"; @JsonProperty(NEWCHATPHOTO_FIELD) private List newChatPhoto; ///< Optional. A chat photo was change to this value - public static final String DELETECHATPHOTO_FIELD = "delete_chat_photo"; @JsonProperty(DELETECHATPHOTO_FIELD) private Boolean deleteChatPhoto; ///< Optional. Informs that the chat photo was deleted - public static final String GROUPCHATCREATED_FIELD = "group_chat_created"; @JsonProperty(GROUPCHATCREATED_FIELD) private Boolean groupchatCreated; ///< Optional. Informs that the group has been created - public static final String REPLYTOMESSAGE_FIELD = "reply_to_message"; @JsonProperty(REPLYTOMESSAGE_FIELD) private Message replyToMessage; - public static final String VOICE_FIELD = "voice"; @JsonProperty(VOICE_FIELD) private Voice voice; ///< Optional. Message is a voice message, information about the file - public static final String SUPERGROUPCREATED_FIELD = "supergroup_chat_created"; @JsonProperty(SUPERGROUPCREATED_FIELD) private Boolean superGroupCreated; ///< Optional. Informs that the supergroup has been created - public static final String CHANNELCHATCREATED_FIELD = "channel_chat_created"; @JsonProperty(CHANNELCHATCREATED_FIELD) private Boolean channelChatCreated; ///< Optional. Informs that the channel has been created - public static final String MIGRATETOCHAT_FIELD = "migrate_to_chat_id"; @JsonProperty(MIGRATETOCHAT_FIELD) private Long migrateToChatId; ///< Optional. The chat has been migrated to a chat with specified identifier, not exceeding 1e13 by absolute value - public static final String MIGRATEFROMCHAT_FIELD = "migrate_from_chat_id"; @JsonProperty(MIGRATEFROMCHAT_FIELD) private Long migrateFromChatId; ///< Optional. The chat has been migrated from a chat with specified identifier, not exceeding 1e13 by absolute value diff --git a/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardHide.java b/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardHide.java index 9b370618..3c4b6aed 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardHide.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardHide.java @@ -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; @@ -21,9 +22,9 @@ import java.io.IOException; public class ReplyKeyboardHide implements ReplyKeyboard { public static final String HIDEKEYBOARD_FIELD = "hide_keyboard"; + public static final String SELECTIVE_FIELD = "selective"; @JsonProperty(HIDEKEYBOARD_FIELD) private Boolean hideKeyboard; ///< Requests clients to hide the custom keyboard - public static final String SELECTIVE_FIELD = "selective"; /** * Optional. Use this parameter if you want to show the keyboard to specific users only. * Targets: diff --git a/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardMarkup.java b/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardMarkup.java index e268566e..846c9d45 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardMarkup.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/ReplyKeyboardMarkup.java @@ -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.JSONArray; import org.json.JSONObject; @@ -20,15 +21,15 @@ import java.util.List; public class ReplyKeyboardMarkup implements ReplyKeyboard { public static final String KEYBOARD_FIELD = "keyboard"; + public static final String RESIZEKEYBOARD_FIELD = "resize_keyboard"; + public static final String ONETIMEKEYBOARD_FIELD = "one_time_keyboard"; + public static final String SELECTIVE_FIELD = "selective"; @JsonProperty(KEYBOARD_FIELD) private List> keyboard; ///< Array of button rows, each represented by an Array of Strings - public static final String RESIZEKEYBOARD_FIELD = "resize_keyboard"; @JsonProperty(RESIZEKEYBOARD_FIELD) private Boolean resizeKeyboard; ///< Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false. - public static final String ONETIMEKEYBOARD_FIELD = "one_time_keyboard"; @JsonProperty(ONETIMEKEYBOARD_FIELD) private Boolean oneTimeKeyboad; ///< Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false. - public static final String SELECTIVE_FIELD = "selective"; /** * Optional. Use this parameter if you want to show the keyboard to specific users only. * Targets: diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Sticker.java b/src/main/java/org/telegram/telegrambots/api/objects/Sticker.java index 2a76a5de..b8a0a1d8 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Sticker.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Sticker.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -18,18 +19,18 @@ import java.io.IOException; public class Sticker implements IBotApiObject { public static final String FILEID_FIELD = "file_id"; + public static final String WIDTH_FIELD = "width"; + public static final String HEIGHT_FIELD = "height"; + public static final String THUMB_FIELD = "thumb"; + public static final String FILESIZE_FIELD = "file_size"; @JsonProperty(FILEID_FIELD) private String fileId; ///< Unique identifier for this file - public static final String WIDTH_FIELD = "width"; @JsonProperty(WIDTH_FIELD) private Integer width; ///< Sticker width - public static final String HEIGHT_FIELD = "height"; @JsonProperty(HEIGHT_FIELD) private Integer height; ///< Sticker height - public static final String THUMB_FIELD = "thumb"; @JsonProperty(THUMB_FIELD) private PhotoSize thumb; ///< Optional. Sticker thumbnail in .webp or .jpg format - public static final String FILESIZE_FIELD = "file_size"; @JsonProperty(FILESIZE_FIELD) private Integer fileSize; ///< Optional. File size diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Update.java b/src/main/java/org/telegram/telegrambots/api/objects/Update.java index a3992945..a766ed5f 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Update.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Update.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -18,15 +19,15 @@ import java.io.IOException; */ public class Update implements IBotApiObject { public static final String UPDATEID_FIELD = "update_id"; + public static final String MESSAGE_FIELD = "message"; + public static final String INLINEQUERY_FIELD = "inline_query"; + public static final String CHOSENINLINEQUERY_FIELD = "chosen_inline_result"; @JsonProperty(UPDATEID_FIELD) private Integer updateId; - public static final String MESSAGE_FIELD = "message"; @JsonProperty(MESSAGE_FIELD) private Message message; ///< Optional. New incoming message of any kind — text, photo, sticker, etc. - public static final String INLINEQUERY_FIELD = "inline_query"; @JsonProperty(INLINEQUERY_FIELD) private InlineQuery inlineQuery; ///< Optional. New incoming inline query - public static final String CHOSENINLINEQUERY_FIELD = "chosen_inline_result"; @JsonProperty(CHOSENINLINEQUERY_FIELD) private ChosenInlineQuery chosenInlineQuery; ///< Optional. The result of a inline query that was chosen by a user and sent to their chat partner diff --git a/src/main/java/org/telegram/telegrambots/api/objects/User.java b/src/main/java/org/telegram/telegrambots/api/objects/User.java index c7920f4d..57969237 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/User.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/User.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -18,15 +19,15 @@ import java.io.IOException; public class User implements IBotApiObject { public static final String ID_FIELD = "id"; + public static final String FIRSTNAME_FIELD = "first_name"; + public static final String LASTNAME_FIELD = "last_name"; + public static final String USERNAME_FIELD = "username"; @JsonProperty(ID_FIELD) private Integer id; ///< Unique identifier for this user or bot - public static final String FIRSTNAME_FIELD = "first_name"; @JsonProperty(FIRSTNAME_FIELD) private String firstName; ///< User‘s or bot’s first name - public static final String LASTNAME_FIELD = "last_name"; @JsonProperty(LASTNAME_FIELD) private String lastName; ///< Optional. User‘s or bot’s last name - public static final String USERNAME_FIELD = "username"; @JsonProperty(USERNAME_FIELD) private String userName; ///< Optional. User‘s or bot’s username diff --git a/src/main/java/org/telegram/telegrambots/api/objects/UserProfilePhotos.java b/src/main/java/org/telegram/telegrambots/api/objects/UserProfilePhotos.java index 5d680abb..c5551b7d 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/UserProfilePhotos.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/UserProfilePhotos.java @@ -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.JSONArray; import org.json.JSONObject; import org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -21,9 +22,9 @@ import java.util.List; public class UserProfilePhotos implements IBotApiObject { public static final String TOTALCOUNT_FIELD = "total_count"; + public static final String PHOTOS_FIELD = "photos"; @JsonProperty(TOTALCOUNT_FIELD) private Integer totalCount; ///< Total number of profile pictures the target user has - public static final String PHOTOS_FIELD = "photos"; @JsonProperty(PHOTOS_FIELD) private List> photos; ///< Requested profile pictures (in up to 4 sizes each) diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Video.java b/src/main/java/org/telegram/telegrambots/api/objects/Video.java index 0a741909..844a262e 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Video.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Video.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -18,24 +19,24 @@ import java.io.IOException; public class Video implements IBotApiObject { public static final String FILEID_FIELD = "file_id"; + public static final String WIDTH_FIELD = "width"; + public static final String HEIGHT_FIELD = "height"; + public static final String DURATION_FIELD = "duration"; + public static final String THUMB_FIELD = "thumb"; + public static final String MIMETYPE_FIELD = "mime_type"; + public static final String FILESIZE_FIELD = "file_size"; @JsonProperty(FILEID_FIELD) private String fileId; ///< Unique identifier for this file - public static final String WIDTH_FIELD = "width"; @JsonProperty(WIDTH_FIELD) private Integer width; ///< Video width as defined by sender - public static final String HEIGHT_FIELD = "height"; @JsonProperty(HEIGHT_FIELD) private Integer height; ///< Video height as defined by sender - public static final String DURATION_FIELD = "duration"; @JsonProperty(DURATION_FIELD) private Integer duration; ///< Duration of the video in seconds as defined by sender - public static final String THUMB_FIELD = "thumb"; @JsonProperty(THUMB_FIELD) private PhotoSize thumb; ///< Video thumbnail - public static final String MIMETYPE_FIELD = "mime_type"; @JsonProperty(MIMETYPE_FIELD) private String mimeType; ///< Optional. Mime type of a file as defined by sender - public static final String FILESIZE_FIELD = "file_size"; @JsonProperty(FILESIZE_FIELD) private Integer fileSize; ///< Optional. File size diff --git a/src/main/java/org/telegram/telegrambots/api/objects/Voice.java b/src/main/java/org/telegram/telegrambots/api/objects/Voice.java index 4d695356..ae82b653 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/Voice.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/Voice.java @@ -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 org.telegram.telegrambots.api.interfaces.IBotApiObject; @@ -17,15 +18,15 @@ import java.io.IOException; */ public class Voice implements IBotApiObject { public static final String FILEID_FIELD = "file_id"; + public static final String DURATION_FIELD = "duration"; + public static final String MIMETYPE_FIELD = "mime_type"; + public static final String FILESIZE_FIELD = "file_size"; @JsonProperty(FILEID_FIELD) private String fileId; ///< Unique identifier for this file - public static final String DURATION_FIELD = "duration"; @JsonProperty(DURATION_FIELD) private Integer duration; ///< Integer Duration of the audio in seconds as defined by sender - public static final String MIMETYPE_FIELD = "mime_type"; @JsonProperty(MIMETYPE_FIELD) private String mimeType; ///< Optional. MIME type of the file as defined by sender - public static final String FILESIZE_FIELD = "file_size"; @JsonProperty(FILESIZE_FIELD) private Integer fileSize; ///< Optional. File size diff --git a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java index 216d0003..ab9b0227 100644 --- a/src/main/java/org/telegram/telegrambots/bots/AbsSender.java +++ b/src/main/java/org/telegram/telegrambots/bots/AbsSender.java @@ -2,7 +2,6 @@ package org.telegram.telegrambots.bots; import org.apache.http.HttpEntity; import org.apache.http.NameValuePair; -import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; @@ -22,6 +21,7 @@ import org.telegram.telegrambots.api.Constants; import org.telegram.telegrambots.api.methods.AnswerInlineQuery; import org.telegram.telegrambots.api.methods.BotApiMethod; import org.telegram.telegrambots.api.methods.ForwardMessage; +import org.telegram.telegrambots.api.methods.GetFile; import org.telegram.telegrambots.api.methods.GetMe; import org.telegram.telegrambots.api.methods.GetUserProfilePhotos; import org.telegram.telegrambots.api.methods.SendAudio; From d00df14abaeeb3d55a96162de08de98530812ed8 Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Sat, 2 Apr 2016 18:45:04 +0200 Subject: [PATCH 17/19] Fix bug in ChosenInlineQuery Added JAR sources --- pom.xml | 16 ++++++++++++++-- .../api/objects/ChosenInlineQuery.java | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 66d69447..4d4aaadb 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ - 4.0.0 jar @@ -82,6 +82,18 @@ ${project.basedir}/src/main/java + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + org.apache.maven.plugins maven-jar-plugin diff --git a/src/main/java/org/telegram/telegrambots/api/objects/ChosenInlineQuery.java b/src/main/java/org/telegram/telegrambots/api/objects/ChosenInlineQuery.java index 0265e533..974aaea4 100644 --- a/src/main/java/org/telegram/telegrambots/api/objects/ChosenInlineQuery.java +++ b/src/main/java/org/telegram/telegrambots/api/objects/ChosenInlineQuery.java @@ -17,9 +17,10 @@ import java.io.IOException; * @date 01 of January of 2016 */ public class ChosenInlineQuery implements IBotApiObject { - public static final String RESULTID_FIELD = "id"; + public static final String RESULTID_FIELD = "result_id"; public static final String FROM_FIELD = "from"; public static final String QUERY_FIELD = "query"; + @JsonProperty(RESULTID_FIELD) private String resultId; ///< The unique identifier for the result that was chosen. @JsonProperty(FROM_FIELD) From 495b794687d29f63209e4519751c69fb82878446 Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Sat, 2 Apr 2016 18:45:39 +0200 Subject: [PATCH 18/19] Added Javadocs --- pom.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index 4d4aaadb..e127009e 100644 --- a/pom.xml +++ b/pom.xml @@ -94,6 +94,18 @@ + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + org.apache.maven.plugins maven-jar-plugin From 8f246c230666ef99b691f9e56ecd26addead070a Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Sat, 2 Apr 2016 18:54:00 +0200 Subject: [PATCH 19/19] Reformat --- .../telegrambots/api/methods/SendAudio.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java b/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java index 4e90fb8b..3ae4c837 100644 --- a/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java +++ b/src/main/java/org/telegram/telegrambots/api/methods/SendAudio.java @@ -18,15 +18,17 @@ public class SendAudio { public static final String PATH = "sendaudio"; public static final String DURATION_FIELD = "duration"; - private Integer duration; ///< Integer Duration of the audio in seconds as defined by sender - public static final String CHATID_FIELD = "chat_id"; - private String chatId; ///< Unique identifier for the chat to send the message to (or Username fro 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 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"; + public static final String REPLYMARKUP_FIELD = "reply_markup"; + public static final String PERFOMER_FIELD = "performer"; + public static final String TITLE_FIELD = "title"; + private Integer duration; ///< Integer Duration of the audio in seconds as defined by sender + private String chatId; ///< Unique identifier for the chat to send the message to (or Username fro channels) + private String audio; ///< Audio file to send. file_id as String to resend an audio that is already on the Telegram servers + private Integer replayToMessageId; ///< Optional. If the message is a reply, ID of the original message /** * Optional. Sends the message silently. * iOS users will not receive a notification, @@ -34,11 +36,8 @@ public class SendAudio { * 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"; private String performer; ///< Optional. Performer of sent audio - public static final String TITLE_FIELD = "title"; private String title; ///< Optional. Title of sent audio private boolean isNewAudio; private String audioName; @@ -47,14 +46,14 @@ public class SendAudio { super(); } - public void setDuration(Integer duration) { - this.duration = duration; - } - public Integer getDuration(){ return this.duration; } + public void setDuration(Integer duration) { + this.duration = duration; + } + public String getChatId() { return chatId; }