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

104 lines
3.1 KiB
Java
Raw Normal View History

2018-07-08 01:41:21 +02:00
package org.telegram.telegrambots.meta.api.methods.send;
2016-01-14 01:14:53 +01:00
import com.fasterxml.jackson.annotation.JsonIgnore;
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;
2018-07-08 01:41:21 +02:00
import org.telegram.telegrambots.meta.api.methods.ActionType;
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;
2016-01-14 01:14:53 +01:00
/**
* @author Ruben Bermudez
* @version 1.0
2017-05-03 01:40:55 +02:00
* Use this method when you need to tell the user that something is happening on the bot's
2016-04-11 02:53:53 +02:00
* side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram
* clients clear its typing status).
2016-01-14 01:14:53 +01:00
*/
2020-11-01 23:46:36 +01:00
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
@ToString
2023-05-30 03:33:18 +02:00
@NoArgsConstructor(force = true)
2020-11-01 23:46:36 +01:00
@AllArgsConstructor
@Builder
2022-06-16 19:36:20 +02:00
public class SendChatAction extends BotApiMethodBoolean {
2016-01-14 01:14:53 +01:00
public static final String PATH = "sendChatAction";
public static final String CHATID_FIELD = "chat_id";
2019-06-08 21:33:28 +02:00
private static final String ACTION_FIELD = "action";
2022-12-31 02:18:03 +01:00
private static final String MESSAGETHREADID_FIELD = "message_thread_id";
@JsonProperty(CHATID_FIELD)
2020-11-01 23:46:36 +01:00
@NonNull
2016-04-02 18:20:49 +02:00
private String chatId; ///< Unique identifier for the chat to send the message to (Or username for channels)
2016-01-14 01:14:53 +01:00
/**
2021-11-06 15:52:47 +01:00
* Type of action to broadcast. Choose one, depending on what the user is about to receive:
* typing for text messages
* upload_photo for photos
* record_video or upload_video for videos
* record_voice or upload_voice for voice notes
* upload_document for general files
* choose_sticker for stickers
* find_location for location data
* record_video_note
* upload_video_note for video notes
2016-01-14 01:14:53 +01:00
*/
@JsonProperty(ACTION_FIELD)
2020-11-01 23:46:36 +01:00
@NonNull
private String action;
2022-12-31 02:18:03 +01:00
/**
* Optional
* Unique identifier for the target message thread; supergroups only
*/
@JsonProperty(MESSAGETHREADID_FIELD)
private Integer messageThreadId;
2022-06-14 22:20:22 +02:00
@Tolerate
public void setChatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
}
@JsonIgnore
2020-11-01 23:46:36 +01:00
public ActionType getActionType() {
return ActionType.get(action);
}
@JsonIgnore
2020-11-01 23:46:36 +01:00
public void setAction(ActionType action) {
this.action = action.toString();
2016-06-20 21:33:14 +02:00
}
2016-01-14 01:14:53 +01:00
@Override
public String getMethod() {
2016-01-14 01:14:53 +01:00
return PATH;
}
@Override
public void validate() throws TelegramApiValidationException {
2021-11-06 15:52:47 +01:00
if (chatId.isEmpty()) {
throw new TelegramApiValidationException("ChatId parameter can't be empty", this);
}
2021-11-06 15:52:47 +01:00
if (action.isEmpty()) {
throw new TelegramApiValidationException("Action parameter can't be empty", this);
}
}
2022-06-14 22:20:22 +02:00
public static class SendChatActionBuilder {
@Tolerate
public SendChatActionBuilder chatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
return this;
}
}
2016-01-14 01:14:53 +01:00
}