Add td_api::telegramPaymentPurposeJoinChat.

This commit is contained in:
levlam 2024-07-25 18:09:09 +03:00
parent d20a3f1552
commit 83be2c698c
3 changed files with 26 additions and 3 deletions

View File

@ -5715,6 +5715,9 @@ telegramPaymentPurposeStars currency:string amount:int53 star_count:int53 = Tele
//@star_count Number of bought Telegram Stars //@star_count Number of bought Telegram Stars
telegramPaymentPurposeGiftedStars user_id:int53 currency:string amount:int53 star_count:int53 = TelegramPaymentPurpose; 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. //@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 //-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

View File

@ -8,10 +8,12 @@
#include "td/telegram/AccessRights.h" #include "td/telegram/AccessRights.h"
#include "td/telegram/DialogId.h" #include "td/telegram/DialogId.h"
#include "td/telegram/DialogInviteLink.h"
#include "td/telegram/DialogManager.h" #include "td/telegram/DialogManager.h"
#include "td/telegram/GiveawayParameters.h" #include "td/telegram/GiveawayParameters.h"
#include "td/telegram/Global.h" #include "td/telegram/Global.h"
#include "td/telegram/InputInvoice.h" #include "td/telegram/InputInvoice.h"
#include "td/telegram/LinkManager.h"
#include "td/telegram/MessageEntity.h" #include "td/telegram/MessageEntity.h"
#include "td/telegram/MessageId.h" #include "td/telegram/MessageId.h"
#include "td/telegram/MessagesManager.h" #include "td/telegram/MessagesManager.h"
@ -151,6 +153,18 @@ Result<InputInvoiceInfo> get_input_invoice_info(Td *td, td_api::object_ptr<td_ap
result.input_invoice_ = telegram_api::make_object<telegram_api::inputInvoiceStars>(std::move(purpose)); result.input_invoice_ = telegram_api::make_object<telegram_api::inputInvoiceStars>(std::move(purpose));
break; break;
} }
case td_api::telegramPaymentPurposeJoinChat::ID: {
auto p = static_cast<td_api::telegramPaymentPurposeJoinChat *>(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<telegram_api::inputInvoiceChatInviteSubscription>(hash);
break;
}
default: default:
UNREACHABLE(); UNREACHABLE();
} }

View File

@ -1015,12 +1015,16 @@ class CliClient final : public Actor {
int64 chat_id = 0; int64 chat_id = 0;
int64 message_id = 0; int64 message_id = 0;
string invoice_name; string invoice_name;
string invite_link;
operator td_api::object_ptr<td_api::InputInvoice>() const { operator td_api::object_ptr<td_api::InputInvoice>() const {
if (invoice_name.empty()) { if (!invite_link.empty()) {
return td_api::make_object<td_api::inputInvoiceMessage>(chat_id, message_id); return td_api::make_object<td_api::inputInvoiceTelegram>(
} else { td_api::make_object<td_api::telegramPaymentPurposeJoinChat>(invite_link));
} else if (!invoice_name.empty()) {
return td_api::make_object<td_api::inputInvoiceName>(invoice_name); return td_api::make_object<td_api::inputInvoiceName>(invoice_name);
} else {
return td_api::make_object<td_api::inputInvoiceMessage>(chat_id, message_id);
} }
} }
}; };
@ -1028,6 +1032,8 @@ class CliClient final : public Actor {
void get_args(string &args, InputInvoice &arg) const { void get_args(string &args, InputInvoice &arg) const {
if (args.size() > 1 && (args[0] == '#' || args[0] == '$')) { if (args.size() > 1 && (args[0] == '#' || args[0] == '$')) {
arg.invoice_name = args.substr(1); arg.invoice_name = args.substr(1);
} else if (args[0] == '+' || begins_with(args, "https://t.me/+")) {
arg.invite_link = args;
} else { } else {
string chat_id; string chat_id;
string message_id; string message_id;