update examples for ktgbotapi 38.0.0

This commit is contained in:
InsanusMokrassar committed 2026-11-26 12:28:56 +06:00
1 parent d0da6c851b
commit 97b4391495
86 files changed
+888 -370

No files matched your search

+5
View File
@@ -8,6 +8,11 @@ ways to consume their payloads with the TelegramBotAPI behaviour builder.
- On startup, the bot fetches and prints its own account details. It stops if the
account has no username, because a username is required to build a deep link.
- `/start` without arguments returns a short usage hint.
- `/invite` returns the bot owner's invitation link. The owner can open it to invite a user to
a private chat with the bot. When Telegram delivers `WriteAccessAllowed.FromInvitation`,
the bot greets that user and names the inviter.
- `/sharetheme` shows the theme for sharing a link to the current chat. For an emoji theme it
looks up the selected backdrop by ID. For a unique-gift theme it shows the gift name.
- A text message containing no bot-command entity is used as the payload of a new
deep link, which the bot returns to the sender.
- A `/start <payload>` deep link is observed by both an `onDeepLink` trigger and a
+1 -1
View File
@@ -11,7 +11,7 @@ buildscript {
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName="DeepLinksBotKt"
application.mainClass = "DeepLinksBotKt"
dependencies {
@@ -1,12 +1,20 @@
import dev.inmo.micro_utils.coroutines.subscribeLoggingDropExceptions
import dev.inmo.tgbotapi.extensions.api.bot.getMe
import dev.inmo.tgbotapi.extensions.api.chat.get.getChat
import dev.inmo.tgbotapi.extensions.api.chat.get.getChatShareThemeBackdrops
import dev.inmo.tgbotapi.extensions.api.send.reply
import dev.inmo.tgbotapi.extensions.api.send.sendMessage
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitDeepLinks
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onCommand
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onDeepLink
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onText
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onWriteAccessAllowed
import dev.inmo.tgbotapi.extensions.utils.formatting.makeBotInviteLink
import dev.inmo.tgbotapi.extensions.utils.formatting.makeTelegramDeepLink
import dev.inmo.tgbotapi.types.EmojiType
import dev.inmo.tgbotapi.types.chat.ChatShareTheme
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.WriteAccessAllowed
import dev.inmo.tgbotapi.types.message.textsources.BotCommandTextSource
/**
@@ -40,6 +48,32 @@ suspend fun main(vararg args: String) {
onCommand("start", requireOnlyCommandInMessage = true) { // handling of `start` without args
reply(it, "Hi :) Send me any text and I will try hard to create deeplink for you")
}
onCommand("invite") {
reply(it, makeBotInviteLink(username))
}
onWriteAccessAllowed { message ->
val invitation = message.chatEvent as? WriteAccessAllowed.FromInvitation ?: return@onWriteAccessAllowed
sendMessage(message.chat, "You were invited by ${invitation.inviter.firstName}.")
}
onCommand("sharetheme") { message ->
val description = when (val theme = getChat(message.chat.id).shareTheme) {
is ChatShareTheme.Emoji -> {
val emojis = theme.emojis.joinToString(" ") {
when (it) {
is EmojiType.Emoji -> it.emoji
is EmojiType.CustomEmoji -> "custom emoji ${it.customEmojiId.string}"
}
}
val backdrop = theme.backgroundBackdropId?.let { id ->
getChatShareThemeBackdrops().backdrops.firstOrNull { it.id == id }?.name ?: id.int.toString()
}
"Emoji: $emojis\nBackdrop: ${backdrop ?: "default"}"
}
is ChatShareTheme.UniqueGift -> "Unique gift: ${theme.gift.name.value}"
null -> "This chat has no share theme."
}
reply(message, description)
}
onDeepLink { (it, deepLink) ->
reply(it, "Ok, I got deep link \"${deepLink}\" in trigger")
}