Add td_api::internalLinkTypeBusinessChat.

This commit is contained in:
levlam 2024-04-12 01:01:26 +03:00
parent 1806799357
commit 1bb4a2007b
5 changed files with 66 additions and 7 deletions

View File

@ -5964,6 +5964,11 @@ internalLinkTypeBotStart bot_username:string start_parameter:string autostart:Bo
//@administrator_rights Expected administrator rights for the bot; may be null
internalLinkTypeBotStartInGroup bot_username:string start_parameter:string administrator_rights:chatAdministratorRights = InternalLinkType;
//@description The link is a link to a business chat. Use getBusinessChatLinkInfo with the provided link name to get information about the link,
//-then open received private chat and replace chat draft with the provided text
//@link_name Name of the link
internalLinkTypeBusinessChat link_name:string = InternalLinkType;
//@description The link is a link to the change phone number section of the app
internalLinkTypeChangePhoneNumber = InternalLinkType;
@ -9789,8 +9794,8 @@ editBusinessChatLink link:string link_info:inputBusinessChatLink = BusinessChatL
//@description Deletes a business chat link of the current account @link The link to delete
deleteBusinessChatLink link:string = Ok;
//@description Returns information about a business chat link @link The link
getBusinessChatLinkInfo link:string = BusinessChatLinkInfo;
//@description Returns information about a business chat link @link_name Name of the link
getBusinessChatLinkInfo link_name:string = BusinessChatLinkInfo;
//@description Returns an HTTPS link, which can be used to get information about the current user

View File

