Add internalLinkTypeBotStart.autostart.

This commit is contained in:
levlam 2022-07-01 16:21:29 +03:00
parent dd89d46a27
commit 2472e13f7f
7 changed files with 22 additions and 20 deletions

View File

@ -2975,7 +2975,7 @@ premiumFeatureAppIcons = PremiumFeature;
premiumLimit type:PremiumLimitType default_value:int32 premium_value:int32 = PremiumLimit;
//@description Contains information about features, available to Premium users @features The list of available features @limits The list of limits, increased for Premium users
//@payment_link An internal link to be opened to pay for Telegram Premium if store payment isn't possible; may be null if direct payment isn't available. If the link has type internalLinkTypeBotStart, then sendBotStartMessage must be called automatically
//@payment_link An internal link to be opened to pay for Telegram Premium if store payment isn't possible; may be null if direct payment isn't available
premiumFeatures features:vector<PremiumFeature> limits:vector<premiumLimit> payment_link:InternalLinkType = PremiumFeatures;
@ -3597,7 +3597,8 @@ internalLinkTypeBackground background_name:string = InternalLinkType;
//@description The link is a link to a chat with a Telegram bot. Call searchPublicChat with the given bot username, check that the user is a bot, show START button in the chat with the bot,
//-and then call sendBotStartMessage with the given start parameter after the button is pressed
//@bot_username Username of the bot @start_parameter The parameter to be passed to sendBotStartMessage
internalLinkTypeBotStart bot_username:string start_parameter:string = InternalLinkType;
//@autostart True, if sendBotStartMessage must be called automatically without showing the START button
internalLinkTypeBotStart bot_username:string start_parameter:string autostart:Bool = InternalLinkType;
//@description The link is a link to a Telegram bot, which is supposed to be added to a group chat. Call searchPublicChat with the given bot username, check that the user is a bot and can be added to groups,
//-ask the current user to select a basic group or a supergroup chat to add the bot to, taking into account that bots can be added to a public supergroup only by administrators of the supergroup.

View File

