Add td_api::launchPrepaidPremiumGiveaway.

This commit is contained in:
levlam 2023-10-12 18:19:08 +03:00
parent 2a46d463e0
commit 5d80e3db72
7 changed files with 68 additions and 4 deletions

View File

@ -2296,8 +2296,8 @@ messageExtendedMediaUnsupported caption:formattedText = MessageExtendedMedia;
//@description Describes parameters of a Telegram Premium giveaway
//@boosted_chat_id Identifier of the channel chat, which will be automatically boosted by the winners of the giveaway for duration of the Premium subscription
//@additional_chat_ids Identifiers of other channel chats that must be subscribed by the users to be eligible for the giveaway
//@date Point in time (Unix timestamp) when the giveaway will be performed; must be from 1 minute to 365 days in the future
//@only_new_subscribers Pass true if only new subscribers of the chats will be eligible for the giveaway
//@date Point in time (Unix timestamp) when the giveaway will be performed; must be from 1 minute to 365 days in the future in scheduled giveaways
//@only_new_subscribers True, if only new subscribers of the chats will be eligible for the giveaway
premiumGiveawayParameters boosted_chat_id:int53 additional_chat_ids:vector<int53> date:int32 only_new_subscribers:Bool = PremiumGiveawayParameters;
@ -4478,7 +4478,7 @@ storePaymentPurposeGiftedPremium user_id:int53 currency:string amount:int53 = St
//@user_ids Identifiers of the users which can activate the gift codes
storePaymentPurposePremiumGiftCodes boosted_chat_id:int53 currency:string amount:int53 user_ids:vector<int53> = StorePaymentPurpose;
//@description The user creating a Telegram Premium giveaway for subscribers of a channel chat
//@description The user creating a Telegram Premium giveaway for subscribers of channel chats; requires can_post_messages rights in the channels
//@parameters Giveaway parameters
//@currency ISO 4217 currency code of the payment currency
//@amount Paid amount, in the smallest units of the currency
@ -4495,7 +4495,7 @@ storePaymentPurposePremiumGiveaway parameters:premiumGiveawayParameters currency
//@month_count Number of month the Telegram Premium subscription will be active for the users
telegramPaymentPurposePremiumGiftCodes boosted_chat_id:int53 currency:string amount:int53 user_ids:vector<int53> month_count:int32 = TelegramPaymentPurpose;
//@description The user creating a Telegram Premium giveaway for subscribers of a channel chat
//@description The user creating a Telegram Premium giveaway for subscribers of channel chats; requires can_post_messages rights in the channels
//@parameters Giveaway parameters
//@currency ISO 4217 currency code of the payment currency
//@amount Paid amount, in the smallest units of the currency
@ -9155,6 +9155,11 @@ checkPremiumGiftCode code:string = PremiumGiftCodeInfo;
//@description Applies a Telegram Premium gift code @code The code to apply
applyPremiumGiftCode code:string = Ok;
//@description Launches a prepaid Telegram Premium giveaway for subscribers of channel chats; requires can_post_messages rights in the channels
//@giveaway_id Unique identifier of the prepaid giveaway
//@parameters Giveaway parameters
launchPrepaidPremiumGiveaway giveaway_id:int64 parameters:premiumGiveawayParameters = Ok;
//@description Returns information about a Telegram Premium giveaway
//@chat_id Identifier of the channel chat which started the giveaway
//@message_id Identifier of the giveaway message in the chat

View File

@ -57,6 +57,10 @@ class GiveawayParameters {
return boosted_channel_id_.is_valid() && date_ > 0;
}
DialogId get_boosted_dialog_id() const {
return DialogId(boosted_channel_id_);
}
void add_dependencies(Dependencies &dependencies) const;
telegram_api::object_ptr<telegram_api::inputStorePaymentPremiumGiveaway> get_input_store_payment_premium_giveaway(

View File

@ -373,6 +373,37 @@ class ApplyGiftCodeQuery final : public Td::ResultHandler {
}
};
class LaunchPrepaidGiveawayQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit LaunchPrepaidGiveawayQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(int64 giveaway_id, const GiveawayParameters &parameters) {
auto dialog_id = parameters.get_boosted_dialog_id();
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
CHECK(input_peer != nullptr);
send_query(G()->net_query_creator().create(telegram_api::payments_launchPrepaidGiveaway(
std::move(input_peer), giveaway_id, parameters.get_input_store_payment_premium_giveaway(td_, string(), 0))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_launchPrepaidGiveaway>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for LaunchPrepaidGiveawayQuery: " << to_string(ptr);
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class GetGiveawayInfoQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::PremiumGiveawayInfo>> promise_;
DialogId dialog_id_;
@ -901,6 +932,13 @@ void apply_premium_gift_code(Td *td, const string &code, Promise<Unit> &&promise
td->create_handler<ApplyGiftCodeQuery>(std::move(promise))->send(code);
}
void launch_prepaid_premium_giveaway(Td *td, int64 giveaway_id,
td_api::object_ptr<td_api::premiumGiveawayParameters> &&parameters,
Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, giveaway_parameters, GiveawayParameters::get_giveaway_parameters(td, parameters.get()));
td->create_handler<LaunchPrepaidGiveawayQuery>(std::move(promise))->send(giveaway_id, giveaway_parameters);
}
void get_premium_giveaway_info(Td *td, MessageFullId message_full_id,
Promise<td_api::object_ptr<td_api::PremiumGiveawayInfo>> &&promise) {
TRY_RESULT_PROMISE(promise, server_message_id, td->messages_manager_->get_giveaway_message_id(message_full_id));

View File

@ -44,6 +44,10 @@ void check_premium_gift_code(Td *td, const string &code,
void apply_premium_gift_code(Td *td, const string &code, Promise<Unit> &&promise);
void launch_prepaid_premium_giveaway(Td *td, int64 giveaway_id,
td_api::object_ptr<td_api::premiumGiveawayParameters> &&parameters,
Promise<Unit> &&promise);
void get_premium_giveaway_info(Td *td, MessageFullId message_full_id,
Promise<td_api::object_ptr<td_api::PremiumGiveawayInfo>> &&promise);

View File

@ -8809,6 +8809,12 @@ void Td::on_request(uint64 id, td_api::applyPremiumGiftCode &request) {
apply_premium_gift_code(this, request.code_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::launchPrepaidPremiumGiveaway &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
launch_prepaid_premium_giveaway(this, request.giveaway_id_, std::move(request.parameters_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getPremiumGiveawayInfo &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();

View File

@ -1603,6 +1603,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::applyPremiumGiftCode &request);
void on_request(uint64 id, td_api::launchPrepaidPremiumGiveaway &request);
void on_request(uint64 id, const td_api::getPremiumGiveawayInfo &request);
void on_request(uint64 id, td_api::canPurchasePremium &request);

View File

@ -3127,6 +3127,11 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::checkPremiumGiftCode>(args));
} else if (op == "apgc") {
send_request(td_api::make_object<td_api::applyPremiumGiftCode>(args));
} else if (op == "lppg") {
int64 giveaway_id;
PremiumGiveawayParameters parameters;
get_args(args, giveaway_id, parameters);
send_request(td_api::make_object<td_api::launchPrepaidPremiumGiveaway>(giveaway_id, parameters));
} else if (op == "gpgi") {
ChatId chat_id;
MessageId message_id;