From 83be2c698cc3adcddb4f2be386622621dd146419 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 25 Jul 2024 18:09:09 +0300 Subject: [PATCH] Add td_api::telegramPaymentPurposeJoinChat. --- td/generate/scheme/td_api.tl | 3 +++ td/telegram/Payments.cpp | 14 ++++++++++++++ td/telegram/cli.cpp | 12 +++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 7aa1f6c1b..a8b3b4d07 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -5715,6 +5715,9 @@ telegramPaymentPurposeStars currency:string amount:int53 star_count:int53 = Tele //@star_count Number of bought Telegram Stars telegramPaymentPurposeGiftedStars user_id:int53 currency:string amount:int53 star_count:int53 = TelegramPaymentPurpose; +//@description The user joins a chat and subscribes to regular Payments in Telegram Stars @invite_link Invite link to use +telegramPaymentPurposeJoinChat invite_link:string = TelegramPaymentPurpose; + //@class DeviceToken @description Represents a data needed to subscribe for push notifications through registerDevice method. //-To use specific push notification service, the correct application platform must be specified and a valid server authentication data must be uploaded at https://my.telegram.org diff --git a/td/telegram/Payments.cpp b/td/telegram/Payments.cpp index db033671c..b560a6c4a 100644 --- a/td/telegram/Payments.cpp +++ b/td/telegram/Payments.cpp @@ -8,10 +8,12 @@ #include "td/telegram/AccessRights.h" #include "td/telegram/DialogId.h" +#include "td/telegram/DialogInviteLink.h" #include "td/telegram/DialogManager.h" #include "td/telegram/GiveawayParameters.h" #include "td/telegram/Global.h" #include "td/telegram/InputInvoice.h" +#include "td/telegram/LinkManager.h" #include "td/telegram/MessageEntity.h" #include "td/telegram/MessageId.h" #include "td/telegram/MessagesManager.h" @@ -151,6 +153,18 @@ Result get_input_invoice_info(Td *td, td_api::object_ptr(std::move(purpose)); break; } + case td_api::telegramPaymentPurposeJoinChat::ID: { + auto p = static_cast(invoice->purpose_.get()); + if (!DialogInviteLink::is_valid_invite_link(p->invite_link_)) { + return Status::Error(400, "Invalid invite link"); + } + auto hash = LinkManager::get_dialog_invite_link_hash(p->invite_link_); + if (!clean_input_string(hash)) { + return Status::Error(400, "Invalid invite link"); + } + result.input_invoice_ = telegram_api::make_object(hash); + break; + } default: UNREACHABLE(); } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index efd91a8f0..3935951f6 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1015,12 +1015,16 @@ class CliClient final : public Actor { int64 chat_id = 0; int64 message_id = 0; string invoice_name; + string invite_link; operator td_api::object_ptr() const { - if (invoice_name.empty()) { - return td_api::make_object(chat_id, message_id); - } else { + if (!invite_link.empty()) { + return td_api::make_object( + td_api::make_object(invite_link)); + } else if (!invoice_name.empty()) { return td_api::make_object(invoice_name); + } else { + return td_api::make_object(chat_id, message_id); } } }; @@ -1028,6 +1032,8 @@ class CliClient final : public Actor { void get_args(string &args, InputInvoice &arg) const { if (args.size() > 1 && (args[0] == '#' || args[0] == '$')) { arg.invoice_name = args.substr(1); + } else if (args[0] == '+' || begins_with(args, "https://t.me/+")) { + arg.invite_link = args; } else { string chat_id; string message_id;