Add internalLinkTypeBotStart.
This commit is contained in:
parent
938d14ab75
commit
1eb62acc07
@ -3006,6 +3006,16 @@ internalLinkTypeAuthenticationCode code:string = InternalLinkType;
|
||||
//@description The link is a link to a background. Call searchBackground with the given background name to process the link @background_name Name of the background
|
||||
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;
|
||||
|
||||
//@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 group to add the bot to, and then call sendBotStartMessage with the given start parameter and the chosen group chat. Bots can be added to a public group only by administrators of the group
|
||||
//@bot_username Username of the bot @start_parameter The parameter to be passed to sendBotStartMessage
|
||||
internalLinkTypeBotStartInGroup bot_username:string start_parameter:string = InternalLinkType;
|
||||
|
||||
//@description The link is a chat invite link. Call checkChatInviteLink to process the link
|
||||
internalLinkTypeChatInvite = InternalLinkType;
|
||||
|
||||
@ -3040,7 +3050,7 @@ internalLinkTypeTheme theme_name:string = InternalLinkType;
|
||||
//@description The link is an unknown tg: link. Call getDeepLinkInfo to process the link
|
||||
internalLinkTypeUnknownDeepLink = InternalLinkType;
|
||||
|
||||
//@description The link is a link to a voice chat. Call searchPublicChat and joinGoupCall with the given chat username and the given invite hash to process the link
|
||||
//@description The link is a link to a voice chat. Call searchPublicChat with the given chat username and then joinGoupCall with the given invite hash to process the link
|
||||
//@chat_username Username of the chat with the voice chat @invite_hash If non-empty, invite hash to be used to join the voice chat without being muted by administrators
|
||||
internalLinkTypeVoiceChat chat_username:string invite_hash:string = InternalLinkType;
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "td/mtproto/ProxySecret.h"
|
||||
|
||||
#include "td/utils/algorithm.h"
|
||||
#include "td/utils/base64.h"
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/HttpUrl.h"
|
||||
#include "td/utils/logging.h"
|
||||
@ -25,6 +26,10 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
static bool is_valid_start_parameter(Slice start_parameter) {
|
||||
return start_parameter.size() <= 64 && is_base64url_characters(start_parameter);
|
||||
}
|
||||
|
||||
class LinkManager::InternalLinkAuthenticationCode : public InternalLink {
|
||||
string code_;
|
||||
|
||||
@ -57,6 +62,42 @@ class LinkManager::InternalLinkBackground : public InternalLink {
|
||||
}
|
||||
};
|
||||
|
||||
class LinkManager::InternalLinkBotStart : public InternalLink {
|
||||
string bot_username_;
|
||||
string start_parameter_;
|
||||
|
||||
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_);
|
||||
}
|
||||
|
||||
InternalLinkType get_type() const final {
|
||||
return InternalLinkType::BotStart;
|
||||
}
|
||||
|
||||
public:
|
||||
InternalLinkBotStart(string bot_username, string start_parameter)
|
||||
: bot_username_(std::move(bot_username)), start_parameter_(std::move(start_parameter)) {
|
||||
}
|
||||
};
|
||||
|
||||
class LinkManager::InternalLinkBotStartInGroup : public InternalLink {
|
||||
string bot_username_;
|
||||
string start_parameter_;
|
||||
|
||||
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
|
||||
return td_api::make_object<td_api::internalLinkTypeBotStartInGroup>(bot_username_, start_parameter_);
|
||||
}
|
||||
|
||||
InternalLinkType get_type() const final {
|
||||
return InternalLinkType::BotStart;
|
||||
}
|
||||
|
||||
public:
|
||||
InternalLinkBotStartInGroup(string bot_username, string start_parameter)
|
||||
: bot_username_(std::move(bot_username)), start_parameter_(std::move(start_parameter)) {
|
||||
}
|
||||
};
|
||||
|
||||
class LinkManager::InternalLinkConfirmPhone : public InternalLink {
|
||||
string hash_;
|
||||
string phone_number_;
|
||||
@ -566,6 +607,14 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
|
||||
// resolve?domain=username&voicechat=<invite_hash>
|
||||
return td::make_unique<InternalLinkVoiceChat>(get_arg("domain"), arg.second);
|
||||
}
|
||||
if (arg.first == "start" && is_valid_start_parameter(arg.second)) {
|
||||
// /<bot_username>?start=<parameter>
|
||||
return td::make_unique<InternalLinkBotStart>(get_arg("domain"), arg.second);
|
||||
}
|
||||
if (arg.first == "startgroup" && is_valid_start_parameter(arg.second)) {
|
||||
// /<bot_username>?startgroup=<parameter>
|
||||
return td::make_unique<InternalLinkBotStartInGroup>(get_arg("domain"), arg.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (path.size() == 1 && path[0] == "login") {
|
||||
@ -759,6 +808,14 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
|
||||
// /<username>?voicechat=<invite_hash>
|
||||
return td::make_unique<InternalLinkVoiceChat>(path[0], arg.second);
|
||||
}
|
||||
if (arg.first == "start" && is_valid_start_parameter(arg.second)) {
|
||||
// /<bot_username>?start=<parameter>
|
||||
return td::make_unique<InternalLinkBotStart>(path[0], arg.second);
|
||||
}
|
||||
if (arg.first == "startgroup" && is_valid_start_parameter(arg.second)) {
|
||||
// /<bot_username>?startgroup=<parameter>
|
||||
return td::make_unique<InternalLinkBotStartInGroup>(path[0], arg.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,8 @@ class LinkManager : public Actor {
|
||||
enum class InternalLinkType : int32 {
|
||||
AuthenticationCode,
|
||||
Background,
|
||||
BotStart,
|
||||
BotStartInGroup,
|
||||
ConfirmPhone,
|
||||
DialogInvite,
|
||||
Language,
|
||||
@ -90,6 +92,8 @@ class LinkManager : public Actor {
|
||||
|
||||
class InternalLinkAuthenticationCode;
|
||||
class InternalLinkBackground;
|
||||
class InternalLinkBotStart;
|
||||
class InternalLinkBotStartInGroup;
|
||||
class InternalLinkConfirmPhone;
|
||||
class InternalLinkDialogInvite;
|
||||
class InternalLinkLanguage;
|
||||
|
@ -69,6 +69,12 @@ TEST(Link, parse_internal_link) {
|
||||
auto background = [](td::string background_name) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeBackground>(background_name);
|
||||
};
|
||||
auto bot_start = [](td::string bot_username, td::string start_parameter) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeBotStart>(bot_username, start_parameter);
|
||||
};
|
||||
auto bot_start_in_group = [](td::string bot_username, td::string start_parameter) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeBotStartInGroup>(bot_username, start_parameter);
|
||||
};
|
||||
auto chat_invite = [] {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeChatInvite>();
|
||||
};
|
||||
@ -448,5 +454,41 @@ TEST(Link, parse_internal_link) {
|
||||
parse_internal_link("t.me/username?voicechat=", voice_chat("username", ""));
|
||||
parse_internal_link("t.me/username#voicechat=asdas", nullptr);
|
||||
parse_internal_link("t.me//username?voicechat=", nullptr);
|
||||
parse_internal_link("https://telegram.dog/telegram?voi%63e%63hat=t%63st", voice_chat("telegram", "tcst"));
|
||||
parse_internal_link("https://telegram.dog/tele%63ram?voi%63e%63hat=t%63st", voice_chat("telecram", "tcst"));
|
||||
|
||||
parse_internal_link("tg:resolve?domain=username&start=aasdasd", bot_start("username", "aasdasd"));
|
||||
parse_internal_link("TG://resolve?domain=username&start=", bot_start("username", ""));
|
||||
parse_internal_link("TG://test@resolve?domain=username&start=", nullptr);
|
||||
parse_internal_link("tg:resolve:80?domain=username&start=", nullptr);
|
||||
parse_internal_link("tg:http://resolve?domain=username&start=", nullptr);
|
||||
parse_internal_link("tg:https://resolve?domain=username&start=", nullptr);
|
||||
parse_internal_link("tg:resolve?domain=&start=", unknown_deep_link());
|
||||
parse_internal_link("tg:resolve?domain=telegram&&&&&&&start=%30", bot_start("telegram", "0"));
|
||||
|
||||
parse_internal_link("t.me/username/0/a//s/as?start=", bot_start("username", ""));
|
||||
parse_internal_link("t.me/username/aasdas?test=1&start=#12312", bot_start("username", ""));
|
||||
parse_internal_link("t.me/username/0?start=", bot_start("username", ""));
|
||||
parse_internal_link("t.me/username/-1?start=asdasd", bot_start("username", "asdasd"));
|
||||
parse_internal_link("t.me/username?start=", bot_start("username", ""));
|
||||
parse_internal_link("t.me/username#start=asdas", nullptr);
|
||||
parse_internal_link("t.me//username?start=", nullptr);
|
||||
parse_internal_link("https://telegram.dog/tele%63ram?start=t%63st", bot_start("telecram", "tcst"));
|
||||
|
||||
parse_internal_link("tg:resolve?domain=username&startgroup=aasdasd", bot_start_in_group("username", "aasdasd"));
|
||||
parse_internal_link("TG://resolve?domain=username&startgroup=", bot_start_in_group("username", ""));
|
||||
parse_internal_link("TG://test@resolve?domain=username&startgroup=", nullptr);
|
||||
parse_internal_link("tg:resolve:80?domain=username&startgroup=", nullptr);
|
||||
parse_internal_link("tg:http://resolve?domain=username&startgroup=", nullptr);
|
||||
parse_internal_link("tg:https://resolve?domain=username&startgroup=", nullptr);
|
||||
parse_internal_link("tg:resolve?domain=&startgroup=", unknown_deep_link());
|
||||
parse_internal_link("tg:resolve?domain=telegram&&&&&&&startgroup=%30", bot_start_in_group("telegram", "0"));
|
||||
|
||||
parse_internal_link("t.me/username/0/a//s/as?startgroup=", bot_start_in_group("username", ""));
|
||||
parse_internal_link("t.me/username/aasdas?test=1&startgroup=#12312", bot_start_in_group("username", ""));
|
||||
parse_internal_link("t.me/username/0?startgroup=", bot_start_in_group("username", ""));
|
||||
parse_internal_link("t.me/username/-1?startgroup=asdasd", bot_start_in_group("username", "asdasd"));
|
||||
parse_internal_link("t.me/username?startgroup=", bot_start_in_group("username", ""));
|
||||
parse_internal_link("t.me/username#startgroup=asdas", nullptr);
|
||||
parse_internal_link("t.me//username?startgroup=", nullptr);
|
||||
parse_internal_link("https://telegram.dog/tele%63ram?startgroup=t%63st", bot_start_in_group("telecram", "tcst"));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user