-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7f4a74
commit 68a6f61
Showing
21 changed files
with
420 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...m/telegrambots/meta/api/methods/groupadministration/CreateChatSubscriptionInviteLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package org.telegram.telegrambots.meta.api.methods.groupadministration; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import lombok.experimental.SuperBuilder; | ||
import lombok.experimental.Tolerate; | ||
import lombok.extern.jackson.Jacksonized; | ||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; | ||
import org.telegram.telegrambots.meta.api.objects.ChatInviteLink; | ||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; | ||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; | ||
|
||
/** | ||
* @author Ruben Bermudez | ||
* @version 7.9 | ||
* | ||
* Use this method to create a subscription invite link for a channel chat. | ||
* Returns the new invite link as a ChatInviteLink object. | ||
* | ||
* @apiNote The bot must have can_invite_users administrator rights. | ||
* @apiNote The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink. | ||
*/ | ||
@EqualsAndHashCode(callSuper = false) | ||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@RequiredArgsConstructor | ||
@SuperBuilder | ||
@Jacksonized | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class CreateChatSubscriptionInviteLink extends BotApiMethod<ChatInviteLink> { | ||
public static final String PATH = "createChatSubscriptionInviteLink"; | ||
|
||
private static final String CHAT_ID_FIELD = "chat_id"; | ||
private static final String SUBSCRIPTION_PERIOD_FIELD = "subscription_period"; | ||
private static final String SUBSCRIPTION_PRICE_FIELD = "subscription_price"; | ||
private static final String NAME_FIELD = "name"; | ||
|
||
/** | ||
* Unique identifier for the target channel chat or username of the target channel (in the format @channelusername) | ||
*/ | ||
@JsonProperty(CHAT_ID_FIELD) | ||
@NonNull | ||
private String chatId; | ||
/** | ||
* The number of seconds the subscription will be active for before the next payment. | ||
* Currently, it must always be 2592000 (30 days). | ||
*/ | ||
@JsonProperty(SUBSCRIPTION_PERIOD_FIELD) | ||
@NonNull | ||
@Builder.Default | ||
private Integer subscriptionPeriod = 2592000; | ||
/** | ||
* The amount of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat; 1-2500 | ||
*/ | ||
@JsonProperty(SUBSCRIPTION_PRICE_FIELD) | ||
@NonNull | ||
private Integer subscriptionPrice; | ||
/** | ||
* Optional | ||
* Invite link name; 0-32 characters | ||
*/ | ||
@JsonProperty(NAME_FIELD) | ||
private String name; | ||
|
||
@Tolerate | ||
public void setChatId(@NonNull Long chatId) { | ||
this.chatId = chatId.toString(); | ||
} | ||
|
||
@Override | ||
public String getMethod() { | ||
return PATH; | ||
} | ||
|
||
@Override | ||
public ChatInviteLink deserializeResponse(String answer) throws TelegramApiRequestException { | ||
return deserializeResponse(answer, ChatInviteLink.class); | ||
} | ||
|
||
@Override | ||
public void validate() throws TelegramApiValidationException { | ||
if (chatId.isEmpty()) { | ||
throw new TelegramApiValidationException("ChatId can't be empty", this); | ||
} | ||
if (name != null && name.length() > 32) { | ||
throw new TelegramApiValidationException("Name must be between 0 and 32 characters", this); | ||
} | ||
if (subscriptionPeriod != 2592000) { | ||
throw new TelegramApiValidationException("SubscriptionPeriod must be 2592000", this); | ||
} | ||
if (subscriptionPrice < 1 || subscriptionPrice > 2500) { | ||
throw new TelegramApiValidationException("SubscriptionPrice must be between 1 and 2500", this); | ||
} | ||
} | ||
|
||
public static abstract class CreateChatSubscriptionInviteLinkBuilder<C extends CreateChatSubscriptionInviteLink, B extends CreateChatSubscriptionInviteLinkBuilder<C, B>> extends BotApiMethodBuilder<ChatInviteLink, C, B> { | ||
@Tolerate | ||
public CreateChatSubscriptionInviteLinkBuilder<C, B> chatId(@NonNull Long chatId) { | ||
this.chatId = chatId.toString(); | ||
return this; | ||
} | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
...ram/telegrambots/meta/api/methods/groupadministration/EditChatSubscriptionInviteLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package org.telegram.telegrambots.meta.api.methods.groupadministration; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import lombok.experimental.SuperBuilder; | ||
import lombok.experimental.Tolerate; | ||
import lombok.extern.jackson.Jacksonized; | ||
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethod; | ||
import org.telegram.telegrambots.meta.api.objects.ChatInviteLink; | ||
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; | ||
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException; | ||
|
||
/** | ||
* @author Ruben Bermudez | ||
* @version 7.9 | ||
* | ||
* Use this method to edit a subscription invite link created by the bot. | ||
* Returns the edited invite link as a ChatInviteLink object. | ||
* | ||
* @apiNote The bot must have can_invite_users administrator rights. | ||
*/ | ||
@EqualsAndHashCode(callSuper = false) | ||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@RequiredArgsConstructor | ||
@SuperBuilder | ||
@Jacksonized | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class EditChatSubscriptionInviteLink extends BotApiMethod<ChatInviteLink> { | ||
public static final String PATH = "editChatSubscriptionInviteLink"; | ||
|
||
private static final String CHAT_ID_FIELD = "chat_id"; | ||
private static final String INVITE_LINK_FIELD = "invite_link"; | ||
private static final String NAME_FIELD = "name"; | ||
|
||
/** | ||
* Unique identifier for the target chat or username of the target channel (in the format @channelusername) | ||
*/ | ||
@JsonProperty(CHAT_ID_FIELD) | ||
@NonNull | ||
private String chatId; | ||
/** | ||
* The number of seconds the subscription will be active for before the next payment. | ||
* Currently, it must always be 2592000 (30 days). | ||
*/ | ||
@JsonProperty(INVITE_LINK_FIELD) | ||
@NonNull | ||
private String inviteLink; | ||
/** | ||
* Optional | ||
* Invite link name; 0-32 characters | ||
*/ | ||
@JsonProperty(NAME_FIELD) | ||
private String name; | ||
|
||
@Tolerate | ||
public void setChatId(@NonNull Long chatId) { | ||
this.chatId = chatId.toString(); | ||
} | ||
|
||
@Override | ||
public String getMethod() { | ||
return PATH; | ||
} | ||
|
||
@Override | ||
public ChatInviteLink deserializeResponse(String answer) throws TelegramApiRequestException { | ||
return deserializeResponse(answer, ChatInviteLink.class); | ||
} | ||
|
||
@Override | ||
public void validate() throws TelegramApiValidationException { | ||
if (chatId.isEmpty()) { | ||
throw new TelegramApiValidationException("ChatId can't be empty", this); | ||
} | ||
if (name != null && name.length() > 32) { | ||
throw new TelegramApiValidationException("Name must be between 0 and 32 characters", this); | ||
} | ||
if (inviteLink.isEmpty()) { | ||
throw new TelegramApiValidationException("InviteLink must not be empty", this); | ||
} | ||
} | ||
|
||
public static abstract class EditChatSubscriptionInviteLinkBuilder<C extends EditChatSubscriptionInviteLink, B extends EditChatSubscriptionInviteLinkBuilder<C, B>> extends BotApiMethodBuilder<ChatInviteLink, C, B> { | ||
@Tolerate | ||
public EditChatSubscriptionInviteLinkBuilder<C, B> chatId(@NonNull Long chatId) { | ||
this.chatId = chatId.toString(); | ||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.