Add supported chat types to internalLinkTypeAttachmentMenuBot.

This commit is contained in:
levlam 2022-06-01 17:12:53 +03:00
parent 7092674c05
commit dfe067e52e
3 changed files with 69 additions and 44 deletions

View File

@ -1478,7 +1478,7 @@ bankCardInfo title:string actions:vector<bankCardActionOpenUrl> = BankCardInfo;
address country_code:string state:string city:string street_line1:string street_line2:string postal_code:string = Address;
//@description Contains parameters of the app theme @background_color A color of the background in the RGB24 format @text_color A color of text in the RGB24 format
//@description Contains parameters of the application theme @background_color A color of the background in the RGB24 format @text_color A color of text in the RGB24 format
//@hint_color A color of hints in the RGB24 format @link_color A color of links in the RGB24 format @button_color A color of the buttons in the RGB24 format
//@button_text_color A color of text on the buttons in the RGB24 format
themeParameters background_color:int32 text_color:int32 hint_color:int32 link_color:int32 button_color:int32 button_text_color:int32 = ThemeParameters;
@ -3537,17 +3537,25 @@ chatReportReasonPersonalDetails = ChatReportReason;
chatReportReasonCustom = ChatReportReason;
//@class InternalLinkType @description Describes an internal https://t.me or tg: link, which must be processed by the app in a special way
//@description Describes supported chat types
//@supports_user_chats True, if private chats with ordinary users are supported
//@supports_bot_chats True, if private chats with other bots are supported
//@supports_group_chats True, if basic group and supergroup chats are supported
//@supports_channel_chats True, if channel chats are supported
supportedChatTypes supports_user_chats:Bool supports_bot_chats:Bool supports_group_chats:Bool supports_channel_chats:Bool = SupportedChatTypes;
//@description The link is a link to the active sessions section of the app. Use getActiveSessions to handle the link
//@class InternalLinkType @description Describes an internal https://t.me or tg: link, which must be processed by the application in a special way
//@description The link is a link to the active sessions section of the application. Use getActiveSessions to handle the link
internalLinkTypeActiveSessions = InternalLinkType;
//@description The link is a link to an attachment menu bot to be opened in the specified chat. Process given chat_link to open corresponding chat.
//@description The link is a link to an attachment menu bot to be opened in the specified or a chosen chat. Process given chat_types and chat_link to choose and open the corresponding chat.
//-Then call searchPublicChat with the given bot username, check that the user is a bot and can be added to attachment menu. Then use getAttachmentMenuBot to receive information about the bot.
//-If the bot isn't added to attachment menu, then user needs to confirm adding the bot to attachment menu. If user confirms adding, then use toggleBotIsAddedToAttachmentMenu to add it.
//-If the attachment menu bot can't be used in the opened chat, show an error to the user. If the bot is added to attachment menu, then use openWebApp with the given URL
//@chat_link An internal link pointing to a chat; may be null if the current chat needs to be kept @bot_username Username of the bot @url URL to be passed to openWebApp
internalLinkTypeAttachmentMenuBot chat_link:InternalLinkType bot_username:string url:string = InternalLinkType;
//@chat_types List of chat types, supported by the link; may be null if chat_link must be processed instead @chat_link An internal link pointing to a chat; may be null if the current chat needs to be kept @bot_username Username of the bot @url URL to be passed to openWebApp
internalLinkTypeAttachmentMenuBot chat_types:supportedChatTypes chat_link:InternalLinkType bot_username:string url:string = InternalLinkType;
//@description The link contains an authentication code. Call checkAuthenticationCode with the code if the current authorization state is authorizationStateWaitCode @code The authentication code
internalLinkTypeAuthenticationCode code:string = InternalLinkType;
@ -3604,7 +3612,7 @@ internalLinkTypeMessage url:string = InternalLinkType;
//@text Message draft text @contains_link True, if the first line of the text contains a link. If true, the input field needs to be focused and the text after the link must be selected
internalLinkTypeMessageDraft text:formattedText contains_link:Bool = InternalLinkType;
//@description The link contains a request of Telegram passport data. Call getPassportAuthorizationForm with the given parameters to process the link if the link was received from outside of the app, otherwise ignore it
//@description The link contains a request of Telegram passport data. Call getPassportAuthorizationForm with the given parameters to process the link if the link was received from outside of the application, otherwise ignore it
//@bot_user_id User identifier of the service's bot @scope Telegram Passport element types requested by the service @public_key Service's public key @nonce Unique request identifier provided by the service
//@callback_url An HTTP URL to open once the request is finished or canceled with the parameter tg_passport=success or tg_passport=cancel respectively. If empty, then the link tgbot{bot_user_id}://passport/success or tgbot{bot_user_id}://passport/cancel needs to be opened instead
internalLinkTypePassportDataRequest bot_user_id:int53 scope:string public_key:string nonce:string callback_url:string = InternalLinkType;
@ -3613,7 +3621,7 @@ internalLinkTypePassportDataRequest bot_user_id:int53 scope:string public_key:st
//@hash Hash value from the link @phone_number Phone number value from the link
internalLinkTypePhoneNumberConfirmation hash:string phone_number:string = InternalLinkType;
//@description The link is a link to the Premium features screen of the app, from which the user can subscribe to Telegram Premium. Call getPremiumFeatures with the given referrer to process the link @referrer Referrer specified in the link
//@description The link is a link to the Premium features screen of the applcation, from which the user can subscribe to Telegram Premium. Call getPremiumFeatures with the given referrer to process the link @referrer Referrer specified in the link
internalLinkTypePremiumFeatures referrer:string = InternalLinkType;
//@description The link is a link to the privacy and security settings section of the app
@ -3630,7 +3638,7 @@ internalLinkTypePublicChat chat_username:string = InternalLinkType;
//-"This code can be used to allow someone to log in to your Telegram account. To confirm Telegram login, please go to Settings > Devices > Scan QR and scan the code" needs to be shown
internalLinkTypeQrCodeAuthentication = InternalLinkType;
//@description The link is a link to app settings
//@description The link is a link to application settings
internalLinkTypeSettings = InternalLinkType;
//@description The link is a link to a sticker set. Call searchStickerSet with the given sticker set name to process the link and show the sticker set @sticker_set_name Name of the sticker set
@ -5520,7 +5528,7 @@ removeAllFilesFromDownloads only_active:Bool only_completed:Bool delete_from_cac
searchFileDownloads query:string only_active:Bool only_completed:Bool offset:string limit:int32 = FoundFileDownloads;
//@description Returns information about a file with messages exported from another app @message_file_head Beginning of the message file; up to 100 first lines
//@description Returns information about a file with messages exported from another application @message_file_head Beginning of the message file; up to 100 first lines
getMessageFileType message_file_head:string = MessageFileType;
//@description Returns a confirmation text to be shown to the user before starting message import

