diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index a1ab5f9aa..e234d6009 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -6544,8 +6544,10 @@ internalLinkTypeBotStartInGroup bot_username:string start_parameter:string admin //@link_name Name of the link internalLinkTypeBusinessChat link_name:string = InternalLinkType; -//@description The link is a link to the Telegram Star purchase section of the application @star_count The number of Telegram Stars that must be purchased by the user -internalLinkTypeBuyStars star_count:int53 = InternalLinkType; +//@description The link is a link to the Telegram Star purchase section of the application +//@star_count The number of Telegram Stars that must be owned by the user +//@purpose Purpose of Telegram Star purchase. Arbitrary string specified by the server, for example, "subs" if the Telegram Stars are required to extend channel subscriptions +internalLinkTypeBuyStars star_count:int53 purpose:string = InternalLinkType; //@description The link is a link to the change phone number section of the application internalLinkTypeChangePhoneNumber = InternalLinkType; diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index 0fd073f82..df50d40b4 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -399,14 +399,15 @@ class LinkManager::InternalLinkBusinessChat final : public InternalLink { class LinkManager::InternalLinkBuyStars final : public InternalLink { int64 star_count_; + string purpose_; td_api::object_ptr get_internal_link_type_object() const final { - return td_api::make_object(star_count_); + return td_api::make_object(star_count_, purpose_); } public: - explicit InternalLinkBuyStars(int64 star_count) - : star_count_(clamp(star_count, static_cast(1), static_cast(1000000000000))) { + explicit InternalLinkBuyStars(int64 star_count, const string &purpose) + : star_count_(clamp(star_count, static_cast(1), static_cast(1000000000000))), purpose_(purpose) { } }; @@ -1559,9 +1560,10 @@ unique_ptr LinkManager::parse_tg_link_query(Slice que // msg_url?url=&text= return get_internal_link_message_draft(get_arg("url"), get_arg("text")); } else if (path.size() == 1 && path[0] == "stars_topup") { - // stars_topup?amount= - if (has_arg("amount")) { - return td::make_unique(to_integer(url_query.get_arg("amount"))); + // stars_topup?balance=&purpose= + if (has_arg("balance")) { + return td::make_unique(to_integer(url_query.get_arg("balance")), + url_query.get_arg("purpose").str()); } } if (!path.empty() && !path[0].empty()) { @@ -2121,7 +2123,7 @@ Result LinkManager::get_internal_link_impl(const td_api::InternalLinkTyp if (link->star_count_ <= 0) { return Status::Error(400, "Invalid Telegram Star number provided"); } - return PSTRING() << "tg://stars_topup?amount=" << link->star_count_; + return PSTRING() << "tg://stars_topup?balance=" << link->star_count_ << "&purpose=" << url_encode(link->purpose_); } case td_api::internalLinkTypeChangePhoneNumber::ID: if (!is_internal) { diff --git a/test/link.cpp b/test/link.cpp index 3be35ff63..4225a2379 100644 --- a/test/link.cpp +++ b/test/link.cpp @@ -224,8 +224,8 @@ static auto business_chat(const td::string &link_name) { return td::td_api::make_object(link_name); } -static auto buy_stars(td::int64 star_count) { - return td::td_api::make_object(star_count); +static auto buy_stars(td::int64 star_count, const td::string &purpose) { + return td::td_api::make_object(star_count, purpose); } static auto change_phone_number() { @@ -1332,10 +1332,10 @@ TEST(Link, parse_internal_link_part4) { parse_internal_link("tg://settings/privacy", privacy_and_security_settings()); parse_internal_link("tg://stars_topup", unknown_deep_link("tg://stars_topup")); - parse_internal_link("tg://stars_topup?amount=", unknown_deep_link("tg://stars_topup?amount=")); - parse_internal_link("tg://stars_topup?amount=test", buy_stars(1)); - parse_internal_link("tg://stars_topup?amount=10", buy_stars(10)); - parse_internal_link("tg://stars_topup?amount=100000000000", buy_stars(100000000000)); + parse_internal_link("tg://stars_topup?balance=", unknown_deep_link("tg://stars_topup?balance=")); + parse_internal_link("tg://stars_topup?balance=test", buy_stars(1, "")); + parse_internal_link("tg://stars_topup?balance=10&purpose=%30test", buy_stars(10, "0test")); + parse_internal_link("tg://stars_topup?balance=100000000000&purpose=subs", buy_stars(100000000000, "subs")); parse_internal_link("username.t.me////0/a//s/as?start=", bot_start("username", "")); parse_internal_link("username.t.me?start=as", bot_start("username", "as"));