All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.orgyflame.springtelegrambotapi.api.method.groupadministration.EditChatInviteLink Maven / Gradle / Ivy

package com.orgyflame.springtelegrambotapi.api.method.groupadministration;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.base.Strings;
import com.orgyflame.springtelegrambotapi.api.method.BotApiMethod;
import com.orgyflame.springtelegrambotapi.api.object.ApiResponse;
import com.orgyflame.springtelegrambotapi.api.object.ChatInviteLink;
import com.orgyflame.springtelegrambotapi.exceptions.TelegramApiRequestException;
import com.orgyflame.springtelegrambotapi.exceptions.TelegramApiValidationException;
import lombok.*;

import java.io.IOException;

/**
 * @author Ruben Bermudez
 * @version 5.1
 * 

* Use this method to edit a non-primary invite link created by the bot. *

* The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. *

* Returns the edited invite link as a ChatInviteLink object. */ @EqualsAndHashCode(callSuper = false) @Getter @Setter @ToString @NoArgsConstructor @AllArgsConstructor @RequiredArgsConstructor @Builder public class EditChatInviteLink extends BotApiMethod { public static final String PATH = "editChatInviteLink"; private static final String CHATID_FIELD = "chat_id"; private static final String INVITELINK_FIELD = "invite_link"; private static final String EXPIREDATE_FIELD = "expire_date"; private static final String MEMBERLIMIT_FIELD = "member_limit"; @JsonProperty(CHATID_FIELD) @NonNull private String chatId; ///< Unique identifier for the target chat or username of the target channel (in the format @channelusername) @JsonProperty(INVITELINK_FIELD) @NonNull private String inviteLink; ///< The invite link to edit @JsonProperty(EXPIREDATE_FIELD) private Integer expireDate; ///< Optional. Point in time (Unix timestamp) when the link will expire /** * Optional. *

* Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999 */ @JsonProperty(MEMBERLIMIT_FIELD) private Integer memberLimit; @Override public String getMethod() { return PATH; } @Override public ChatInviteLink deserializeResponse(String answer) throws TelegramApiRequestException { try { ApiResponse result = OBJECT_MAPPER.readValue(answer, new TypeReference>() { }); if (result.getOk()) { return result.getResult(); } else { throw new TelegramApiRequestException("Error creating invite link", result); } } catch (IOException e) { throw new TelegramApiRequestException("Unable to deserialize response", e); } } @Override public void validate() throws TelegramApiValidationException { if (Strings.isNullOrEmpty(chatId)) { throw new TelegramApiValidationException("ChatId can't be empty", this); } if (Strings.isNullOrEmpty(inviteLink)) { throw new TelegramApiValidationException("InviteLink can't be empty", this); } if (memberLimit != null && (memberLimit < 1 || memberLimit > 99999)) { throw new TelegramApiValidationException("MemberLimit must be between 1 and 99999", this); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy