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

82 lines
2.5 KiB
Java
Raw Normal View History

2018-07-08 01:41:21 +02:00
package org.telegram.telegrambots.meta.api.methods.updatingmessages;
2017-05-03 01:40:55 +02: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.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.BotApiMethodBoolean;
2018-07-08 01:41:21 +02:00
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
2017-05-03 01:40:55 +02:00
/**
* @author Ruben Bermudez
* @version 1.0
*
2019-04-08 02:43:46 +02:00
* 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.
2022-11-08 19:33:50 +01:00
* - Service messages about a supergroup, channel, or forum topic creation can't be deleted
2019-04-08 02:43:46 +02:00
* Returns True on success.
2017-05-03 01:40:55 +02:00
*/
2020-11-01 23:46:36 +01:00
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
2022-06-16 19:36:20 +02:00
public class DeleteMessage extends BotApiMethodBoolean {
2017-05-03 01:40:55 +02:00
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)
2020-11-01 23:46:36 +01:00
@NonNull
2017-05-03 01:40:55 +02:00
private String chatId;
/**
* Identifier of the message to delete
*/
@JsonProperty(MESSAGEID_FIELD)
2020-11-01 23:46:36 +01:00
@NonNull
2017-05-03 01:40:55 +02:00
private Integer messageId;
2022-06-14 22:20:22 +02:00
@Tolerate
public void setChatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
}
2017-05-03 01:40:55 +02:00
@Override
public String getMethod() {
return PATH;
}
@Override
public void validate() throws TelegramApiValidationException {
2022-06-14 22:20:22 +02:00
if (chatId.isEmpty()) {
2017-05-03 01:40:55 +02:00
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
2022-06-14 22:20:22 +02:00
}
public static class DeleteMessageBuilder {
@Tolerate
public DeleteMessageBuilder chatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
return this;
2017-05-03 01:40:55 +02:00
}
}
}