Add td_api::getStarAdAccountUrl.

This commit is contained in:
levlam 2024-06-24 20:45:55 +03:00
parent 9061e9f2b1
commit 60d3130193
6 changed files with 73 additions and 6 deletions

View File

@ -10759,7 +10759,7 @@ reportMessageReactions chat_id:int53 message_id:int53 sender_id:MessageSender =
//@description Returns detailed revenue statistics about a chat. Currently, this method can be used only for channels if supergroupFullInfo.can_get_revenue_statistics == true @chat_id Chat identifier @is_dark Pass true if a dark theme is used by the application
getChatRevenueStatistics chat_id:int53 is_dark:Bool = ChatRevenueStatistics;
//@description Returns URL for chat revenue withdrawal; requires owner privileges in the chat. Currently, this method can be used only for channels if supergroupFullInfo.can_get_revenue_statistics == true and getOption("can_withdraw_chat_revenue")
//@description Returns a URL for chat revenue withdrawal; requires owner privileges in the chat. Currently, this method can be used only for channels if supergroupFullInfo.can_get_revenue_statistics == true and getOption("can_withdraw_chat_revenue")
//@chat_id Chat identifier
//@password The 2-step verification password of the current user
getChatRevenueWithdrawalUrl chat_id:int53 password:string = HttpUrl;
@ -10772,16 +10772,20 @@ getChatRevenueTransactions chat_id:int53 offset:int32 limit:int32 = ChatRevenueT
//@description Returns detailed Telegram star revenue statistics
//@owner_id Identifier of the owner of the Telegram stars; can be identifier of an owned bot, or identifier of a channel chat with supergroupFullInfo.can_get_revenue_statistics == true
//@owner_id Identifier of the owner of the Telegram stars; can be identifier of an owned bot, or identifier of an owned channel chat
//@is_dark Pass true if a dark theme is used by the application
getStarRevenueStatistics owner_id:MessageSender is_dark:Bool = StarRevenueStatistics;
//@description Returns URL for Telegram star withdrawal
//@owner_id Identifier of the owner of the Telegram stars; can be identifier of an owned bot, or identifier of a channel chat with supergroupFullInfo.can_get_revenue_statistics == true
//@description Returns a URL for Telegram star withdrawal
//@owner_id Identifier of the owner of the Telegram stars; can be identifier of an owned bot, or identifier of an owned channel chat
//@star_count The number of Telegram stars to withdraw. Must be at least getOption("star_withdrawal_count_min")
//@password The 2-step verification password of the current user
getStarWithdrawalUrl owner_id:MessageSender star_count:int53 password:string = HttpUrl;
//@description Returns a URL for a Telegram Ad platform account that can be used to set up advertisments for the chat paid in the owned Telegram stars
//@owner_id Identifier of the owner of the Telegram stars; can be identifier of an owned bot, or identifier of an owned channel chat
getStarAdAccountUrl owner_id:MessageSender = HttpUrl;
//@description Returns detailed statistics about a chat. Currently, this method can be used only for supergroups and channels. Can be used only if supergroupFullInfo.can_get_statistics == true @chat_id Chat identifier @is_dark Pass true if a dark theme is used by the application
getChatStatistics chat_id:int53 is_dark:Bool = ChatStatistics;

View File

@ -361,6 +361,41 @@ class GetStarsRevenueWithdrawalUrlQuery final : public Td::ResultHandler {
}
};
class GetStarsRevenueAdsAccountUrlQuery final : public Td::ResultHandler {
Promise<string> promise_;
DialogId dialog_id_;
public:
explicit GetStarsRevenueAdsAccountUrlQuery(Promise<string> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id) {
dialog_id_ = dialog_id;
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return on_error(Status::Error(400, "Have no access to the chat"));
}
send_query(
G()->net_query_creator().create(telegram_api::payments_getStarsRevenueAdsAccountUrl(std::move(input_peer))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_getStarsRevenueAdsAccountUrl>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
promise_.set_value(std::move(result_ptr.ok_ref()->url_));
}
void on_error(Status status) final {
td_->dialog_manager_->on_get_dialog_error(dialog_id_, status, "GetStarsRevenueAdsAccountUrlQuery");
promise_.set_error(std::move(status));
}
};
StarManager::StarManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
}
@ -386,8 +421,8 @@ Status StarManager::can_manage_stars(DialogId dialog_id, bool allow_self) const
if (!td_->chat_manager_->is_broadcast_channel(channel_id)) {
return Status::Error(400, "Chat is not a channel");
}
if (!td_->chat_manager_->get_channel_permissions(channel_id).is_creator()) {
return Status::Error(400, "Not enough rights to withdraw stars");
if (!td_->chat_manager_->get_channel_permissions(channel_id).is_creator() && !allow_self) {
return Status::Error(400, "Not enough rights");
}
break;
}
@ -455,6 +490,13 @@ void StarManager::send_get_star_withdrawal_url_query(
->send(dialog_id, star_count, std::move(input_check_password));
}
void StarManager::get_star_ad_account_url(const td_api::object_ptr<td_api::MessageSender> &owner_id,
Promise<string> &&promise) {
TRY_RESULT_PROMISE(promise, dialog_id, get_message_sender_dialog_id(td_, owner_id, true, false));
TRY_STATUS_PROMISE(promise, can_manage_stars(dialog_id));
td_->create_handler<GetStarsRevenueAdsAccountUrlQuery>(std::move(promise))->send(dialog_id);
}
void StarManager::on_update_stars_revenue_status(
telegram_api::object_ptr<telegram_api::updateStarsRevenueStatus> &&update) {
DialogId dialog_id(update->peer_);

View File

@ -39,6 +39,8 @@ class StarManager final : public Actor {
void get_star_withdrawal_url(const td_api::object_ptr<td_api::MessageSender> &owner_id, int64 star_count,
const string &password, Promise<string> &&promise);
void get_star_ad_account_url(const td_api::object_ptr<td_api::MessageSender> &owner_id, Promise<string> &&promise);
void on_update_stars_revenue_status(telegram_api::object_ptr<telegram_api::updateStarsRevenueStatus> &&update);
static int64 get_star_count(int64 amount, bool allow_negative = false);

View File

@ -8754,6 +8754,19 @@ void Td::on_request(uint64 id, const td_api::getStarWithdrawalUrl &request) {
std::move(query_promise));
}
void Td::on_request(uint64 id, const td_api::getStarAdAccountUrl &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<string> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(td_api::make_object<td_api::httpUrl>(result.move_as_ok()));
}
});
star_manager_->get_star_ad_account_url(request.owner_id_, std::move(query_promise));
}
void Td::on_request(uint64 id, const td_api::getMessageStatistics &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();

View File

@ -1701,6 +1701,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getStarWithdrawalUrl &request);
void on_request(uint64 id, const td_api::getStarAdAccountUrl &request);
void on_request(uint64 id, const td_api::getMessageStatistics &request);
void on_request(uint64 id, const td_api::getStoryStatistics &request);

View File

@ -6792,6 +6792,10 @@ class CliClient final : public Actor {
get_args(args, owner_id, star_count, password);
send_request(
td_api::make_object<td_api::getStarWithdrawalUrl>(as_message_sender(owner_id), star_count, password));
} else if (op == "gsaau") {
string owner_id;
get_args(args, owner_id);
send_request(td_api::make_object<td_api::getStarAdAccountUrl>(as_message_sender(owner_id)));
} else {
op_not_found_count++;
}