From 64b0be31541be66e8c9365aa4c2bdfff646f2709 Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Mon, 8 Apr 2019 01:43:46 +0100 Subject: [PATCH] Api version 4.2 --- .../pinnedmessages/PinChatMessage.java | 8 +- .../pinnedmessages/UnpinChatMessage.java | 7 +- .../meta/api/methods/polls/SendPoll.java | 209 ++++++++++++++++++ .../meta/api/methods/polls/StopPoll.java | 119 ++++++++++ .../meta/api/methods/send/SendAnimation.java | 2 +- .../meta/api/methods/send/SendAudio.java | 2 +- .../meta/api/methods/send/SendDocument.java | 2 +- .../meta/api/methods/send/SendVideo.java | 2 +- .../meta/api/methods/send/SendVideoNote.java | 2 +- .../updatingmessages/DeleteMessage.java | 14 +- .../updatingmessages/EditMessageCaption.java | 4 +- .../EditMessageLiveLocation.java | 2 +- .../EditMessageReplyMarkup.java | 4 +- .../updatingmessages/EditMessageText.java | 2 +- .../telegrambots/meta/api/objects/Chat.java | 2 +- .../meta/api/objects/ChatMember.java | 5 +- .../meta/api/objects/Message.java | 11 + .../telegrambots/meta/api/objects/Update.java | 13 +- .../objects/media/InputMediaAnimation.java | 2 +- .../api/objects/media/InputMediaAudio.java | 2 +- .../api/objects/media/InputMediaDocument.java | 2 +- .../api/objects/media/InputMediaVideo.java | 2 +- .../meta/api/objects/polls/Poll.java | 73 ++++++ .../meta/api/objects/polls/PollOption.java | 47 ++++ 24 files changed, 507 insertions(+), 31 deletions(-) create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/SendPoll.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/StopPoll.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/polls/Poll.java create mode 100644 telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/polls/PollOption.java diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/PinChatMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/PinChatMessage.java index 6cc4e705..f684de3f 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/PinChatMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/PinChatMessage.java @@ -15,10 +15,10 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * @author Ruben Bermudez * @version 3.1 - * Use this method to pin a message in a supergroup or channel. - * The bot must be an administrator in the chat for this to work and must have the ‘can_pin_messages’ - * admin right in the supergroup or ‘can_edit_messages’ admin right in the channel. - * Returns True on success. + * Use this method to pin a message in a group, a supergroup or a channel. + * The bot must be an administrator in the chat for this to work and must + * have the ‘can_pin_messages’ admin right in the supergroup or ‘can_edit_messages’ + * admin right in the channel. Returns True on success. */ public class PinChatMessage extends BotApiMethod { public static final String PATH = "pinChatMessage"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/UnpinChatMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/UnpinChatMessage.java index 6104d419..b757c695 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/UnpinChatMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/pinnedmessages/UnpinChatMessage.java @@ -15,9 +15,10 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * @author Ruben Bermudez * @version 3.1 - * Use this method to unpin a message in a supergroup or channel. - * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. - * Returns True on success. + * Use this method to unpin a message in a group, a supergroup or a channel. + * The bot must be an administrator in the chat for this to work and must have + * the ‘can_pin_messages’ admin right in the supergroup or ‘can_edit_messages’ + * admin right in the channel. Returns True on success. */ public class UnpinChatMessage extends BotApiMethod { public static final String PATH = "unpinChatMessage"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/SendPoll.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/SendPoll.java new file mode 100644 index 00000000..e01d4ef7 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/SendPoll.java @@ -0,0 +1,209 @@ +package org.telegram.telegrambots.meta.api.methods.polls; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import org.telegram.telegrambots.meta.api.methods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.Message; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboard; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.io.IOException; +import java.util.List; +import java.util.Objects; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Ruben Bermudez + * @version 1.0 + * Use this method to send a native poll. + * A native poll can't be sent to a private chat. + * + * On success, the sent Message is returned. + */ +public class SendPoll extends BotApiMethod { + public static final String PATH = "sendPoll"; + + private static final String CHATID_FIELD = "chat_id"; + private static final String QUESTION_FIELD = "question"; + private static final String OPTIONS_FIELD = "options"; + private static final String DISABLENOTIFICATION_FIELD = "disable_notification"; + private static final String REPLYTOMESSAGEID_FIELD = "reply_to_message_id"; + private static final String REPLYMARKUP_FIELD = "reply_markup"; + + @JsonProperty(CHATID_FIELD) + /** + * Unique identifier for the target chat or username of the target channel (in the format @channelusername). + * A native poll can't be sent to a private chat. + */ + private String chatId; + @JsonProperty(QUESTION_FIELD) + private String question; ///< Poll question, 1-255 characters + @JsonProperty(OPTIONS_FIELD) + private List options; ///< List of answer options, 1-10 strings 1-100 characters each + @JsonProperty(DISABLENOTIFICATION_FIELD) + private Boolean disableNotification; ///< Optional. Sends the message silently. Users will receive a notification with no sound. + @JsonProperty(REPLYTOMESSAGEID_FIELD) + private Integer replyToMessageId; ///< Optional. If the message is a reply, ID of the original message + @JsonProperty(REPLYMARKUP_FIELD) + private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard + + public SendPoll() { + super(); + } + + public SendPoll(String chatId, String question, List options) { + this.chatId = checkNotNull(chatId); + this.question = checkNotNull(question); + this.options = checkNotNull(options); + } + + public SendPoll(Long chatId, String question, List options) { + this.chatId = checkNotNull(chatId).toString(); + this.question = checkNotNull(question); + this.options = checkNotNull(options); + } + + public String getChatId() { + return chatId; + } + + public SendPoll setChatId(String chatId) { + this.chatId = chatId; + return this; + } + + public SendPoll setChatId(Long chatId) { + Objects.requireNonNull(chatId); + this.chatId = chatId.toString(); + return this; + } + + public String getQuestion() { + return question; + } + + public SendPoll setQuestion(String question) { + this.question = question; + return this; + } + + public List getOptions() { + return options; + } + + public SendPoll setOptions(List options) { + this.options = options; + return this; + } + + public Integer getReplyToMessageId() { + return replyToMessageId; + } + + public SendPoll setReplyToMessageId(Integer replyToMessageId) { + this.replyToMessageId = replyToMessageId; + return this; + } + + public ReplyKeyboard getReplyMarkup() { + return replyMarkup; + } + + public SendPoll setReplyMarkup(ReplyKeyboard replyMarkup) { + this.replyMarkup = replyMarkup; + return this; + } + + + public Boolean getDisableNotification() { + return disableNotification; + } + + public SendPoll enableNotification() { + this.disableNotification = null; + return this; + } + + public SendPoll disableNotification() { + this.disableNotification = true; + return this; + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public Message deserializeResponse(String answer) throws TelegramApiRequestException { + try { + ApiResponse result = OBJECT_MAPPER.readValue(answer, + new TypeReference>(){}); + if (result.getOk()) { + return result.getResult(); + } else { + throw new TelegramApiRequestException("Error sending poll", result); + } + } catch (IOException e) { + throw new TelegramApiRequestException("Unable to deserialize response", e); + } + } + + @Override + public void validate() throws TelegramApiValidationException { + if (chatId == null) { + throw new TelegramApiValidationException("ChatId parameter can't be empty", this); + } + if (question == null || question.isEmpty()) { + throw new TelegramApiValidationException("Question parameter can't be empty", this); + } + if (options == null || options.isEmpty()) { + throw new TelegramApiValidationException("Options parameter can't be empty", this); + } + if (replyMarkup != null) { + replyMarkup.validate(); + } + } + + @Override + public boolean equals(Object o) { + if (o == this) return true; + if (!(o instanceof SendPoll)) { + return false; + } + SendPoll sendMessage = (SendPoll) o; + return Objects.equals(chatId, sendMessage.chatId) + && Objects.equals(disableNotification, sendMessage.disableNotification) + && Objects.equals(question, sendMessage.question) + && Objects.equals(options, sendMessage.options) + && Objects.equals(replyMarkup, sendMessage.replyMarkup) + && Objects.equals(replyToMessageId, sendMessage.replyToMessageId) + ; + } + + @Override + public int hashCode() { + return Objects.hash( + chatId, + disableNotification, + options, + replyMarkup, + replyToMessageId, + question); + } + + @Override + public String toString() { + return "SendPoll{" + + "chatId='" + chatId + '\'' + + ", question='" + question + '\'' + + ", options=" + options + + ", disableNotification=" + disableNotification + + ", replyToMessageId=" + replyToMessageId + + ", replyMarkup=" + replyMarkup + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/StopPoll.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/StopPoll.java new file mode 100644 index 00000000..c921e3a0 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/polls/StopPoll.java @@ -0,0 +1,119 @@ +package org.telegram.telegrambots.meta.api.methods.polls; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import org.telegram.telegrambots.meta.api.methods.BotApiMethod; +import org.telegram.telegrambots.meta.api.objects.polls.Poll; +import org.telegram.telegrambots.meta.api.objects.replykeyboard.ApiResponse; +import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; +import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; + +import java.io.IOException; +import java.util.Objects; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Ruben Bermudez + * @version 1.0 + * Use this method to stop a poll which was sent by the bot. + * + * On success, the stopped Poll with the final results is returned. + */ +public class StopPoll extends BotApiMethod { + public static final String PATH = "stopPoll"; + + private static final String CHATID_FIELD = "chat_id"; + private static final String MESSAGEID_FIELD = "message_id"; + + @JsonProperty(CHATID_FIELD) + private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername) + @JsonProperty(MESSAGEID_FIELD) + private Integer messageId; ///< Identifier of the original message with the poll + + public StopPoll() { + super(); + } + + public StopPoll(String chatId, Integer messageId) { + this.chatId = checkNotNull(chatId); + this.messageId = checkNotNull(messageId); + } + + public StopPoll(Long chatId, Integer messageId) { + this.chatId = checkNotNull(chatId).toString(); + this.messageId = checkNotNull(messageId); + } + + public String getChatId() { + return chatId; + } + + public StopPoll setChatId(String chatId) { + this.chatId = chatId; + return this; + } + + public StopPoll setChatId(Long chatId) { + Objects.requireNonNull(chatId); + this.chatId = chatId.toString(); + return this; + } + + @Override + public String getMethod() { + return PATH; + } + + @Override + public Poll deserializeResponse(String answer) throws TelegramApiRequestException { + try { + ApiResponse result = OBJECT_MAPPER.readValue(answer, + new TypeReference>(){}); + if (result.getOk()) { + return result.getResult(); + } else { + throw new TelegramApiRequestException("Error stopping poll", result); + } + } catch (IOException e) { + throw new TelegramApiRequestException("Unable to deserialize response", e); + } + } + + @Override + public void validate() throws TelegramApiValidationException { + if (chatId == null) { + throw new TelegramApiValidationException("ChatId parameter can't be empty", this); + } + if (messageId == null || messageId == 0) { + throw new TelegramApiValidationException("Message Id parameter can't be empty", this); + } + } + + @Override + public boolean equals(Object o) { + if (o == this) return true; + if (!(o instanceof StopPoll)) { + return false; + } + StopPoll sendMessage = (StopPoll) o; + return Objects.equals(chatId, sendMessage.chatId) + && Objects.equals(messageId, sendMessage.messageId) + ; + } + + @Override + public int hashCode() { + return Objects.hash( + chatId, + messageId); + } + + @Override + public String toString() { + return "StopPoll{" + + "chatId='" + chatId + '\'' + + ", messageId=" + messageId + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAnimation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAnimation.java index f4d971aa..9c352fdd 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAnimation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAnimation.java @@ -55,7 +55,7 @@ public class SendAnimation extends PartialBotApiMethod { private String parseMode; ///< Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. /** * Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. - * A thumbnail‘s width and height should not exceed 90. + * A thumbnail’s width and height should not exceed 320. * Ignored if the file is not uploaded using multipart/form-data. * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” * if the thumbnail was uploaded using multipart/form-data under . diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAudio.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAudio.java index a1c1e1e4..cdf8ab42 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAudio.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendAudio.java @@ -50,7 +50,7 @@ public class SendAudio extends PartialBotApiMethod { private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. /** * Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. - * A thumbnail‘s width and height should not exceed 90. + * A thumbnail’s width and height should not exceed 320. * Ignored if the file is not uploaded using multipart/form-data. * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass * “attach://” if the thumbnail was uploaded using multipart/form-data under . diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendDocument.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendDocument.java index ab5342b2..56ddb89e 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendDocument.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendDocument.java @@ -40,7 +40,7 @@ public class SendDocument extends PartialBotApiMethod { private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. /** * Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. - * A thumbnail‘s width and height should not exceed 90. + * A thumbnail’s width and height should not exceed 320. * Ignored if the file is not uploaded using multipart/form-data. * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” * if the thumbnail was uploaded using multipart/form-data under . diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideo.java index 5c5bd310..02d877e8 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideo.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideo.java @@ -49,7 +49,7 @@ public class SendVideo extends PartialBotApiMethod { private String parseMode; ///< Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. /** * Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. - * A thumbnail‘s width and height should not exceed 90. + * A thumbnail’s width and height should not exceed 320. * Ignored if the file is not uploaded using multipart/form-data. * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” * if the thumbnail was uploaded using multipart/form-data under . diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideoNote.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideoNote.java index 14a28f68..0e83de3d 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideoNote.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/send/SendVideoNote.java @@ -44,7 +44,7 @@ public class SendVideoNote extends PartialBotApiMethod { private ReplyKeyboard replyMarkup; ///< Optional. JSON-serialized object for a custom reply keyboard /** * Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. - * A thumbnail‘s width and height should not exceed 90. + * A thumbnail’s width and height should not exceed 320. * Ignored if the file is not uploaded using multipart/form-data. * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” * if the thumbnail was uploaded using multipart/form-data under . diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/DeleteMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/DeleteMessage.java index 9437f3c7..a20cd986 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/DeleteMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/DeleteMessage.java @@ -16,12 +16,14 @@ import static com.google.common.base.Preconditions.checkNotNull; * @author Ruben Bermudez * @version 1.0 * - * Use this method to delete a message. A message can only be deleted if it was sent less than - * 48 hours ago. Any sent outgoing message may be deleted. - * Additionally, if the bot is an administrator in a group chat, it can delete any message. - * If the bot is an administrator of a supergroup or channel, - * it can delete ordinary messages from any other user, - * including service messages about people added or removed from the chat. + * Use this method to delete a message, including service messages, with the following limitations: + * - A message can only be deleted if it was sent less than 48 hours ago. + * - Bots can delete outgoing messages in private chats, groups, and supergroups. + * - Bots can delete incoming messages in private chats. + * - Bots granted can_post_messages permissions can delete outgoing messages in channels. + * - If the bot is an administrator of a group, it can delete any message there. + * - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. + * Returns True on success. */ public class DeleteMessage extends BotApiMethod { public static final String PATH = "deleteMessage"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageCaption.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageCaption.java index 6e020651..e30609b1 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageCaption.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageCaption.java @@ -16,8 +16,8 @@ import java.io.Serializable; /** * @author Ruben Bermudez * @version 1.0 - * Use this method to edit captions of messages sent by the bot or via the bot (for inline - * bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. + * Use this method to edit captions of messages. + * On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. */ public class EditMessageCaption extends BotApiMethod { public static final String PATH = "editmessagecaption"; diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java index bb5c391c..d5469327 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageLiveLocation.java @@ -17,7 +17,7 @@ import java.util.Objects; /** * @author Ruben Bermudez * @version 1.0 - * Use this method to edit live location messages sent by the bot or via the bot (for inline bots). + * Use this method to edit live location. * A location can be edited until its live_period expires or editing is explicitly disabled by a call to * stopMessageLiveLocation. On success, if the edited message was sent by the bot, the edited Message is returned, * otherwise True is returned. diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageReplyMarkup.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageReplyMarkup.java index 085cef07..3d935641 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageReplyMarkup.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageReplyMarkup.java @@ -16,8 +16,8 @@ import java.io.Serializable; /** * @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, if edited message is sent by the bot, the edited Message is returned, + * @brief Use this method to edit only the reply markup of messages. + * 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 */ diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageText.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageText.java index 49c09b04..994b8cf2 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageText.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/updatingmessages/EditMessageText.java @@ -17,7 +17,7 @@ import java.io.Serializable; /** * @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 + * @brief Use this method to edit text messages. 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 */ diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java index 24ac9d1e..ffc7cea1 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Chat.java @@ -61,7 +61,7 @@ public class Chat implements BotApiObject { @JsonProperty(INVITELINK_FIELD) private String inviteLink; ///< Optional. Chat invite link, for supergroups and channel chats. Returned only in getChat. @JsonProperty(PINNEDMESSAGE_FIELD) - private Message pinnedMessage; ///< Optional. Pinned message, for supergroups. Returned only in getChat. + private Message pinnedMessage; ///< Optional. Pinned message, for groups, supergroups and channels. Returned only in getChat. @JsonProperty(STICKERSETNAME_FIELD) private String stickerSetName; ///< Optional. For supergroups, name of Group sticker set. Returned only in getChat. @JsonProperty(CANSETSTICKERSET_FIELD) diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java index 347e1a2b..842f3459 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/ChatMember.java @@ -29,6 +29,7 @@ public class ChatMember implements BotApiObject { private static final String CANSENDMEDIAMESSAGES_FIELD = "can_send_media_messages"; private static final String CANSENDOTHERMESSAGES_FIELD = "can_send_other_messages"; private static final String CANADDWEBPAGEPREVIEWS_FIELD = "can_add_web_page_previews"; + private static final String ISMEMBER_FIELD = "is_member"; @JsonProperty(USER_FIELD) private User user; ///< Information about the user @@ -51,7 +52,7 @@ public class ChatMember implements BotApiObject { @JsonProperty(CANRESTRICTUSERS_FIELD) private Boolean canRestrictUsers; ///< Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members @JsonProperty(CANPINMESSAGES_FIELD) - private Boolean canPinMessages; ///< Optional. Administrators only. True, if the administrator can pin messages + private Boolean canPinMessages; ///< Optional. Administrators only. True, if the administrator can pin messages, groups and supergroups only @JsonProperty(CANPROMOTEMEMBERS_FIELD) private Boolean canPromoteMembers; ///< Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that it has promoted, directly or indirectly (promoted by administrators that were appointed by the bot) @JsonProperty(CANSENDMESSAGES_FIELD) @@ -62,6 +63,8 @@ public class ChatMember implements BotApiObject { private Boolean canSendOtherMessages; ///< Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages @JsonProperty(CANADDWEBPAGEPREVIEWS_FIELD) private Boolean canAddWebPagePreviews; ///< Optional. Restricted only. True, if user may add web page previews Э to his messages, implies can_send_messages + @JsonProperty(ISMEMBER_FIELD) + private Boolean isMemberField; ///< True, if the user is a member of the chat at the moment of the request. For example, it can be false for the chat creator or for a restricted user. public ChatMember() { super(); diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Message.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Message.java index d0f6f3e6..cc1a8ba8 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Message.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Message.java @@ -62,6 +62,7 @@ public class Message implements BotApiObject { private static final String MEDIAGROUPID_FIELD = "media_group_id"; private static final String CONNECTEDWEBSITE_FIELD = "connected_website"; private static final String PASSPORTDATA_FIELD = "passport_data"; + private static final String FORWARDSENDERNAME_FIELD = "forward_sender_name"; @JsonProperty(MESSAGEID_FIELD) private Integer messageId; ///< Integer Unique message identifier @@ -191,6 +192,8 @@ public class Message implements BotApiObject { private String connectedWebsite; ///< Optional. The domain name of the website on which the user has logged in @JsonProperty(PASSPORTDATA_FIELD) private PassportData passportData; ///< Optional. Telegram Passport data + @JsonProperty(FORWARDSENDERNAME_FIELD) + private String forwardSenderName; ///< Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages. public Message() { super(); @@ -478,6 +481,14 @@ public class Message implements BotApiObject { return animation != null; } + public String getForwardSenderName() { + return forwardSenderName; + } + + public void setForwardSenderName(String forwardSenderName) { + this.forwardSenderName = forwardSenderName; + } + @Override public String toString() { return "Message{" + diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Update.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Update.java index a5de6095..2bfd7c23 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Update.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/Update.java @@ -1,12 +1,12 @@ package org.telegram.telegrambots.meta.api.objects; import com.fasterxml.jackson.annotation.JsonProperty; - import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; import org.telegram.telegrambots.meta.api.objects.inlinequery.ChosenInlineQuery; import org.telegram.telegrambots.meta.api.objects.inlinequery.InlineQuery; import org.telegram.telegrambots.meta.api.objects.payments.PreCheckoutQuery; import org.telegram.telegrambots.meta.api.objects.payments.ShippingQuery; +import org.telegram.telegrambots.meta.api.objects.polls.Poll; /** * @author Ruben Bermudez @@ -27,6 +27,7 @@ public class Update implements BotApiObject { private static final String EDITEDCHANNELPOST_FIELD = "edited_channel_post"; private static final String SHIPPING_QUERY_FIELD = "shipping_query"; private static final String PRE_CHECKOUT_QUERY_FIELD = "pre_checkout_query"; + private static final String POLL_FIELD = "poll"; @JsonProperty(UPDATEID_FIELD) private Integer updateId; @@ -48,6 +49,8 @@ public class Update implements BotApiObject { private ShippingQuery shippingQuery; ///< Optional. New incoming shipping query. Only for invoices with flexible price @JsonProperty(PRE_CHECKOUT_QUERY_FIELD) private PreCheckoutQuery preCheckoutQuery; ///< Optional. New incoming pre-checkout query. Contains full information about checkout + @JsonProperty(POLL_FIELD) + private Poll poll; ///< Optional. New poll state. Bots receive only updates about polls, which are sent by the bot. public Update() { super(); @@ -93,6 +96,10 @@ public class Update implements BotApiObject { return preCheckoutQuery; } + public Poll getPoll() { + return poll; + } + public boolean hasMessage() { return message != null; } @@ -129,6 +136,10 @@ public class Update implements BotApiObject { return preCheckoutQuery != null; } + public boolean hasPoll() { + return poll != null; + } + @Override public String toString() { return "Update{" + diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaAnimation.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaAnimation.java index 36638551..1595da8f 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaAnimation.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaAnimation.java @@ -27,7 +27,7 @@ public class InputMediaAnimation extends InputMedia { private Integer duration; ///< Optional. Animation duration /** * Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. - * A thumbnail‘s width and height should not exceed 90. + * A thumbnail’s width and height should not exceed 320. * Ignored if the file is not uploaded using multipart/form-data. * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” * if the thumbnail was uploaded using multipart/form-data under . diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaAudio.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaAudio.java index ac115e5e..078528d7 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaAudio.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaAudio.java @@ -27,7 +27,7 @@ public class InputMediaAudio extends InputMedia { private String title; ///< Optional. Title of the audio /** * Optional. Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. - * A thumbnail‘s width and height should not exceed 90. + * A thumbnail’s width and height should not exceed 320. * Ignored if the file is not uploaded using multipart/form-data. * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” * if the thumbnail was uploaded using multipart/form-data under . diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaDocument.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaDocument.java index 0ff6bc04..7098e89d 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaDocument.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaDocument.java @@ -16,7 +16,7 @@ public class InputMediaDocument extends InputMedia { /** * Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. - * A thumbnail‘s width and height should not exceed 90. + * A thumbnail’s width and height should not exceed 320. * Ignored if the file is not uploaded using multipart/form-data. * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” * if the thumbnail was uploaded using multipart/form-data under . diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaVideo.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaVideo.java index a05082f0..5f0645b7 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaVideo.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/media/InputMediaVideo.java @@ -30,7 +30,7 @@ public class InputMediaVideo extends InputMedia { private Boolean supportsStreaming; ///< Optional. Pass True, if the uploaded video is suitable for streaming /** * Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. - * A thumbnail‘s width and height should not exceed 90. + * A thumbnail’s width and height should not exceed 320. * Ignored if the file is not uploaded using multipart/form-data. * Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://” * if the thumbnail was uploaded using multipart/form-data under . diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/polls/Poll.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/polls/Poll.java new file mode 100644 index 00000000..15e0a264 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/polls/Poll.java @@ -0,0 +1,73 @@ +package org.telegram.telegrambots.meta.api.objects.polls; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +import java.util.List; + +/** + * @author Ruben Bermudez + * @version 4.2 + * + * This object contains information about a poll. + */ +public class Poll implements BotApiObject { + private static final String ID_FIELD = "id"; + private static final String QUESTION_FIELD = "question"; + private static final String OPTIONS_FIELD = "options"; + private static final String ISCLOSED_FIELD = "is_closed"; + + @JsonProperty(ID_FIELD) + private String id; ///< Unique poll identifier + @JsonProperty(QUESTION_FIELD) + private String question; ///< Poll question, 1-255 characters + @JsonProperty(OPTIONS_FIELD) + private List options; ///< List of poll options + @JsonProperty(ISCLOSED_FIELD) + private Boolean isClosed; ///< True, if the poll is closed + + public Poll() { + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getQuestion() { + return question; + } + + public void setQuestion(String question) { + this.question = question; + } + + public List getOptions() { + return options; + } + + public void setOptions(List options) { + this.options = options; + } + + public Boolean getClosed() { + return isClosed; + } + + public void setClosed(Boolean closed) { + isClosed = closed; + } + + @Override + public String toString() { + return "Poll{" + + "id='" + id + '\'' + + ", question='" + question + '\'' + + ", options=" + options + + ", isClosed=" + isClosed + + '}'; + } +} diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/polls/PollOption.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/polls/PollOption.java new file mode 100644 index 00000000..85cef066 --- /dev/null +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/objects/polls/PollOption.java @@ -0,0 +1,47 @@ +package org.telegram.telegrambots.meta.api.objects.polls; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.telegram.telegrambots.meta.api.interfaces.BotApiObject; + +/** + * @author Ruben Bermudez + * @version 4.2 + * + * This object contains information about one answer option in a poll. + */ +public class PollOption implements BotApiObject { + private static final String TEXT_FIELD = "text"; + private static final String VOTERCOUNT_FIELD = "voter_count"; + + @JsonProperty(TEXT_FIELD) + private String text; ///< Option text, 1-100 characters + @JsonProperty(VOTERCOUNT_FIELD) + private Integer voterCount; ///< Number of users that voted for this option + + public PollOption() { + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public Integer getVoterCount() { + return voterCount; + } + + public void setVoterCount(Integer voterCount) { + this.voterCount = voterCount; + } + + @Override + public String toString() { + return "PollOption{" + + "text='" + text + '\'' + + ", voterCount=" + voterCount + + '}'; + } +}