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

78 lines
2.6 KiB
Java
Raw Normal View History

2018-07-08 01:41:21 +02:00
package org.telegram.telegrambots.meta.api.methods.groupadministration;
2017-06-30 14:15:48 +02:00
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.PartialBotApiMethod;
2020-11-01 23:46:36 +01:00
import org.telegram.telegrambots.meta.api.objects.InputFile;
2018-07-08 01:41:21 +02:00
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException;
2017-06-30 14:15:48 +02:00
/**
* @author Ruben Bermudez
* @version 3.1
* Use this method to set a new profile photo for the chat. Photos can't be changed for private chats.
* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
* Returns True on success.
*
* @apiNote In regular groups (non-supergroups), this method will only work if the All Members Are Admins setting is off in the target group.
*/
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
2017-06-30 14:15:48 +02:00
public class SetChatPhoto extends PartialBotApiMethod<Boolean> {
public static final String PATH = "setChatPhoto";
public static final String CHATID_FIELD = "chat_id";
public static final String PHOTO_FIELD = "photo";
2020-11-01 23:46:36 +01:00
@NonNull
2017-06-30 14:15:48 +02:00
private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername)
2020-11-01 23:46:36 +01:00
@NonNull
private InputFile photo; ///< New chat photo as InputStream, uploaded using multipart/form-data
2017-06-30 14:15:48 +02:00
2022-06-14 22:20:22 +02:00
@Tolerate
public void setChatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
}
@Override
public String getMethod() {
return PATH;
}
2017-06-30 14:15:48 +02:00
@Override
public Boolean deserializeResponse(String answer) throws TelegramApiRequestException {
2022-06-16 19:36:20 +02:00
return deserializeResponse(answer, Boolean.class);
2017-06-30 14:15:48 +02:00
}
@Override
public void validate() throws TelegramApiValidationException {
2022-06-14 22:20:22 +02:00
if (chatId.isEmpty()) {
2017-06-30 14:15:48 +02:00
throw new TelegramApiValidationException("ChatId can't be empty", this);
}
2022-06-14 22:20:22 +02:00
if (!photo.isNew()) {
2020-11-01 23:46:36 +01:00
throw new TelegramApiValidationException("Photo parameter is required and must be a new file to upload", this);
2017-06-30 14:15:48 +02:00
}
}
2022-06-14 22:20:22 +02:00
public static class SetChatPhotoBuilder {
@Tolerate
public SetChatPhotoBuilder chatId(@NonNull Long chatId) {
this.chatId = chatId.toString();
return this;
}
}
2017-06-30 14:15:48 +02:00
}