Fix bug with editMessageXXXX methods

(#187)
This commit is contained in:
Rubenlagus 2017-01-15 03:21:57 +01:00 committed by Ruben Bermudez
parent 20ec648c57
commit 75c3a48766
11 changed files with 75 additions and 29 deletions

View File

@ -31,8 +31,8 @@ Just import add the library to your project with one of these options:
</dependency> </dependency>
``` ```
2. Using Jitpack from [here](https://jitpack.io/#rubenlagus/TelegramBots/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.3) 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`. In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.

View File

@ -29,4 +29,9 @@
1. In `BotSession`, renamed `close` to `stop`. `Close` method is maintained for backward compatibility. 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) 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]]** **[[How to update to version 2.4.4.3|How-To-Update#2.4.4.3]]**
### <a id="2.4.4.4"></a>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]]**

View File

@ -11,13 +11,13 @@ First you need ot get the library and add it to your project. There are few poss
<dependency> <dependency>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId> <artifactId>telegrambots</artifactId>
<version>2.4.4.3</version> <version>2.4.4.4</version>
</dependency> </dependency>
``` ```
* With **Gradle**: * With **Gradle**:
```groovy ```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). 2. Don't like **Maven Central Repository**? It can also be taken from [Jitpack](https://jitpack.io/#rubenlagus/TelegramBots).

View File

@ -16,4 +16,8 @@
3. Removed deprecated stuff from version 2.4.3 3. Removed deprecated stuff from version 2.4.3
### <a id="2.4.4.3"></a>To version 2.4.4.3 ### ### <a id="2.4.4.3"></a>To version 2.4.4.3 ###
1. Replace `BotSession.close()` by `BotSession.stop()`. 1. Replace `BotSession.close()` by `BotSession.stop()`.
### <a id="2.4.4.4"></a>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<Serializable>` due to new return type.

View File

@ -7,7 +7,7 @@
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>Bots</artifactId> <artifactId>Bots</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>2.4.4.3</version> <version>2.4.4.4</version>
<modules> <modules>
<module>telegrambots</module> <module>telegrambots</module>
@ -24,6 +24,6 @@
<properties> <properties>
<maven.deploy.skip>true</maven.deploy.skip> <maven.deploy.skip>true</maven.deploy.skip>
<bots.version>2.4.4.3</bots.version> <bots.version>2.4.4.4</bots.version>
</properties> </properties>
</project> </project>

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots-meta</artifactId> <artifactId>telegrambots-meta</artifactId>
<version>2.4.4.3</version> <version>2.4.4.4</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Telegram Bots Meta</name> <name>Telegram Bots Meta</name>

View File

@ -11,15 +11,16 @@ import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 1.0 * @version 1.0
* @brief Use this method to edit captions of messages sent by the bot or via the bot (for inline * @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 * @date 10 of April of 2016
*/ */
public class EditMessageCaption extends BotApiMethod<Message> { public class EditMessageCaption extends BotApiMethod<Serializable> {
public static final String PATH = "editmessagecaption"; public static final String PATH = "editmessagecaption";
private static final String CHATID_FIELD = "chat_id"; private static final String CHATID_FIELD = "chat_id";
@ -104,7 +105,7 @@ public class EditMessageCaption extends BotApiMethod<Message> {
} }
@Override @Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException { public Serializable deserializeResponse(String answer) throws TelegramApiRequestException {
try { try {
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer, ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Message>>(){}); new TypeReference<ApiResponse<Message>>(){});
@ -114,7 +115,18 @@ public class EditMessageCaption extends BotApiMethod<Message> {
throw new TelegramApiRequestException("Error editing message caption", result); throw new TelegramApiRequestException("Error editing message caption", result);
} }
} catch (IOException e) { } catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e); try {
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>() {
});
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);
}
} }
} }

View File

@ -11,16 +11,18 @@ import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 1.0 * @version 1.0
* @brief Use this method to edit only the reply markup of messages sent by the bot or via the bot * @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 * @date 10 of April of 2016
*/ */
public class EditMessageReplyMarkup extends BotApiMethod<Message> { public class EditMessageReplyMarkup extends BotApiMethod<Serializable> {
public static final String PATH = "editmessagereplymarkup"; public static final String PATH = "editmessagereplymarkup";
private static final String CHATID_FIELD = "chat_id"; private static final String CHATID_FIELD = "chat_id";
@ -99,7 +101,7 @@ public class EditMessageReplyMarkup extends BotApiMethod<Message> {
} }
@Override @Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException { public Serializable deserializeResponse(String answer) throws TelegramApiRequestException {
try { try {
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer, ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Message>>(){}); new TypeReference<ApiResponse<Message>>(){});
@ -109,7 +111,18 @@ public class EditMessageReplyMarkup extends BotApiMethod<Message> {
throw new TelegramApiRequestException("Error editing message reply markup", result); throw new TelegramApiRequestException("Error editing message reply markup", result);
} }
} catch (IOException e) { } catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e); try {
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>() {
});
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);
}
} }
} }

View File

