1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

Merge pull request #768 from klimatov/makeTgDeepLink

added support for the tg:// format for deep links
This commit is contained in:
InsanusMokrassar 2023-06-16 12:09:01 +06:00 committed by GitHub
commit d84d982eb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)