From 2f6f40362a0121154c64eee3f0ab0a373cca2c5f Mon Sep 17 00:00:00 2001 From: Pavel Klimatov Date: Fri, 16 Jun 2023 01:54:06 +0700 Subject: [PATCH] added support for the tg:// format for deep links --- .../tgbotapi/extensions/utils/formatting/LinksFormatting.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt index a5df98590e..5ee2ce87d2 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/formatting/LinksFormatting.kt @@ -8,6 +8,7 @@ import io.ktor.http.encodeURLQueryComponent fun makeUsernameLink(username: String, threadId: MessageThreadId? = null) = "$internalLinkBeginning/$username${threadId ?.let { "/$it" } ?: ""}" +fun makeTgUsernameLink(username: String) = "${internalTgAppLinksBeginning}resolve?domain=$username" fun makeUserLink(userId: UserId) = userId.userLink fun makeChatLink(identifier: Identifier, threadId: MessageThreadId? = null) = identifier.toString().replace( linkIdRedundantPartRegex, @@ -16,6 +17,7 @@ fun makeChatLink(identifier: Identifier, threadId: MessageThreadId? = null) = id "$internalLinkBeginning/c/$bareId${threadId ?.let { "/$it" } ?: ""}" } fun makeUsernameDeepLinkPrefix(username: String) = "${makeUsernameLink(username)}?start=" +fun makeTgUsernameDeepLinkPrefix(username: String) = "${makeTgUsernameLink(username)}&start=" fun makeUsernameStartattachPrefix(username: String) = "$internalLinkBeginning/$username?startattach" fun makeUsernameStartattachLink(username: String, data: String? = null) = "${makeUsernameStartattachPrefix(username)}${data?.let { "=$it" } ?: ""}" inline val Username.usernameLink @@ -30,6 +32,8 @@ inline val Username.startattachPrefix get() = makeUsernameStartattachPrefix(usernameWithoutAt) inline fun makeLink(username: Username, threadId: MessageThreadId? = null) = username.link(threadId) inline fun makeTelegramDeepLink(username: String, startParameter: String) = "${makeUsernameDeepLinkPrefix(username)}$startParameter".encodeURLQueryComponent() +inline fun makeTgDeepLink(username: String, startParameter: String) = "${makeTgUsernameDeepLinkPrefix(username)}$startParameter".encodeURLQueryComponent() +inline fun makeTgDeepLink(username: Username, startParameter: String) = makeTgDeepLink(username.usernameWithoutAt, startParameter) inline fun makeTelegramStartattach(username: String, data: String? = null) = makeUsernameStartattachLink(username, data) inline fun makeDeepLink(username: Username, startParameter: String) = makeTelegramDeepLink(username.usernameWithoutAt, startParameter) inline fun makeTelegramDeepLink(username: Username, startParameter: String) = makeDeepLink(username, startParameter)