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

82 lines
2.5 KiB
Java

package org.telegram.telegrambots.meta.api.methods.updatingmessages;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Tolerate;
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
/**
* @author Ruben Bermudez
* @version 1.0
*
* 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.
* - Service messages about a supergroup, channel, or forum topic creation can't be deleted
* Returns True on success.
*/
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DeleteMessage extends BotApiMethodBoolean {
public static final String PATH = "deleteMessage";
private static final String CHATID_FIELD = "chat_id";
private static final String MESSAGEID_FIELD = "message_id";
/**
* Unique identifier for the chat to send the message to (Or username for channels)
*/
@JsonProperty(CHATID_FIELD)
@NonNull
private String chatId;
/**
* Identifier of the message to delete
*/
@JsonProperty(MESSAGEID_FIELD)
@NonNull
private Integer messageId;
@Tolerate
public void setChatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
}
@Override
public String getMethod() {
return PATH;
}
@Override
public void validate() throws TelegramApiValidationException {
if (chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
}
public static class DeleteMessageBuilder {
@Tolerate
public DeleteMessageBuilder chatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
return this;
}
}
}