mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-05-19 23:07:19 +00:00
Compare commits
15 Commits
eccbe71e68
...
8.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| a85fdc227e | |||
| 43482ee94e | |||
| 4addb6c755 | |||
| 7d958b6edb | |||
| 323c21f415 | |||
| 6350581739 | |||
| ea1d40fd05 | |||
| 8cee63a0fb | |||
| d42ef2c6cb | |||
| c7fe90ddd7 | |||
| acb382d3f7 | |||
| 0cfe60fd77 | |||
| 6719b9e17c | |||
| 8d33dc0ab2 | |||
| 3e2ccf9cf1 |
@@ -1,8 +1,10 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
|
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.getChat
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.telegramBotWithBehaviourAndLongPolling
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onContentMessage
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.onMentionWithAnyContent
|
||||||
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sender_chat
|
import dev.inmo.tgbotapi.extensions.utils.extensions.raw.sender_chat
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
import dev.inmo.tgbotapi.extensions.utils.formatting.linkMarkdownV2
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
import dev.inmo.tgbotapi.extensions.utils.formatting.textMentionMarkdownV2
|
||||||
@@ -25,24 +27,25 @@ suspend fun main(vararg args: String) {
|
|||||||
val botToken = args.first()
|
val botToken = args.first()
|
||||||
|
|
||||||
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
telegramBotWithBehaviourAndLongPolling(botToken, CoroutineScope(Dispatchers.IO)) {
|
||||||
onContentMessage { message ->
|
val me = getMe()
|
||||||
|
onMentionWithAnyContent(me.username) { message ->
|
||||||
val chat = message.chat
|
val chat = message.chat
|
||||||
|
|
||||||
val answerText = when (val chat = message.chat) {
|
val answerText = when (val chat = message.chat) {
|
||||||
is ChannelChat -> {
|
is ChannelChat -> {
|
||||||
val answer = "Hi everybody in this channel \"${chat.title}\""
|
val answer = "Hi everybody in this channel \"${chat.title}\""
|
||||||
reply(message, answer, MarkdownV2)
|
reply(message, answer, MarkdownV2)
|
||||||
return@onContentMessage
|
return@onMentionWithAnyContent
|
||||||
}
|
}
|
||||||
is PrivateChat -> {
|
is PrivateChat -> {
|
||||||
reply(message, "Hi, " + "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id), MarkdownV2)
|
reply(message, "Hi, " + "${chat.firstName} ${chat.lastName}".textMentionMarkdownV2(chat.id), MarkdownV2)
|
||||||
return@onContentMessage
|
return@onMentionWithAnyContent
|
||||||
}
|
}
|
||||||
is GroupChat -> {
|
is GroupChat -> {
|
||||||
message.ifFromChannelGroupContentMessage {
|
message.ifFromChannelGroupContentMessage {
|
||||||
val answer = "Hi, ${it.senderChat.title}"
|
val answer = "Hi, ${it.senderChat.title}"
|
||||||
reply(message, answer, MarkdownV2)
|
reply(message, answer, MarkdownV2)
|
||||||
return@onContentMessage
|
return@onMentionWithAnyContent
|
||||||
}
|
}
|
||||||
"Oh, hi, " + when (chat) {
|
"Oh, hi, " + when (chat) {
|
||||||
is SupergroupChat -> (chat.username ?.username ?: getChat(chat).inviteLink) ?.let {
|
is SupergroupChat -> (chat.username ?.username ?: getChat(chat).inviteLink) ?.let {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
# RandomFileSenderBot
|
# InlineQueriesBot
|
||||||
|
|
||||||
This bot will send random file from input folder OR from bot working folder
|
This bot will form the inline queries for you. For that feature you should explicitly enable inline queries in bot settings
|
||||||
|
|
||||||
## Launch
|
## Launch
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
../gradlew run --args="BOT_TOKEN[ optional/folder/path]"
|
../gradlew run --args="BOT_TOKEN"
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -13,11 +13,8 @@ import dev.inmo.tgbotapi.types.inlineQueryAnswerResultsLimit
|
|||||||
import dev.inmo.tgbotapi.utils.buildEntities
|
import dev.inmo.tgbotapi.utils.buildEntities
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This bot will send files inside of working directory OR from directory in the second argument.
|
* Thi bot will create inline query answers. You
|
||||||
* You may send /send_file command to this bot to get random file from the directory OR
|
* should enable inline queries in bot settings
|
||||||
* `/send_file $number` when you want to receive required number of files. For example,
|
|
||||||
* /send_file and `/send_file 1` will have the same effect - bot will send one random file.
|
|
||||||
* But if you will send `/send_file 5` it will choose 5 random files and send them as group
|
|
||||||
*/
|
*/
|
||||||
suspend fun doInlineQueriesBot(token: String) {
|
suspend fun doInlineQueriesBot(token: String) {
|
||||||
val bot = telegramBot(token)
|
val bot = telegramBot(token)
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ fun main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
appendText("Example button")
|
appendText("Exit button")
|
||||||
} ?: window.alert("Unable to load body")
|
} ?: window.alert("Unable to load body")
|
||||||
|
|
||||||
document.body ?.appendElement("p", {})
|
document.body ?.appendElement("p", {})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
import dev.inmo.micro_utils.ktor.server.createKtorServer
|
||||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.answers.answerInlineQuery
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||||
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
import dev.inmo.tgbotapi.extensions.api.bot.setMyCommands
|
||||||
import dev.inmo.tgbotapi.extensions.api.send.*
|
import dev.inmo.tgbotapi.extensions.api.send.*
|
||||||
@@ -9,6 +10,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
|||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling.*
|
||||||
import dev.inmo.tgbotapi.extensions.utils.formatting.makeTelegramStartattach
|
import dev.inmo.tgbotapi.extensions.utils.formatting.makeTelegramStartattach
|
||||||
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
import dev.inmo.tgbotapi.extensions.utils.types.buttons.*
|
||||||
|
import dev.inmo.tgbotapi.requests.answers.InlineQueryResultsButton
|
||||||
import dev.inmo.tgbotapi.types.BotCommand
|
import dev.inmo.tgbotapi.types.BotCommand
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.InlineQueryResultArticle
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputTextMessageContent
|
||||||
@@ -102,7 +104,7 @@ suspend fun main(vararg args: String) {
|
|||||||
onCommand("attachment_menu") {
|
onCommand("attachment_menu") {
|
||||||
reply(
|
reply(
|
||||||
it,
|
it,
|
||||||
,
|
"Button",
|
||||||
replyMarkup = inlineKeyboard {
|
replyMarkup = inlineKeyboard {
|
||||||
row {
|
row {
|
||||||
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
webAppButton("Open WebApp", WebAppInfo(args[1]))
|
||||||
@@ -111,6 +113,15 @@ suspend fun main(vararg args: String) {
|
|||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
onBaseInlineQuery {
|
||||||
|
answerInlineQuery(
|
||||||
|
it,
|
||||||
|
button = InlineQueryResultsButton.invoke(
|
||||||
|
"Open webApp",
|
||||||
|
WebAppInfo(args[1])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
onUnhandledCommand {
|
onUnhandledCommand {
|
||||||
reply(
|
reply(
|
||||||
it,
|
it,
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ org.gradle.parallel=true
|
|||||||
org.gradle.jvmargs=-Xmx2g
|
org.gradle.jvmargs=-Xmx2g
|
||||||
|
|
||||||
|
|
||||||
kotlin_version=1.8.20
|
kotlin_version=1.8.21
|
||||||
telegram_bot_api_version=7.1.0-branch_7.1.0-build1602
|
telegram_bot_api_version=8.0.1
|
||||||
micro_utils_version=0.17.8
|
micro_utils_version=0.19.2
|
||||||
serialization_version=1.5.0
|
serialization_version=1.5.1
|
||||||
ktor_version=2.3.0
|
ktor_version=2.3.1
|
||||||
|
|||||||
Reference in New Issue
Block a user