@ -12,16 +12,17 @@ import org.telegram.telegrambots.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.exceptions.TelegramApiValidationException; import org.telegram.telegrambots.exceptions.TelegramApiValidationException;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 1.0 * @version 1.0
* @brief Use this method to edit text messages sent by the bot or via the bot (for inline bots). On * @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 * @date 10 of April of 2016
*/ */
public class EditMessageText extends BotApiMethod<Message> { public class EditMessageText extends BotApiMethod<Serializable> {
public static final String PATH = "editmessagetext"; public static final String PATH = "editmessagetext";
private static final String CHATID_FIELD = "chat_id"; private static final String CHATID_FIELD = "chat_id";
@ -159,7 +160,7 @@ public class EditMessageText extends BotApiMethod<Message> {
} }
@Override @Override
public Message deserializeResponse(String answer) throws TelegramApiRequestException { public Serializable deserializeResponse(String answer) throws TelegramApiRequestException {
try { try {
ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer, ApiResponse<Message> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Message>>(){}); new TypeReference<ApiResponse<Message>>(){});
@ -169,7 +170,18 @@ public class EditMessageText extends BotApiMethod<Message> {
throw new TelegramApiRequestException("Error editing message text", result); throw new TelegramApiRequestException("Error editing message text", result);
} }
} catch (IOException e) { } catch (IOException e) {
throw new TelegramApiRequestException("Unable to deserialize response", e); try {
ApiResponse<Boolean> result = OBJECT_MAPPER.readValue(answer,
new TypeReference<ApiResponse<Boolean>>() {
});
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);
}
} }
} }

View File

@ -164,21 +164,21 @@ public abstract class AbsSender {
return sendApiMethod(getChatMemberCount); return sendApiMethod(getChatMemberCount);
} }
public final Message editMessageText(EditMessageText editMessageText) throws TelegramApiException { public final Serializable editMessageText(EditMessageText editMessageText) throws TelegramApiException {
if (editMessageText == null) { if (editMessageText == null) {
throw new TelegramApiException("Parameter editMessageText can not be null"); throw new TelegramApiException("Parameter editMessageText can not be null");
} }
return sendApiMethod(editMessageText); return sendApiMethod(editMessageText);
} }
public final Message editMessageCaption(EditMessageCaption editMessageCaption) throws TelegramApiException { public final Serializable editMessageCaption(EditMessageCaption editMessageCaption) throws TelegramApiException {
if (editMessageCaption == null) { if (editMessageCaption == null) {
throw new TelegramApiException("Parameter editMessageCaption can not be null"); throw new TelegramApiException("Parameter editMessageCaption can not be null");
} }
return sendApiMethod(editMessageCaption); return sendApiMethod(editMessageCaption);
} }
public final Message editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup) throws TelegramApiException { public final Serializable editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup) throws TelegramApiException {
if (editMessageReplyMarkup == null) { if (editMessageReplyMarkup == null) {
throw new TelegramApiException("Parameter editMessageReplyMarkup can not be null"); throw new TelegramApiException("Parameter editMessageReplyMarkup can not be null");
} }
@ -407,7 +407,7 @@ public abstract class AbsSender {
sendApiMethodAsync(getChatMemberCount, sentCallback); sendApiMethodAsync(getChatMemberCount, sentCallback);
} }
public final void editMessageTextAsync(EditMessageText editMessageText, SentCallback<Message> sentCallback) throws TelegramApiException { public final void editMessageTextAsync(EditMessageText editMessageText, SentCallback<Serializable> sentCallback) throws TelegramApiException {
if (editMessageText == null) { if (editMessageText == null) {
throw new TelegramApiException("Parameter editMessageText can not be null"); throw new TelegramApiException("Parameter editMessageText can not be null");
} }
@ -418,7 +418,7 @@ public abstract class AbsSender {
sendApiMethodAsync(editMessageText, sentCallback); sendApiMethodAsync(editMessageText, sentCallback);
} }
public final void editMessageCaptionAsync(EditMessageCaption editMessageCaption, SentCallback<Message> sentCallback) throws TelegramApiException { public final void editMessageCaptionAsync(EditMessageCaption editMessageCaption, SentCallback<Serializable> sentCallback) throws TelegramApiException {
if (editMessageCaption == null) { if (editMessageCaption == null) {
throw new TelegramApiException("Parameter editMessageCaption can not be null"); throw new TelegramApiException("Parameter editMessageCaption can not be null");
} }
@ -429,7 +429,7 @@ public abstract class AbsSender {
sendApiMethodAsync(editMessageCaption, sentCallback); sendApiMethodAsync(editMessageCaption, sentCallback);
} }
public final void editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup, SentCallback<Message> sentCallback) throws TelegramApiException { public final void editMessageReplyMarkup(EditMessageReplyMarkup editMessageReplyMarkup, SentCallback<Serializable> sentCallback) throws TelegramApiException {
if (editMessageReplyMarkup == null) { if (editMessageReplyMarkup == null) {
throw new TelegramApiException("Parameter editMessageReplyMarkup can not be null"); throw new TelegramApiException("Parameter editMessageReplyMarkup can not be null");
} }

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId> <artifactId>telegrambots</artifactId>
<version>2.4.4.3</version> <version>2.4.4.4</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Telegram Bots</name> <name>Telegram Bots</name>
@ -65,7 +65,7 @@
<json.version>20160810</json.version> <json.version>20160810</json.version>
<jackson.version>2.8.5</jackson.version> <jackson.version>2.8.5</jackson.version>
<commonio.version>2.5</commonio.version> <commonio.version>2.5</commonio.version>
<bots.version>2.4.4.3</bots.version> <bots.version>2.4.4.4</bots.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>