Merge pull request #70 from rubenlagus/dev

Added new api fields
This commit is contained in:
Ruben Bermudez 2016-05-07 18:43:46 +02:00
commit bb110e1127
4 changed files with 30 additions and 2 deletions

View File

@ -15,7 +15,7 @@ I recommend using getUpdates methods.
## Usage
Just import add the library to your project using [Maven, Gradly, ...](https://jitpack.io/#rubenlagus/TelegramBots/v2.3.1) or download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v2.3.1)
Just import add the library to your project using [Maven, Gradly, ...](https://jitpack.io/#rubenlagus/TelegramBots/v2.3.2) or download the jar(including all dependencies) from [here](https://github.com/rubenlagus/TelegramBots/releases/tag/v2.3.2)
In order to use Long Polling mode, just create your own bot extending `org.telegram.telegrambots.bots.TelegramLongPollingBot`.

View File

@ -6,7 +6,7 @@
<packaging>jar</packaging>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>2.3.1</version>
<version>2.3.2</version>
<name>Telegram Bots</name>
<url>https://telegram.me/JavaBotsApi</url>

View File

@ -25,6 +25,7 @@ public class Message implements IBotApiObject {
private static final String DATE_FIELD = "date";
private static final String CHAT_FIELD = "chat";
private static final String FORWARDFROM_FIELD = "forward_from";
private static final String FORWARDFROMCHAT_FIELD = "forward_from_chat";
private static final String FORWARDDATE_FIELD = "forward_date";
private static final String TEXT_FIELD = "text";
private static final String ENTITIES_FIELD = "entities";
@ -59,6 +60,8 @@ public class Message implements IBotApiObject {
private Chat chat; ///< Conversation the message belongs to
@JsonProperty(FORWARDFROM_FIELD)
private User forwardFrom; ///< Optional. For forwarded messages, sender of the original message
@JsonProperty(FORWARDFROMCHAT_FIELD)
private Chat forwardedFromChat; ///< Optional. For messages forwarded from a channel, information about the original channel
@JsonProperty(FORWARDDATE_FIELD)
private Integer forwardDate; ///< Optional. For forwarded messages, date the original message was sent
@JsonProperty(TEXT_FIELD)
@ -126,6 +129,9 @@ public class Message implements IBotApiObject {
this.date = jsonObject.getInt(DATE_FIELD);
}
this.chat = new Chat(jsonObject.getJSONObject(CHAT_FIELD));
if (jsonObject.has(FORWARDFROMCHAT_FIELD)) {
this.forwardedFromChat = new Chat(jsonObject.getJSONObject(FORWARDFROMCHAT_FIELD));
}
if (jsonObject.has(FORWARDFROM_FIELD)) {
this.forwardFrom = new User(jsonObject.getJSONObject(FORWARDFROM_FIELD));
}
@ -367,6 +373,10 @@ public class Message implements IBotApiObject {
return location != null;
}
public Chat getForwardedFromChat() {
return forwardedFromChat;
}
@Override
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
@ -378,6 +388,9 @@ public class Message implements IBotApiObject {
gen.writeNumberField(DATE_FIELD, date);
}
gen.writeObjectField(CHAT_FIELD, chat);
if (forwardedFromChat != null) {
gen.writeObjectField(FORWARDFROMCHAT_FIELD, forwardedFromChat);
}
if (forwardFrom != null) {
gen.writeObjectField(FORWARDFROM_FIELD, forwardFrom);
}
@ -472,6 +485,7 @@ public class Message implements IBotApiObject {
", date=" + date +
", chat=" + chat +
", forwardFrom=" + forwardFrom +
", forwardedFromChat=" + forwardedFromChat +
", forwardDate=" + forwardDate +
", text='" + text + '\'' +
", audio=" + audio +

View File

@ -23,6 +23,7 @@ public class Sticker implements IBotApiObject {
private static final String HEIGHT_FIELD = "height";
private static final String THUMB_FIELD = "thumb";
private static final String FILESIZE_FIELD = "file_size";
private static final String EMOJI_FIELD = "emoji";
@JsonProperty(FILEID_FIELD)
private String fileId; ///< Unique identifier for this file
@JsonProperty(WIDTH_FIELD)
@ -33,6 +34,8 @@ public class Sticker implements IBotApiObject {
private PhotoSize thumb; ///< Optional. Sticker thumbnail in .webp or .jpg format
@JsonProperty(FILESIZE_FIELD)
private Integer fileSize; ///< Optional. File size
@JsonProperty(EMOJI_FIELD)
private String emoji; ///< Optional. Emoji associated with the sticker
public Sticker() {
super();
@ -49,6 +52,9 @@ public class Sticker implements IBotApiObject {
if (jsonObject.has(FILESIZE_FIELD)) {
this.fileSize = jsonObject.getInt(FILESIZE_FIELD);
}
if (jsonObject.has(EMOJI_FIELD)) {
this.emoji = jsonObject.getString(EMOJI_FIELD);
}
}
public String getFileId() {
@ -71,6 +77,10 @@ public class Sticker implements IBotApiObject {
return fileSize;
}
public String getEmoji() {
return emoji;
}
@Override
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
@ -83,6 +93,9 @@ public class Sticker implements IBotApiObject {
if (fileSize != null) {
gen.writeNumberField(FILESIZE_FIELD, fileSize);
}
if (emoji != null) {
gen.writeStringField(EMOJI_FIELD, emoji);
}
gen.writeEndObject();
gen.flush();
}
@ -100,6 +113,7 @@ public class Sticker implements IBotApiObject {
", height=" + height +
", thumb=" + thumb +
", fileSize=" + fileSize +
", emoji=" + emoji +
'}';
}
}