mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-10-15 08:34:46 +00:00
update examples for ktgbotapi 37.0.0
This commit is contained in:
@@ -10,10 +10,7 @@ import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||
import dev.inmo.tgbotapi.extensions.api.send.withTypingAction
|
||||
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.onGiveawayCompleted
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGiveawayContent
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGiveawayCreated
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onGiveawayWinners
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onUniqueGiftSentOrReceived
|
||||
import dev.inmo.tgbotapi.types.chat.BusinessChat
|
||||
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||
import dev.inmo.tgbotapi.types.chat.PublicChat
|
||||
@@ -22,6 +19,7 @@ import dev.inmo.tgbotapi.types.gifts.OwnedGift
|
||||
import dev.inmo.tgbotapi.types.message.textsources.splitForText
|
||||
import dev.inmo.tgbotapi.utils.bold
|
||||
import dev.inmo.tgbotapi.utils.buildEntities
|
||||
import dev.inmo.tgbotapi.utils.regular
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
||||
@@ -30,7 +28,8 @@ import kotlinx.coroutines.Dispatchers
|
||||
*
|
||||
* Business chats are queried through their business connection, private chats through their user ID, and public or
|
||||
* unknown chat types through their chat ID. Regular and unique gifts are rendered as formatted text and long results
|
||||
* are split across replies. The bot also prints its [getMe] result at startup.
|
||||
* are split across replies. Unique-gift service messages also expose the Bot API 10.3 text, entities and privacy flag.
|
||||
* The bot prints its [getMe] result at startup.
|
||||
*
|
||||
* @param args the bot token followed by optional, case-sensitive `debug` and `testServer` flags; unknown trailing
|
||||
* arguments are ignored
|
||||
@@ -55,6 +54,28 @@ suspend fun main(vararg args: String) {
|
||||
val me = getMe()
|
||||
println(me)
|
||||
|
||||
onUniqueGiftSentOrReceived { message ->
|
||||
val uniqueGiftInfo = message.chatEvent
|
||||
println(
|
||||
"Unique gift ${uniqueGiftInfo.gift.name.value}: " +
|
||||
"text=${uniqueGiftInfo.text}, textSources=${uniqueGiftInfo.textSources}, " +
|
||||
"isPrivate=${uniqueGiftInfo.isPrivate}"
|
||||
)
|
||||
reply(
|
||||
message,
|
||||
buildEntities {
|
||||
bold("Unique gift") + ": ${uniqueGiftInfo.gift.name.value}\n"
|
||||
bold("Private") + ": ${uniqueGiftInfo.isPrivate}\n"
|
||||
bold("Text") + ": "
|
||||
if (uniqueGiftInfo.textSources.isEmpty()) {
|
||||
regular(uniqueGiftInfo.text ?: "(None)")
|
||||
} else {
|
||||
+uniqueGiftInfo.textSources
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
onCommand("start") {
|
||||
val giftsFlow = when (val chat = it.chat) {
|
||||
is BusinessChat -> {
|
||||
|
||||
Reference in New Issue
Block a user