TDLightTelegramBots/telegrambots-meta/src/main/java/org/telegram/telegrambots/meta/api/methods/ForwardMessage.java

109 lines
3.5 KiB
Java
Raw Normal View History

2018-07-08 01:41:21 +02:00
package org.telegram.telegrambots.meta.api.methods;
2016-01-14 01:14:53 +01:00
import com.fasterxml.jackson.annotation.JsonProperty;
2020-11-01 23:46:36 +01:00
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
2022-06-14 22:20:22 +02:00
import lombok.experimental.Tolerate;
2022-06-16 19:57:41 +02:00
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodMessage;
2018-07-08 01:41:21 +02:00
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
2016-01-14 01:14:53 +01:00
/**
* @author Ruben Bermudez
* @version 1.0
2021-04-26 21:55:00 +02:00
* Use this method to forward messages of any kind.
* Service messages can't be forwarded.
*
* On success, the sent Message is returned.
2016-01-14 01:14:53 +01:00
*/
2020-11-01 23:46:36 +01:00
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
2022-06-16 19:36:20 +02:00
public class ForwardMessage extends BotApiMethodMessage {
2016-01-14 01:14:53 +01:00
public static final String PATH = "forwardmessage";
2016-06-01 02:06:35 +02:00
private static final String CHATID_FIELD = "chat_id";
2022-11-08 19:33:50 +01:00
private static final String MESSAGETHREADID_FIELD = "message_thread_id";
2016-06-01 02:06:35 +02:00
private static final String FROMCHATID_FIELD = "from_chat_id";
private static final String MESSAGEID_FIELD = "message_id";
private static final String DISABLENOTIFICATION_FIELD = "disable_notification";
2022-01-02 00:06:28 +01:00
private static final String PROTECTCONTENT_FIELD = "protect_content";
@JsonProperty(CHATID_FIELD)
2020-11-01 23:46:36 +01:00
@NonNull
2016-04-12 19:53:21 +02:00
private String chatId; ///< Unique identifier for the chat to send the message to (or username for channels)
2022-11-08 19:33:50 +01:00
/**
* Unique identifier for the target message thread (topic) of the forum;
* for forum supergroups only
*/
@JsonProperty(MESSAGETHREADID_FIELD)
private Integer messageThreadId;
@JsonProperty(FROMCHATID_FIELD)
2020-11-01 23:46:36 +01:00
@NonNull
2016-06-01 02:06:35 +02:00
private String fromChatId; ///< Unique identifier for the chat where the original message was sent — User or GroupChat id
@JsonProperty(MESSAGEID_FIELD)
2020-11-01 23:46:36 +01:00
@NonNull
2016-04-12 19:53:21 +02:00
private Integer messageId; ///< Unique message identifier
2016-02-27 03:17:06 +01:00
/**
* Optional. Sends the message silently.
* iOS users will not receive a notification,
* Android users will receive a notification with no sound.
* Other apps coming soon
*/
@JsonProperty(DISABLENOTIFICATION_FIELD)
2016-02-27 03:17:06 +01:00
private Boolean disableNotification;
2022-01-02 00:06:28 +01:00
@JsonProperty(PROTECTCONTENT_FIELD)
private Boolean protectContent; ///< Optional. Protects the contents of sent messages from forwarding and saving
2016-01-14 01:14:53 +01:00
2022-06-14 22:20:22 +02:00
@Tolerate
public void setChatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
}
@Tolerate
public void setFromChatId(@NonNull Long fromChatId) {
this.fromChatId = fromChatId.toString();
}
@Override
public void validate() throws TelegramApiValidationException {
2022-06-14 22:20:22 +02:00
if (chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
2022-06-14 22:20:22 +02:00
if (fromChatId.isEmpty()) {
throw new TelegramApiValidationException("FromChatId can't be empty", this);
}
2016-02-27 03:17:06 +01:00
}
2016-01-14 01:14:53 +01:00
@Override
public String getMethod() {
2016-01-14 01:14:53 +01:00
return PATH;
}
2022-06-14 22:20:22 +02:00
public static class ForwardMessageBuilder {
@Tolerate
public ForwardMessageBuilder chatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
return this;
}
@Tolerate
public ForwardMessageBuilder fromChatId(@NonNull Long fromChatId) {
this.fromChatId = fromChatId.toString();
return this;
}
}
2016-01-14 01:14:53 +01:00
}