@ -384,6 +384,18 @@ class LinkManager::InternalLinkBotStartInGroup final : public InternalLink {
}
};
class LinkManager::InternalLinkBusinessChat final : public InternalLink {
string link_name_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeBusinessChat>(link_name_);
}
public:
explicit InternalLinkBusinessChat(string link_name) : link_name_(std::move(link_name)) {
}
};
class LinkManager::InternalLinkChangePhoneNumber final : public InternalLink {
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeChangePhoneNumber>();
@ -1130,9 +1142,9 @@ LinkManager::LinkInfo LinkManager::get_link_info(Slice link) {
if (ends_with(host, ".t.me") && host.size() >= 9 && host.find('.') == host.size() - 5) {
Slice subdomain(&host[0], host.size() - 5);
static const FlatHashSet<Slice, SliceHash> disallowed_subdomains(
{"addemoji", "addlist", "addstickers", "addtheme", "auth", "boost", "confirmphone",
"contact", "giftcode", "invoice", "joinchat", "login", "proxy", "setlanguage",
"share", "socks", "web", "a", "k", "z"});
{"addemoji", "addlist", "addstickers", "addtheme", "auth", "boost", "confirmphone",
"contact", "giftcode", "invoice", "joinchat", "login", "m", "proxy",
"setlanguage", "share", "socks", "web", "a", "k", "z"});
if (is_valid_username(subdomain) && disallowed_subdomains.count(subdomain) == 0) {
result.type_ = LinkType::TMe;
result.query_ = PSTRING() << '/' << subdomain << http_url.query_;
@ -1514,6 +1526,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
if (has_arg("slug")) {
return td::make_unique<InternalLinkPremiumGiftCode>(url_query.get_arg("slug").str());
}
} else if (path.size() == 1 && path[0] == "message") {
// message?slug=<name>
if (has_arg("slug")) {
return td::make_unique<InternalLinkBusinessChat>(url_query.get_arg("slug").str());
}
} else if (path.size() == 1 && (path[0] == "share" || path[0] == "msg" || path[0] == "msg_url")) {
// msg_url?url=<url>
// msg_url?url=<url>&text=<text>
@ -1669,6 +1686,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
// /giftcode/<code>
return td::make_unique<InternalLinkPremiumGiftCode>(path[1]);
}
} else if (path[0] == "m") {
if (path.size() >= 2 && !path[1].empty()) {
// /m/<link_name>
return td::make_unique<InternalLinkBusinessChat>(path[1]);
}
} else if (path[0][0] == '$') {
if (path[0].size() >= 2) {
// /$<invoice_name>
@ -2039,6 +2061,14 @@ Result<string> LinkManager::get_internal_link_impl(const td_api::InternalLinkTyp
return PSTRING() << get_t_me_url() << link->bot_username_ << "?startgroup" << start_parameter << admin;
}
}
case td_api::internalLinkTypeBusinessChat::ID: {
auto link = static_cast<const td_api::internalLinkTypeBusinessChat *>(type_ptr);
if (is_internal) {
return PSTRING() << "tg://message?slug=" << url_encode(link->link_name_);
} else {
return PSTRING() << get_t_me_url() << "m/" << url_encode(link->link_name_);
}
}
case td_api::internalLinkTypeChangePhoneNumber::ID:
if (!is_internal) {
return Status::Error("HTTP link is unavailable for the link type");

View File

@ -124,6 +124,7 @@ class LinkManager final : public Actor {
class InternalLinkBotAddToChannel;
class InternalLinkBotStart;
class InternalLinkBotStartInGroup;
class InternalLinkBusinessChat;
class InternalLinkChangePhoneNumber;
class InternalLinkConfirmPhone;
class InternalLinkDefaultMessageAutoDeleteTimerSettings;

View File

@ -8013,9 +8013,9 @@ void Td::on_request(uint64 id, td_api::deleteBusinessChatLink &request) {
void Td::on_request(uint64 id, td_api::getBusinessChatLinkInfo &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.link_);
CLEAN_INPUT_STRING(request.link_name_);
CREATE_REQUEST_PROMISE();
business_manager_->get_business_chat_link_info(request.link_, std::move(promise));
business_manager_->get_business_chat_link_info(request.link_name_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::setSupergroupUsername &request) {

View File

@ -219,6 +219,10 @@ static auto bot_start_in_group(const td::string &bot_username, const td::string
std::move(administrator_rights));
}
static auto business_chat(const td::string &link_name) {
return td::td_api::make_object<td::td_api::internalLinkTypeBusinessChat>(link_name);
}
static auto change_phone_number() {
return td::td_api::make_object<td::td_api::internalLinkTypeChangePhoneNumber>();
}
@ -672,6 +676,24 @@ TEST(Link, parse_internal_link_part2) {
parse_internal_link("tg:giftcode?slug=abc%30ef", premium_gift_code("abc0ef"));
parse_internal_link("tg://giftcode?slug=", unknown_deep_link("tg://giftcode?slug="));
parse_internal_link("t.me/m?slug=abcdef", nullptr);
parse_internal_link("t.me/m", nullptr);
parse_internal_link("t.me/m/", nullptr);
parse_internal_link("t.me/m//abcdef", nullptr);
parse_internal_link("t.me/m?/abcdef", nullptr);
parse_internal_link("t.me/m/?abcdef", nullptr);
parse_internal_link("t.me/m/#abcdef", nullptr);
parse_internal_link("t.me/m/abacaba", business_chat("abacaba"));
parse_internal_link("t.me/m/aba%20aba", business_chat("aba aba"));
parse_internal_link("t.me/m/123456a", business_chat("123456a"));
parse_internal_link("t.me/m/12345678901", business_chat("12345678901"));
parse_internal_link("t.me/m/123456", business_chat("123456"));
parse_internal_link("t.me/m/123456/123123/12/31/a/s//21w/?asdas#test", business_chat("123456"));
parse_internal_link("tg:message?slug=abcdef", business_chat("abcdef"));
parse_internal_link("tg:message?slug=abc%30ef", business_chat("abc0ef"));
parse_internal_link("tg://message?slug=", unknown_deep_link("tg://message?slug="));
parse_internal_link("tg:share?url=google.com&text=text#asdasd", message_draft("google.com\ntext", true));
parse_internal_link("tg:share?url=google.com&text=", message_draft("google.com", false));
parse_internal_link("tg:share?url=&text=google.com", message_draft("google.com", false));
@ -1308,6 +1330,7 @@ TEST(Link, parse_internal_link_part4) {
parse_internal_link("invoice.t.me", nullptr);
parse_internal_link("joinchat.t.me", nullptr);
parse_internal_link("login.t.me", nullptr);
parse_internal_link("m.t.me", nullptr);
parse_internal_link("proxy.t.me", nullptr);
parse_internal_link("setlanguage.t.me", nullptr);
parse_internal_link("share.t.me", nullptr);