2020-11-01 23:46:36 +01:00
package org.telegram.telegrambots.meta.api.methods ;
import com.fasterxml.jackson.annotation.JsonProperty ;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize ;
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 ;
2020-11-01 23:46:36 +01:00
import org.telegram.telegrambots.meta.api.objects.MessageEntity ;
import org.telegram.telegrambots.meta.api.objects.MessageId ;
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.util.List ;
/ * *
* @author Ruben Bermudez
* @version 1 . 0
2021-04-26 21:55:00 +02:00
* Use this method to copy messages of any kind .
* Service messages and invoice messages can ' t be copied .
2022-08-15 02:42:50 +02:00
* A quiz poll can be copied only if the value of the field correct_option_id is known to the bot .
2021-04-26 21:55:00 +02:00
* The method is analogous to the method forwardMessage , but the copied message doesn ' t have a link to the original message .
2020-11-01 23:46:36 +01:00
* Returns the MessageId of the sent message on success .
* /
@SuppressWarnings ( " unused " )
@EqualsAndHashCode ( callSuper = false )
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CopyMessage extends BotApiMethod < MessageId > {
public static final String PATH = " copyMessage " ;
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 " ;
2020-11-01 23:46:36 +01:00
private static final String FROMCHATID_FIELD = " from_chat_id " ;
private static final String MESSAGEID_FIELD = " message_id " ;
private static final String CAPTION_FIELD = " caption " ;
private static final String PARSEMODE_FIELD = " parse_mode " ;
private static final String CAPTIONENTITIES_FIELD = " caption_entities " ;
private static final String DISABLENOTIFICATION_FIELD = " disable_notification " ;
private static final String REPLYTOMESSAGEID_FIELD = " reply_to_message_id " ;
private static final String ALLOWSENDINGWITHOUTREPLY_FIELD = " allow_sending_without_reply " ;
private static final String REPLYMARKUP_FIELD = " reply_markup " ;
2022-01-02 00:06:28 +01:00
private static final String PROTECTCONTENT_FIELD = " protect_content " ;
2020-11-01 23:46:36 +01:00
@JsonProperty ( CHATID_FIELD )
@NonNull
private String chatId ; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
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 ;
2020-11-01 23:46:36 +01:00
@JsonProperty ( FROMCHATID_FIELD )
@NonNull
private String fromChatId ; ///< Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
@JsonProperty ( MESSAGEID_FIELD )
@NonNull
private Integer messageId ; ///< Message identifier in the chat specified in from_chat_id
@JsonProperty ( CAPTION_FIELD )
private String caption ; ///< Optional. New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept
@JsonProperty ( PARSEMODE_FIELD )
private String parseMode ; ///< Optional. Mode for parsing entities in the new caption. See formatting options for more details.
@JsonProperty ( CAPTIONENTITIES_FIELD )
private List < MessageEntity > captionEntities ; ///< Optional. List of special entities that appear in the new caption, which can be specified instead of parse_mode
@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 ( ALLOWSENDINGWITHOUTREPLY_FIELD )
private Boolean allowSendingWithoutReply ; ///< Optional. Pass True, if the message should be sent even if the specified replied-to message is not found
/ * *
* Optional .
*
* Additional interface options .
* A JSON - serialized object for an inline keyboard , custom reply keyboard , instructions to remove reply keyboard or
* to force a reply from the user .
* /
@JsonProperty ( REPLYMARKUP_FIELD )
@JsonDeserialize ( )
private ReplyKeyboard replyMarkup ;
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
2020-11-01 23:46:36 +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 ( ) ;
}
2020-11-01 23:46:36 +01:00
public void enableNotification ( ) {
this . disableNotification = null ;
}
public void disableNotification ( ) {
this . disableNotification = true ;
}
public void enableMarkdown ( boolean enable ) {
if ( enable ) {
this . parseMode = ParseMode . MARKDOWN ;
} else {
this . parseMode = null ;
}
}
public void enableHtml ( boolean enable ) {
if ( enable ) {
this . parseMode = ParseMode . HTML ;
} else {
this . parseMode = null ;
}
}
public void enableMarkdownV2 ( boolean enable ) {
if ( enable ) {
this . parseMode = ParseMode . MARKDOWNV2 ;
} else {
this . parseMode = null ;
}
}
@Override
public String getMethod ( ) {
return PATH ;
}
@Override
public MessageId deserializeResponse ( String answer ) throws TelegramApiRequestException {
2022-06-16 19:36:20 +02:00
return deserializeResponse ( answer , MessageId . class ) ;
2020-11-01 23:46:36 +01:00
}
@Override
public void validate ( ) throws TelegramApiValidationException {
2022-06-14 22:20:22 +02:00
if ( chatId . isEmpty ( ) ) {
2020-11-01 23:46:36 +01:00
throw new TelegramApiValidationException ( " ChatId parameter can't be empty " , this ) ;
}
if ( parseMode ! = null & & ( captionEntities ! = null & & ! captionEntities . isEmpty ( ) ) ) {
throw new TelegramApiValidationException ( " Parse mode can't be enabled if Entities are provided " , this ) ;
}
if ( replyMarkup ! = null ) {
replyMarkup . validate ( ) ;
}
}
2022-06-14 22:20:22 +02:00
public static class CopyMessageBuilder {
@Tolerate
public CopyMessageBuilder chatId ( @NonNull Long chatId ) {
this . chatId = chatId . toString ( ) ;
return this ;
}
@Tolerate
public CopyMessageBuilder fromChatId ( @NonNull Long fromChatId ) {
this . fromChatId = fromChatId . toString ( ) ;
return this ;
}
}
2020-11-01 23:46:36 +01:00
}