From 75c3a487663bb970803a7f1fdab14b6d1a8d9f6b Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Sun, 15 Jan 2017 03:21:57 +0100 Subject: [PATCH] Fix bug with editMessageXXXX methods (#187) --- README.md | 4 ++-- TelegramBots.wiki/Changelog.md | 7 ++++++- TelegramBots.wiki/Getting-Started.md | 4 ++-- TelegramBots.wiki/How-To-Update.md | 6 +++++- pom.xml | 4 ++-- telegrambots-meta/pom.xml | 2 +- .../updatingmessages/EditMessageCaption.java | 20 ++++++++++++++---- .../EditMessageReplyMarkup.java | 21 +++++++++++++++---- .../updatingmessages/EditMessageText.java | 20 ++++++++++++++---- .../telegram/telegrambots/bots/AbsSender.java | 12 +++++------ telegrambots/pom.xml | 4 ++-- 11 files changed, 75 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index bd0d968f..5a5071d1 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,8 @@ Just import add the library to your project with one of these options: ``` - 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/2.4.4.3) - 3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/2.4.4.3) + 2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/2.4.4.4) + 3. Download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/2.4.4.4) In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`. diff --git a/TelegramBots.wiki/Changelog.md b/TelegramBots.wiki/Changelog.md index 4974c335..36e8b8f3 100644 --- a/TelegramBots.wiki/Changelog.md +++ b/TelegramBots.wiki/Changelog.md @@ -29,4 +29,9 @@ 1. In `BotSession`, renamed `close` to `stop`. `Close` method is maintained for backward compatibility. 2. Support crating webhook with HTTP servers (HTTPS must be managed via external tools) -**[[How to update to version 2.4.4.3|How-To-Update#2.4.4.3]]** \ No newline at end of file +**[[How to update to version 2.4.4.3|How-To-Update#2.4.4.3]]** + +### 2.4.4.4 ### +1. EditMessageText, EditMessageCaption and EditMessageReplyMarkup now return a `Serializable` object that can be `Boolean` or `Message` + +**[[How to update to version 2.4.4.4|How-To-Update#2.4.4.4]]** \ No newline at end of file diff --git a/TelegramBots.wiki/Getting-Started.md b/TelegramBots.wiki/Getting-Started.md index 47d76e47..cb9d6649 100644 --- a/TelegramBots.wiki/Getting-Started.md +++ b/TelegramBots.wiki/Getting-Started.md @@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss org.telegram telegrambots - 2.4.4.3 + 2.4.4.4 ``` * With **Gradle**: ```groovy - compile group: 'org.telegram', name: 'telegrambots', version: '2.4.4.3' + compile group: 'org.telegram', name: 'telegrambots', version: '2.4.4.4' ``` 2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots). diff --git a/TelegramBots.wiki/How-To-Update.md b/TelegramBots.wiki/How-To-Update.md index 399d7ac5..e0a82b2c 100644 --- a/TelegramBots.wiki/How-To-Update.md +++ b/TelegramBots.wiki/How-To-Update.md @@ -16,4 +16,8 @@ 3. Removed deprecated stuff from version 2.4.3 ### To version 2.4.4.3 ### -1. Replace `BotSession.close()` by `BotSession.stop()`. \ No newline at end of file +1. Replace `BotSession.close()` by `BotSession.stop()`. + +### To version 2.4.4.4 ### +1. All calls to `editMessageText`, `editMessageCaption` or `editMessageReplyMarkup` in `AbsSender` return value is changed to `Serializable` +2. In `editMessageTextAsync`, `editMessageCaptionAsync` or `editMessageReplyMarkupAsync` in `AbsSender`, second parameter should become `SentCallback` due to new return type. \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5c4788ee..04c7dc69 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.telegram Bots pom - 2.4.4.3 + 2.4.4.4 telegrambots @@ -24,6 +24,6 @@ true - 2.4.4.3 + 2.4.4.4 \ No newline at end of file diff --git a/telegrambots-meta/pom.xml b/telegrambots-meta/pom.xml index 02f72e0f..a3031f57 100644 --- a/telegrambots-meta/pom.xml +++ b/telegrambots-meta/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots-meta - 2.4.4.3 + 2.4.4.4 jar Telegram Bots Meta diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageCaption.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageCaption.java index f3d76aaf..cba6e216 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageCaption.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageCaption.java @@ -11,15 +11,16 @@ import org.telegram.telegrambots.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.exceptions.TelegramApiValidationException; import java.io.IOException; +import java.io.Serializable; /** * @author Ruben Bermudez * @version 1.0 * @brief Use this method to edit captions of messages sent by the bot or via the bot (for inline - * bots). On success, the edited Message is returned + * bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. * @date 10 of April of 2016 */ -public class EditMessageCaption extends BotApiMethod { +public class EditMessageCaption extends BotApiMethod { public static final String PATH = "editmessagecaption"; private static final String CHATID_FIELD = "chat_id"; @@ -104,7 +105,7 @@ public class EditMessageCaption extends BotApiMethod { } @Override - public Message deserializeResponse(String answer) throws TelegramApiRequestException { + public Serializable deserializeResponse(String answer) throws TelegramApiRequestException { try { ApiResponse result = OBJECT_MAPPER.readValue(answer, new TypeReference>(){}); @@ -114,7 +115,18 @@ public class EditMessageCaption extends BotApiMethod { throw new TelegramApiRequestException("Error editing message caption", result); } } catch (IOException e) { - throw new TelegramApiRequestException("Unable to deserialize response", e); + try { + ApiResponse result = OBJECT_MAPPER.readValue(answer, + new TypeReference>() { + }); + if (result.getOk()) { + return result.getResult(); + } else { + throw new TelegramApiRequestException("Error editing message caption", result); + } + } catch (IOException e2) { + throw new TelegramApiRequestException("Unable to deserialize response", e); + } } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageReplyMarkup.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageReplyMarkup.java index 0d8c8bef..f34e6748 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageReplyMarkup.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageReplyMarkup.java @@ -11,16 +11,18 @@ import org.telegram.telegrambots.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.exceptions.TelegramApiValidationException; import java.io.IOException; +import java.io.Serializable; import java.util.Objects; /** * @author Ruben Bermudez * @version 1.0 * @brief Use this method to edit only the reply markup of messages sent by the bot or via the bot - * (for inline bots). On success, the edited Message is returned. + * (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, + * therwise True is returned. * @date 10 of April of 2016 */ -public class EditMessageReplyMarkup extends BotApiMethod { +public class EditMessageReplyMarkup extends BotApiMethod { public static final String PATH = "editmessagereplymarkup"; private static final String CHATID_FIELD = "chat_id"; @@ -99,7 +101,7 @@ public class EditMessageReplyMarkup extends BotApiMethod { } @Override - public Message deserializeResponse(String answer) throws TelegramApiRequestException { + public Serializable deserializeResponse(String answer) throws TelegramApiRequestException { try { ApiResponse result = OBJECT_MAPPER.readValue(answer, new TypeReference>(){}); @@ -109,7 +111,18 @@ public class EditMessageReplyMarkup extends BotApiMethod { throw new TelegramApiRequestException("Error editing message reply markup", result); } } catch (IOException e) { - throw new TelegramApiRequestException("Unable to deserialize response", e); + try { + ApiResponse result = OBJECT_MAPPER.readValue(answer, + new TypeReference>() { + }); + if (result.getOk()) { + return result.getResult(); + } else { + throw new TelegramApiRequestException("Error editing message reply markup", result); + } + } catch (IOException e2) { + throw new TelegramApiRequestException("Unable to deserialize response", e); + } } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageText.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageText.java index debf64fb..b87ae198 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageText.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/updatingmessages/EditMessageText.java @@ -12,16 +12,17 @@ import org.telegram.telegrambots.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.exceptions.TelegramApiValidationException; import java.io.IOException; +import java.io.Serializable; import java.util.Objects; /** * @author Ruben Bermudez * @version 1.0 * @brief Use this method to edit text messages sent by the bot or via the bot (for inline bots). On - * success, the edited Message is returned. + * success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. * @date 10 of April of 2016 */ -public class EditMessageText extends BotApiMethod { +public class EditMessageText extends BotApiMethod { public static final String PATH = "editmessagetext"; private static final String CHATID_FIELD = "chat_id"; @@ -159,7 +160,7 @@ public class EditMessageText extends BotApiMethod { } @Override - public Message deserializeResponse(String answer) throws TelegramApiRequestException { + public Serializable deserializeResponse(String answer) throws TelegramApiRequestException { try { ApiResponse result = OBJECT_MAPPER.readValue(answer, new TypeReference>(){}); @@ -169,7 +170,18 @@ public class EditMessageText extends BotApiMethod { throw new TelegramApiRequestException("Error editing message text", result); } } catch (IOException e) { - throw new TelegramApiRequestException("Unable to deserialize response", e); + try { + ApiResponse result = OBJECT_MAPPER.readValue(answer, + new TypeReference>() { + }); + if (result.getOk()) { + return result.getResult(); + } else { + throw new TelegramApiRequestException("Error editing message text", result); + } + } catch (IOException e2) { + throw new TelegramApiRequestException("Unable to deserialize response", e); + } } } diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/bots/AbsSender.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/bots/AbsSender.java index a438dccd..51e194ec 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/bots/AbsSender.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/bots/AbsSender.java @@ -164,21 +164,21 @@ public abstract class AbsSender { return sendApiMethod(getChatMemberCount); } - public final Message editMessageText(EditMessageText editMessageText) throws TelegramApiException { + public final Serializable editMessageText(EditMessageText editMessageText) throws TelegramApiException { if (editMessageText == null) { throw new TelegramApiException("Parameter editMessageText can not be null"); } return sendApiMethod(editMessageText); } - public final Message editMessageCaption(EditMessageCaption editMessageCaption) throws TelegramApiException { + public final Serializable editMessageCaption(EditMessageCaption editMessageCaption) throws TelegramApiException { if (editMessageCaption == null) { throw new TelegramApiException("Parameter editMessageCaption can not be null"); } return sendApiMethod(editMessageCaption); } - public final Message editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup) throws TelegramApiException { + public final Serializable editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup) throws TelegramApiException { if (editMessageReplyMarkup == null) { throw new TelegramApiException("Parameter editMessageReplyMarkup can not be null"); } @@ -407,7 +407,7 @@ public abstract class AbsSender { sendApiMethodAsync(getChatMemberCount, sentCallback); } - public final void editMessageTextAsync(EditMessageText editMessageText, SentCallback sentCallback) throws TelegramApiException { + public final void editMessageTextAsync(EditMessageText editMessageText, SentCallback sentCallback) throws TelegramApiException { if (editMessageText == null) { throw new TelegramApiException("Parameter editMessageText can not be null"); } @@ -418,7 +418,7 @@ public abstract class AbsSender { sendApiMethodAsync(editMessageText, sentCallback); } - public final void editMessageCaptionAsync(EditMessageCaption editMessageCaption, SentCallback sentCallback) throws TelegramApiException { + public final void editMessageCaptionAsync(EditMessageCaption editMessageCaption, SentCallback sentCallback) throws TelegramApiException { if (editMessageCaption == null) { throw new TelegramApiException("Parameter editMessageCaption can not be null"); } @@ -429,7 +429,7 @@ public abstract class AbsSender { sendApiMethodAsync(editMessageCaption, sentCallback); } - public final void editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup, SentCallback sentCallback) throws TelegramApiException { + public final void editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup, SentCallback sentCallback) throws TelegramApiException { if (editMessageReplyMarkup == null) { throw new TelegramApiException("Parameter editMessageReplyMarkup can not be null"); } diff --git a/telegrambots/pom.xml b/telegrambots/pom.xml index 14af9c8f..df9d3462 100644 --- a/telegrambots/pom.xml +++ b/telegrambots/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.telegram telegrambots - 2.4.4.3 + 2.4.4.4 jar Telegram Bots @@ -65,7 +65,7 @@ 20160810 2.8.5 2.5 - 2.4.4.3 + 2.4.4.4