mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
deeplinking fixes and additions
This commit is contained in:
parent
b2bc47ec04
commit
1ebaa1c387
@ -2,6 +2,14 @@
|
||||
|
||||
## 0.38.5
|
||||
|
||||
* `Core`:
|
||||
* `Username` got new property `usernameWithoutAt` which will return `username` without leading `@`
|
||||
* `Utils`:
|
||||
* Several new functions for working with deep links:
|
||||
* `makeUsernameDeepLinkPrefix`
|
||||
* `makeTelegramDeepLink`
|
||||
* `makeDeepLink`
|
||||
|
||||
## 0.38.4
|
||||
|
||||
__This update contains including of [Telegram Bot API 5.7](https://core.telegram.org/bots/api-changelog#january-31-2022)__
|
||||
|
@ -46,6 +46,9 @@ fun Byte.toChatId(): ChatId = toLong().toChatId()
|
||||
data class Username(
|
||||
val username: String
|
||||
) : ChatIdentifier() {
|
||||
val usernameWithoutAt
|
||||
get() = username.dropWhile { it == '@' }
|
||||
|
||||
init {
|
||||
if (!username.startsWith("@")) {
|
||||
throw IllegalArgumentException("Username must starts with `@`")
|
||||
|
@ -9,9 +9,15 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
private const val internalLinkBeginning = "https://t.me"
|
||||
|
||||
fun makeUsernameLink(username: String) = "$internalLinkBeginning/$username"
|
||||
fun makeUsernameDeepLinkPrefix(username: String) = "${makeUsernameLink(username)}?start="
|
||||
inline val Username.link
|
||||
get() = makeUsernameLink(username)
|
||||
get() = makeUsernameLink(usernameWithoutAt)
|
||||
inline val Username.deepLinkPrefix
|
||||
get() = makeUsernameDeepLinkPrefix(usernameWithoutAt)
|
||||
inline fun makeLink(username: Username) = username.link
|
||||
inline fun makeTelegramDeepLink(username: String, startParameter: String) = "${makeUsernameDeepLinkPrefix(username)}$startParameter"
|
||||
inline fun makeDeepLink(username: Username, startParameter: String) = "${username.deepLinkPrefix}$startParameter"
|
||||
inline fun makeTelegramDeepLink(username: Username, startParameter: String) = makeDeepLink(username, startParameter)
|
||||
|
||||
fun makeLinkToMessage(
|
||||
username: String,
|
||||
|
Loading…
Reference in New Issue
Block a user