View File

@ -154,18 +154,29 @@ class LinkManager::InternalLinkActiveSessions final : public InternalLink {
};
class LinkManager::InternalLinkAttachMenuBot final : public InternalLink {
td_api::object_ptr<td_api::supportedChatTypes> dialog_types_;
unique_ptr<InternalLink> dialog_link_;
string bot_username_;
string url_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
td_api::object_ptr<td_api::supportedChatTypes> dialog_types;
if (dialog_types_ != nullptr) {
dialog_types = td_api::make_object<td_api::supportedChatTypes>(
dialog_types_->supports_user_chats_, dialog_types_->supports_bot_chats_, dialog_types_->supports_group_chats_,
dialog_types_->supports_channel_chats_);
}
return td_api::make_object<td_api::internalLinkTypeAttachmentMenuBot>(
dialog_link_ == nullptr ? nullptr : dialog_link_->get_internal_link_type_object(), bot_username_, url_);
std::move(dialog_types), dialog_link_ == nullptr ? nullptr : dialog_link_->get_internal_link_type_object(),
bot_username_, url_);
}
public:
InternalLinkAttachMenuBot(unique_ptr<InternalLink> dialog_link, string bot_username, Slice start_parameter)
: dialog_link_(std::move(dialog_link)), bot_username_(std::move(bot_username)) {
InternalLinkAttachMenuBot(td_api::object_ptr<td_api::supportedChatTypes> dialog_types,
unique_ptr<InternalLink> dialog_link, string bot_username, Slice start_parameter)
: dialog_types_(std::move(dialog_types))
, dialog_link_(std::move(dialog_link))
, bot_username_(std::move(bot_username)) {
if (!start_parameter.empty()) {
url_ = PSTRING() << "start://" << start_parameter;
}
@ -987,12 +998,12 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
// resolve?domain=<username>&attach=<bot_username>
// resolve?domain=<username>&attach=<bot_username>&startattach=<start_parameter>
return td::make_unique<InternalLinkAttachMenuBot>(
td::make_unique<InternalLinkPublicDialog>(std::move(username)), url_query.get_arg("attach").str(),
nullptr, td::make_unique<InternalLinkPublicDialog>(std::move(username)), url_query.get_arg("attach").str(),
url_query.get_arg("startattach"));
} else if (url_query.has_arg("startattach")) {
// resolve?domain=<bot_username>&startattach
// resolve?domain=<bot_username>&startattach=<start_parameter>
return td::make_unique<InternalLinkAttachMenuBot>(nullptr, std::move(username),
return td::make_unique<InternalLinkAttachMenuBot>(nullptr, nullptr, std::move(username),
url_query.get_arg("startattach"));
}
if (username == "telegrampassport") {
@ -1006,8 +1017,8 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
if (!url_query.get_arg("attach").empty()) {
// resolve?phone=<phone_number>&attach=<bot_username>
// resolve?phone=<phone_number>&attach=<bot_username>&startattach=<start_parameter>
return td::make_unique<InternalLinkAttachMenuBot>(std::move(user_link), url_query.get_arg("attach").str(),
url_query.get_arg("startattach"));
return td::make_unique<InternalLinkAttachMenuBot>(
nullptr, std::move(user_link), url_query.get_arg("attach").str(), url_query.get_arg("startattach"));
}
// resolve?phone=12345
return user_link;
@ -1188,8 +1199,8 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
if (!url_query.get_arg("attach").empty()) {
// /+<phone_number>?attach=<bot_username>
// /+<phone_number>?attach=<bot_username>&startattach=<start_parameter>
return td::make_unique<InternalLinkAttachMenuBot>(std::move(user_link), url_query.get_arg("attach").str(),
url_query.get_arg("startattach"));
return td::make_unique<InternalLinkAttachMenuBot>(
nullptr, std::move(user_link), url_query.get_arg("attach").str(), url_query.get_arg("startattach"));
}
// /+<phone_number>
return user_link;
@ -1313,13 +1324,14 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
if (!url_query.get_arg("attach").empty()) {
// /<username>?attach=<bot_username>
// /<username>?attach=<bot_username>&startattach=<start_parameter>
return td::make_unique<InternalLinkAttachMenuBot>(td::make_unique<InternalLinkPublicDialog>(std::move(username)),
url_query.get_arg("attach").str(),
return td::make_unique<InternalLinkAttachMenuBot>(
nullptr, td::make_unique<InternalLinkPublicDialog>(std::move(username)), url_query.get_arg("attach").str(),
url_query.get_arg("startattach"));
} else if (url_query.has_arg("startattach")) {
// /<bot_username>?startattach
// /<bot_username>?startattach=<start_parameter>
return td::make_unique<InternalLinkAttachMenuBot>(nullptr, std::move(username), url_query.get_arg("startattach"));
return td::make_unique<InternalLinkAttachMenuBot>(nullptr, nullptr, std::move(username),
url_query.get_arg("startattach"));
}
// /<username>

View File

@ -98,10 +98,12 @@ TEST(Link, parse_internal_link) {
auto active_sessions = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeActiveSessions>();
};
auto attachment_menu_bot = [](td::td_api::object_ptr<td::td_api::InternalLinkType> chat_link,
auto attachment_menu_bot = [](td::td_api::object_ptr<td::td_api::supportedChatTypes> chat_types,
td::td_api::object_ptr<td::td_api::InternalLinkType> chat_link,
const td::string &bot_username, const td::string &start_parameter) {
return td::td_api::make_object<td::td_api::internalLinkTypeAttachmentMenuBot>(
std::move(chat_link), bot_username, start_parameter.empty() ? td::string() : "start://" + start_parameter);
std::move(chat_types), std::move(chat_link), bot_username,
start_parameter.empty() ? td::string() : "start://" + start_parameter);
};
auto authentication_code = [](const td::string &code) {
return td::td_api::make_object<td::td_api::internalLinkTypeAuthenticationCode>(code);
@ -242,15 +244,17 @@ TEST(Link, parse_internal_link) {
parse_internal_link("tg:resolve?domain=telegram&post=&single", public_chat("telegram"));
parse_internal_link("tg:resolve?domain=123456&post=&single",
unknown_deep_link("tg://resolve?domain=123456&post=&single"));
parse_internal_link("tg:resolve?domain=telegram&startattach", attachment_menu_bot(nullptr, "telegram", ""));
parse_internal_link("tg:resolve?domain=telegram&startattach=1", attachment_menu_bot(nullptr, "telegram", "1"));
parse_internal_link("tg:resolve?domain=telegram&attach=&startattach", attachment_menu_bot(nullptr, "telegram", ""));
parse_internal_link("tg:resolve?domain=telegram&startattach", attachment_menu_bot(nullptr, nullptr, "telegram", ""));
parse_internal_link("tg:resolve?domain=telegram&startattach=1",
attachment_menu_bot(nullptr, nullptr, "telegram", "1"));
parse_internal_link("tg:resolve?domain=telegram&attach=&startattach",
attachment_menu_bot(nullptr, nullptr, "telegram", ""));
parse_internal_link("tg:resolve?domain=telegram&attach=&startattach=1",
attachment_menu_bot(nullptr, "telegram", "1"));
attachment_menu_bot(nullptr, nullptr, "telegram", "1"));
parse_internal_link("tg:resolve?domain=telegram&attach=test&startattach",
attachment_menu_bot(public_chat("telegram"), "test", ""));
attachment_menu_bot(nullptr, public_chat("telegram"), "test", ""));
parse_internal_link("tg:resolve?domain=telegram&attach=test&startattach=1",
attachment_menu_bot(public_chat("telegram"), "test", "1"));
attachment_menu_bot(nullptr, public_chat("telegram"), "test", "1"));
parse_internal_link("tg:resolve?phone=1", user_phone_number("1"));
parse_internal_link("tg:resolve?phone=123456", user_phone_number("123456"));
@ -260,11 +264,11 @@ TEST(Link, parse_internal_link) {
parse_internal_link("tg:resolve?phone=123456&attach=&startattach", user_phone_number("123456"));
parse_internal_link("tg:resolve?phone=123456&attach=&startattach=123", user_phone_number("123456"));
parse_internal_link("tg:resolve?phone=123456&attach=test",
attachment_menu_bot(user_phone_number("123456"), "test", ""));
attachment_menu_bot(nullptr, user_phone_number("123456"), "test", ""));
parse_internal_link("tg:resolve?phone=123456&attach=test&startattach",
attachment_menu_bot(user_phone_number("123456"), "test", ""));
attachment_menu_bot(nullptr, user_phone_number("123456"), "test", ""));
parse_internal_link("tg:resolve?phone=123456&attach=test&startattach=123",
attachment_menu_bot(user_phone_number("123456"), "test", "123"));
attachment_menu_bot(nullptr, user_phone_number("123456"), "test", "123"));
parse_internal_link("tg:resolve?phone=01234567890123456789012345678912",
user_phone_number("01234567890123456789012345678912"));
parse_internal_link("tg:resolve?phone=012345678901234567890123456789123",
@ -289,15 +293,16 @@ TEST(Link, parse_internal_link) {
parse_internal_link("t.me/username/-12345", public_chat("username"));
parse_internal_link("t.me//12345?single", nullptr);
parse_internal_link("https://telegram.dog/telegram/?single", public_chat("telegram"));
parse_internal_link("t.me/username?startattach", attachment_menu_bot(nullptr, "username", ""));
parse_internal_link("t.me/username?startattach=1", attachment_menu_bot(nullptr, "username", "1"));
parse_internal_link("t.me/username?startattach", attachment_menu_bot(nullptr, nullptr, "username", ""));
parse_internal_link("t.me/username?startattach=1", attachment_menu_bot(nullptr, nullptr, "username", "1"));
parse_internal_link("t.me/username?attach=", public_chat("username"));
parse_internal_link("t.me/username?attach=&startattach", attachment_menu_bot(nullptr, "username", ""));
parse_internal_link("t.me/username?attach=&startattach=1", attachment_menu_bot(nullptr, "username", "1"));
parse_internal_link("t.me/username?attach=bot", attachment_menu_bot(public_chat("username"), "bot", ""));
parse_internal_link("t.me/username?attach=bot&startattach", attachment_menu_bot(public_chat("username"), "bot", ""));
parse_internal_link("t.me/username?attach=&startattach", attachment_menu_bot(nullptr, nullptr, "username", ""));
parse_internal_link("t.me/username?attach=&startattach=1", attachment_menu_bot(nullptr, nullptr, "username", "1"));
parse_internal_link("t.me/username?attach=bot", attachment_menu_bot(nullptr, public_chat("username"), "bot", ""));
parse_internal_link("t.me/username?attach=bot&startattach",
attachment_menu_bot(nullptr, public_chat("username"), "bot", ""));
parse_internal_link("t.me/username?attach=bot&startattach=1",
attachment_menu_bot(public_chat("username"), "bot", "1"));
attachment_menu_bot(nullptr, public_chat("username"), "bot", "1"));
parse_internal_link("tg:privatepost?domain=username/12345&single",
unknown_deep_link("tg://privatepost?domain=username/12345&single"));
@ -497,11 +502,11 @@ TEST(Link, parse_internal_link) {
parse_internal_link("t.me/+123456?attach=", user_phone_number("123456"));
parse_internal_link("t.me/+123456?attach=&startattach", user_phone_number("123456"));
parse_internal_link("t.me/+123456?attach=&startattach=1", user_phone_number("123456"));
parse_internal_link("t.me/+123456?attach=bot", attachment_menu_bot(user_phone_number("123456"), "bot", ""));
parse_internal_link("t.me/+123456?attach=bot", attachment_menu_bot(nullptr, user_phone_number("123456"), "bot", ""));
parse_internal_link("t.me/+123456?attach=bot&startattach",
attachment_menu_bot(user_phone_number("123456"), "bot", ""));
attachment_menu_bot(nullptr, user_phone_number("123456"), "bot", ""));
parse_internal_link("t.me/+123456?attach=bot&startattach=1",
attachment_menu_bot(user_phone_number("123456"), "bot", "1"));
attachment_menu_bot(nullptr, user_phone_number("123456"), "bot", "1"));
parse_internal_link("tg:join?invite=abcdef", chat_invite("abcdef"));
parse_internal_link("tg:join?invite=abc%20def", chat_invite("abc%20def"));