mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2024-11-17 13:53:53 +00:00
commit
30358f7d2f
@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.extensions.api.send.sendMessage
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithArgs
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.sameThread
|
||||
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
@ -54,7 +54,7 @@ suspend fun main(args: Array<String>) {
|
||||
val content = contentMessage.content
|
||||
|
||||
when {
|
||||
content is TextContent && content.parseCommandsWithParams().keys.contains("stop") -> StopState(it.context)
|
||||
content is TextContent && content.parseCommandsWithArgs().keys.contains("stop") -> StopState(it.context)
|
||||
else -> {
|
||||
execute(content.createResend(it.context))
|
||||
it
|
||||
|
@ -9,6 +9,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onDeepLi
|
||||
import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||
import dev.inmo.tgbotapi.types.InlineQueryId
|
||||
import dev.inmo.tgbotapi.types.inlineQueryAnswerResultsLimit
|
||||
import dev.inmo.tgbotapi.utils.buildEntities
|
||||
|
||||
@ -31,9 +32,9 @@ suspend fun doInlineQueriesBot(token: String) {
|
||||
answer(
|
||||
it,
|
||||
results = results.map { resultNumber ->
|
||||
val resultAsString = resultNumber.toString()
|
||||
val inlineQueryId = InlineQueryId(resultNumber.toString())
|
||||
InlineQueryResultArticle(
|
||||
resultAsString,
|
||||
inlineQueryId,
|
||||
"Title $resultNumber",
|
||||
InputTextMessageContent(
|
||||
buildEntities {
|
||||
|
@ -15,6 +15,7 @@ import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||
import dev.inmo.tgbotapi.types.BotCommand
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||
import dev.inmo.tgbotapi.types.InlineQueryId
|
||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import dev.inmo.tgbotapi.utils.*
|
||||
import kotlinx.coroutines.*
|
||||
@ -137,7 +138,7 @@ suspend fun activateKeyboardsBot(
|
||||
it,
|
||||
results = listOf(
|
||||
InlineQueryResultArticle(
|
||||
it.query,
|
||||
InlineQueryId(it.query),
|
||||
"Send buttons",
|
||||
InputTextMessageContent("It is sent via inline mode inline buttons"),
|
||||
replyMarkup = inlineKeyboard {
|
||||
|
@ -11,10 +11,7 @@ import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
||||
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
||||
import dev.inmo.tgbotapi.extensions.utils.ifChannelChat
|
||||
import dev.inmo.tgbotapi.extensions.utils.ifFromChannelGroupContentMessage
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.PollIdentifier
|
||||
import dev.inmo.tgbotapi.types.ReplyParameters
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.*
|
||||
import dev.inmo.tgbotapi.types.chat.GroupChat
|
||||
import dev.inmo.tgbotapi.types.chat.PrivateChat
|
||||
@ -44,7 +41,7 @@ suspend fun main(vararg args: String) {
|
||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||
val me = getMe()
|
||||
|
||||
val pollToChat = mutableMapOf<PollIdentifier, IdChatIdentifier>()
|
||||
val pollToChat = mutableMapOf<PollId, IdChatIdentifier>()
|
||||
val pollToChatMutex = Mutex()
|
||||
|
||||
onCommand("anonymous") {
|
||||
|
@ -67,7 +67,7 @@ suspend fun main(args: Array<String>) {
|
||||
|
||||
val bot = telegramBot(botToken)
|
||||
|
||||
val allowedAdmin = ChatId(args[1].toLong())
|
||||
val allowedAdmin = ChatId(RawChatId(args[1].toLong()))
|
||||
|
||||
fun Boolean?.allowedSymbol() = when (this) {
|
||||
true -> "✅"
|
||||
@ -377,8 +377,8 @@ suspend fun main(args: Array<String>) {
|
||||
initialFilter = { it.user.id == allowedAdmin }
|
||||
) {
|
||||
val (channelIdString, userIdString) = it.data.split(" ").drop(1)
|
||||
val channelId = ChatId(channelIdString.toLong())
|
||||
val userId = ChatId(userIdString.toLong())
|
||||
val channelId = ChatId(RawChatId(channelIdString.toLong()))
|
||||
val userId = ChatId(RawChatId(userIdString.toLong()))
|
||||
val chatMember = getChatMember(channelId, userId)
|
||||
val asAdmin = chatMember.administratorChatMemberOrNull()
|
||||
val asMember = chatMember.memberChatMemberOrNull()
|
||||
|
@ -44,7 +44,7 @@ fun StickerSet?.buildInfo() = buildEntities {
|
||||
StickerType.Regular -> "Regular"
|
||||
is StickerType.Unknown -> "Unknown type \"${stickerType.type}\""
|
||||
}
|
||||
) + " sticker set with title " + bold(title) + " and name " + bold(name)
|
||||
) + " sticker set with title " + bold(title) + " and name " + bold(name.string)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onSticke
|
||||
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sticker
|
||||
import dev.inmo.tgbotapi.requests.abstracts.asMultipartFile
|
||||
import dev.inmo.tgbotapi.requests.stickers.InputSticker
|
||||
import dev.inmo.tgbotapi.types.StickerSetName
|
||||
import dev.inmo.tgbotapi.types.chat.Chat
|
||||
import dev.inmo.tgbotapi.types.files.*
|
||||
import dev.inmo.tgbotapi.types.toChatId
|
||||
@ -32,7 +33,7 @@ suspend fun main(args: Array<String>) {
|
||||
}
|
||||
) {
|
||||
val me = getMe()
|
||||
fun Chat.stickerSetName() = "s${id.chatId}_by_${me.username ?.usernameWithoutAt}"
|
||||
fun Chat.stickerSetName() = StickerSetName("s${id.chatId}_by_${me.username ?.withoutAt}")
|
||||
onCommand("start") {
|
||||
reply(it) {
|
||||
botCommand("delete") + " - to clear stickers"
|
||||
@ -82,7 +83,7 @@ suspend fun main(args: Array<String>) {
|
||||
}.onFailure { _ ->
|
||||
createNewStickerSet(
|
||||
it.chat.id.toChatId(),
|
||||
stickerSetName,
|
||||
stickerSetName.string,
|
||||
"Sticker set by ${me.firstName}",
|
||||
it.content.media.stickerFormat,
|
||||
listOf(
|
||||
|
@ -18,6 +18,7 @@ import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
||||
import dev.inmo.tgbotapi.types.BotCommand
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||
import dev.inmo.tgbotapi.types.InlineQueryId
|
||||
import dev.inmo.tgbotapi.types.LinkPreviewOptions
|
||||
import dev.inmo.tgbotapi.types.webAppQueryIdField
|
||||
import dev.inmo.tgbotapi.types.webapps.WebAppInfo
|
||||
@ -77,9 +78,9 @@ suspend fun main(vararg args: String) {
|
||||
}
|
||||
post("inline") {
|
||||
val requestBody = call.receiveText()
|
||||
val queryId = call.parameters[webAppQueryIdField] ?: error("$webAppQueryIdField should be presented")
|
||||
val queryId = call.parameters[webAppQueryIdField] ?.let(::InlineQueryId) ?: error("$webAppQueryIdField should be presented")
|
||||
|
||||
bot.answer(queryId, InlineQueryResultArticle(queryId, "Result", InputTextMessageContent(requestBody)))
|
||||
bot.answerInlineQuery(queryId, listOf(InlineQueryResultArticle(queryId, "Result", InputTextMessageContent(requestBody))))
|
||||
call.respond(HttpStatusCode.OK)
|
||||
}
|
||||
post("check") {
|
||||
|
@ -4,8 +4,8 @@ org.gradle.parallel=true
|
||||
org.gradle.jvmargs=-Xmx2344m
|
||||
|
||||
|
||||
kotlin_version=1.9.22
|
||||
telegram_bot_api_version=10.1.1
|
||||
micro_utils_version=0.20.37
|
||||
kotlin_version=1.9.23
|
||||
telegram_bot_api_version=11.0.0
|
||||
micro_utils_version=0.20.39
|
||||
serialization_version=1.6.3
|
||||
ktor_version=2.3.8
|
||||
ktor_version=2.3.9
|
||||
|
Loading…
Reference in New Issue
Block a user