diff --git a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java index bf2e6f25..ae3b11de 100644 --- a/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java +++ b/telegrambots-meta/src/main/java/org/telegram/telegrambots/api/methods/ForwardMessage.java @@ -14,8 +14,7 @@ import java.util.Objects; /** * @author Ruben Bermudez * @version 1.0 - * @brief Use this method to send text messages. On success, the sent Message is returned. - * @date 20 of June of 2015 + * Use this method to send text messages. On success, the sent Message is returned. */ public class ForwardMessage extends BotApiMethod { public static final String PATH = "forwardmessage"; @@ -44,6 +43,42 @@ public class ForwardMessage extends BotApiMethod { super(); } + public ForwardMessage(String chatId, String fromChatId, Integer messageId) { + this(); + Objects.requireNonNull(chatId); + Objects.requireNonNull(fromChatId); + this.chatId = chatId; + this.fromChatId = fromChatId; + this.messageId = messageId; + } + + public ForwardMessage(String chatId, Long fromChatId, Integer messageId) { + this(); + Objects.requireNonNull(chatId); + Objects.requireNonNull(fromChatId); + this.chatId = chatId; + this.fromChatId = fromChatId.toString(); + this.messageId = messageId; + } + + public ForwardMessage(Long chatId, String fromChatId, Integer messageId) { + this(); + Objects.requireNonNull(chatId); + Objects.requireNonNull(fromChatId); + this.chatId = chatId.toString(); + this.fromChatId = fromChatId; + this.messageId = messageId; + } + + public ForwardMessage(Long chatId, Long fromChatId, Integer messageId) { + this(); + Objects.requireNonNull(chatId); + Objects.requireNonNull(fromChatId); + this.chatId = chatId.toString(); + this.fromChatId = fromChatId.toString(); + this.messageId = messageId; + } + public String getChatId() { return chatId; } @@ -68,6 +103,12 @@ public class ForwardMessage extends BotApiMethod { return this; } + public ForwardMessage setFromChatId(Long fromChatId) { + Objects.requireNonNull(fromChatId); + this.fromChatId = fromChatId.toString(); + return this; + } + public Integer getMessageId() { return messageId; } @@ -93,10 +134,10 @@ public class ForwardMessage extends BotApiMethod { @Override public void validate() throws TelegramApiValidationException { - if (chatId == null) { + if (chatId == null || chatId.isEmpty()) { throw new TelegramApiValidationException("ChatId can't be empty", this); } - if (fromChatId == null) { + if (fromChatId == null || fromChatId.isEmpty()) { throw new TelegramApiValidationException("FromChatId can't be empty", this); } if (messageId == null) { @@ -128,8 +169,9 @@ public class ForwardMessage extends BotApiMethod { public String toString() { return "ForwardMessage{" + "chatId='" + chatId + '\'' + - ", fromChatId=" + fromChatId + + ", fromChatId='" + fromChatId + '\'' + ", messageId=" + messageId + + ", disableNotification=" + disableNotification + '}'; } } diff --git a/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java b/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java index c35e85db..3716ad92 100644 --- a/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java +++ b/telegrambots/src/test/java/org/telegram/telegrambots/test/BotApiMethodHelperFactory.java @@ -102,7 +102,7 @@ public final class BotApiMethodHelperFactory { } public static BotApiMethod getForwardMessage() { - return new ForwardMessage() + return new ForwardMessage(54L, 123L, 55) .setFromChatId("From") .setChatId("To") .setMessageId(15)