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

makeUserLink

This commit is contained in:
InsanusMokrassar 2023-02-13 11:16:49 +06:00
parent 041c3ecc1b
commit dad42cf939
3 changed files with 6 additions and 1 deletions

View File

@ -2,6 +2,9 @@
## 5.1.1
* `Core`:
* Add opportunity to get user link with `makeUserLink`
## 5.1.0
[Bot API 6.5](https://core.telegram.org/bots/api-changelog#february-3-2023) support

View File

@ -14,6 +14,7 @@ import kotlinx.serialization.json.longOrNull
import kotlin.jvm.JvmInline
const val internalLinkBeginning = "https://t.me"
const val internalUserLinkBeginning = "tg://user?id="
@Serializable(ChatIdentifierSerializer::class)
@ClassCastsIncluded
@ -66,7 +67,7 @@ fun IdChatIdentifier.toChatWithThreadId(threadId: MessageThreadId) = IdChatIdent
*/
@Warning("This API have restrictions in Telegram System")
val Identifier.userLink: String
get() = "tg://user?id=$this"
get() = "$internalUserLinkBeginning$this"
/**
* https://core.telegram.org/bots/api#formatting-options
*/

View File

@ -8,6 +8,7 @@ import io.ktor.http.encodeURLQueryComponent
fun makeUsernameLink(username: String, threadId: MessageThreadId? = null) = "$internalLinkBeginning/$username${threadId ?.let { "/$it" } ?: ""}"
fun makeUserLink(userId: UserId) = userId.userLink
fun makeChatLink(identifier: Identifier, threadId: MessageThreadId? = null) = identifier.toString().replace(
linkIdRedundantPartRegex,
""