@ -250,14 +250,15 @@ class LinkManager::InternalLinkBotAddToChannel final : public InternalLink {
class LinkManager::InternalLinkBotStart final : public InternalLink {
string bot_username_;
string start_parameter_;
bool autostart_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeBotStart>(bot_username_, start_parameter_);
return td_api::make_object<td_api::internalLinkTypeBotStart>(bot_username_, start_parameter_, autostart_);
}
public:
InternalLinkBotStart(string bot_username, string start_parameter)
: bot_username_(std::move(bot_username)), start_parameter_(std::move(start_parameter)) {
InternalLinkBotStart(string bot_username, string start_parameter, bool autostart)
: bot_username_(std::move(bot_username)), start_parameter_(std::move(start_parameter)), autostart_(autostart) {
}
};
@ -918,15 +919,15 @@ LinkManager::LinkInfo LinkManager::get_link_info(Slice link) {
return result;
}
unique_ptr<LinkManager::InternalLink> LinkManager::parse_internal_link(Slice link) {
unique_ptr<LinkManager::InternalLink> LinkManager::parse_internal_link(Slice link, bool is_trusted) {
auto info = get_link_info(link);
if (!info.is_internal_) {
return nullptr;
}
if (info.is_tg_) {
return parse_tg_link_query(info.query_);
return parse_tg_link_query(info.query_, is_trusted);
} else {
return parse_t_me_link_query(info.query_);
return parse_t_me_link_query(info.query_, is_trusted);
}
}
@ -959,7 +960,7 @@ StringBuilder &operator<<(StringBuilder &string_builder, const CopyArg &copy_arg
}
} // namespace
unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice query) {
unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice query, bool is_trusted) {
const auto url_query = parse_url_query(query);
const auto &path = url_query.path_;
@ -997,7 +998,7 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
}
if (arg.first == "start" && is_valid_start_parameter(arg.second)) {
// resolve?domain=<bot_username>&start=<parameter>
return td::make_unique<InternalLinkBotStart>(std::move(username), arg.second);
return td::make_unique<InternalLinkBotStart>(std::move(username), arg.second, is_trusted);
}
if (arg.first == "startgroup" && is_valid_start_parameter(arg.second)) {
// resolve?domain=<bot_username>&startgroup=<parameter>
@ -1178,7 +1179,7 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
return nullptr;
}
unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice query) {
unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice query, bool is_trusted) {
CHECK(query[0] == '/');
const auto url_query = parse_url_query(query);
const auto &path = url_query.path_;
@ -1324,7 +1325,7 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
}
if (arg.first == "start" && is_valid_start_parameter(arg.second)) {
// /<bot_username>?start=<parameter>
return td::make_unique<InternalLinkBotStart>(std::move(username), arg.second);
return td::make_unique<InternalLinkBotStart>(std::move(username), arg.second, is_trusted);
}
if (arg.first == "startgroup" && is_valid_start_parameter(arg.second)) {
// /<bot_username>?startgroup=<parameter>

View File

@ -53,7 +53,7 @@ class LinkManager final : public Actor {
static string get_checked_link(Slice link, bool http_only = false, bool https_only = false);
// checks whether the link is a supported tg or t.me link and parses it
static unique_ptr<InternalLink> parse_internal_link(Slice link);
static unique_ptr<InternalLink> parse_internal_link(Slice link, bool is_trusted = false);
void update_autologin_domains(string autologin_token, vector<string> autologin_domains,
vector<string> url_auth_domains);
@ -124,9 +124,9 @@ class LinkManager final : public Actor {
// returns information about the link
static LinkInfo get_link_info(Slice link);
static unique_ptr<InternalLink> parse_tg_link_query(Slice query);
static unique_ptr<InternalLink> parse_tg_link_query(Slice query, bool is_trusted);
static unique_ptr<InternalLink> parse_t_me_link_query(Slice query);
static unique_ptr<InternalLink> parse_t_me_link_query(Slice query, bool is_trusted);
static unique_ptr<InternalLink> get_internal_link_passport(Slice query,
const vector<std::pair<string, string>> &args);

View File

@ -431,7 +431,7 @@ void get_premium_features(Td *td, const td_api::object_ptr<td_api::PremiumSource
td_api::object_ptr<td_api::InternalLinkType> payment_link;
auto premium_bot_username = G()->shared_config().get_option_string("premium_bot_username");
if (!premium_bot_username.empty()) {
payment_link = td_api::make_object<td_api::internalLinkTypeBotStart>(premium_bot_username, source_str);
payment_link = td_api::make_object<td_api::internalLinkTypeBotStart>(premium_bot_username, source_str, true);
} else {
auto premium_invoice_slug = G()->shared_config().get_option_string("premium_invoice_slug");
if (!premium_invoice_slug.empty()) {

View File

@ -163,7 +163,7 @@ td_api::object_ptr<td_api::sponsoredMessage> SponsoredMessageManager::get_sponso
if (bot_username.empty()) {
break;
}
link = td_api::make_object<td_api::internalLinkTypeBotStart>(bot_username, sponsored_message.start_param);
link = td_api::make_object<td_api::internalLinkTypeBotStart>(bot_username, sponsored_message.start_param, false);
break;
}
case DialogType::Channel:

View File

@ -1315,8 +1315,8 @@ tl_object_ptr<td_api::webPageInstantView> WebPagesManager::get_web_page_instant_
LOG(ERROR) << "Trying to get not loaded web page instant view";
return nullptr;
}
auto feedback_link =
td_api::make_object<td_api::internalLinkTypeBotStart>("previews", PSTRING() << "webpage" << web_page_id.get());
auto feedback_link = td_api::make_object<td_api::internalLinkTypeBotStart>(
"previews", PSTRING() << "webpage" << web_page_id.get(), true);
return td_api::make_object<td_api::webPageInstantView>(
get_page_block_objects(web_page_instant_view->page_blocks, td_, web_page_instant_view->url),
web_page_instant_view->view_count, web_page_instant_view->is_v2 ? 2 : 1, web_page_instant_view->is_rtl,

View File

@ -128,7 +128,7 @@ TEST(Link, parse_internal_link) {
std::move(administrator_rights));
};
auto bot_start = [](const td::string &bot_username, const td::string &start_parameter) {
return td::td_api::make_object<td::td_api::internalLinkTypeBotStart>(bot_username, start_parameter);
return td::td_api::make_object<td::td_api::internalLinkTypeBotStart>(bot_username, start_parameter, false);
};
auto bot_start_in_group = [](const td::string &bot_username, const td::string &start_parameter,
td::td_api::object_ptr<td::td_api::chatAdministratorRights> &&administrator_rights) {