mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-11-27 05:43:14 +00:00
update examples for ktgbotapi 38.0.0
This commit is contained in:
1 parent
d0da6c851b
commit
97b4391495
86 files changed
+888
-370
No files matched your search
@@ -17,11 +17,9 @@ The bot also prints its own account information at startup, logs received update
|
||||
|
||||
## Setup
|
||||
|
||||
Create a bot and obtain its token, then enable inline mode for it in BotFather (for example, with `/setinline`). Keep the
|
||||
token private.
|
||||
|
||||
Both launchers require the bot token as the first command-line argument. Starting either launcher without an argument
|
||||
fails immediately; additional arguments are ignored.
|
||||
Create a bot and obtain its token. To enable inline mode and set the search placeholder through `setMySettings`,
|
||||
pass `configureInline` after the token on either launcher. Telegram saves both settings, so subsequent launches only
|
||||
need the token. You can also enable inline mode through BotFather.
|
||||
|
||||
## Launch from the repository root
|
||||
|
||||
@@ -31,6 +29,12 @@ fails immediately; additional arguments are ignored.
|
||||
./gradlew :InlineQueriesBot:runJvm --args="<BOT_TOKEN>"
|
||||
```
|
||||
|
||||
To configure inline mode on the first run:
|
||||
|
||||
```bash
|
||||
./gradlew :InlineQueriesBot:runJvm --args="<BOT_TOKEN> configureInline"
|
||||
```
|
||||
|
||||
### Kotlin/Native
|
||||
|
||||
The shared native configuration supports Linux x64/Arm64 and Windows x64 hosts. Build the debug executable with Gradle,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import dev.inmo.micro_utils.coroutines.subscribeLoggingDropExceptions
|
||||
import dev.inmo.tgbotapi.extensions.api.answers.answer
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.getMe
|
||||
import dev.inmo.tgbotapi.extensions.api.bot.setMySettings
|
||||
import dev.inmo.tgbotapi.extensions.api.send.reply
|
||||
import dev.inmo.tgbotapi.extensions.api.telegramBot
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.buildBehaviourWithLongPolling
|
||||
@@ -16,8 +17,14 @@ import dev.inmo.tgbotapi.utils.buildEntities
|
||||
/**
|
||||
* Starts the inline-query bot with [token] and suspends until long polling stops.
|
||||
*/
|
||||
suspend fun doInlineQueriesBot(token: String) {
|
||||
suspend fun doInlineQueriesBot(token: String, configureInline: Boolean = false) {
|
||||
val bot = telegramBot(token)
|
||||
if (configureInline) {
|
||||
bot.setMySettings(
|
||||
supportsInlineQueries = true,
|
||||
inlineQueryPlaceholder = "Search numbered articles"
|
||||
)
|
||||
}
|
||||
|
||||
bot.buildBehaviourWithLongPolling(
|
||||
defaultExceptionsHandler = { it.printStackTrace() },
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** JVM entry point; [args] must contain the bot token as its first element. */
|
||||
suspend fun main(args: Array<String>) {
|
||||
doInlineQueriesBot(args.first())
|
||||
doInlineQueriesBot(args.first(), configureInline = "configureInline" in args)
|
||||
}
|
||||
@@ -3,6 +3,6 @@ import kotlinx.coroutines.runBlocking
|
||||
/** Kotlin/Native entry point; [args] must contain the bot token as its first element. */
|
||||
fun main(args: Array<String>) {
|
||||
runBlocking {
|
||||
doInlineQueriesBot(args.first())
|
||||
doInlineQueriesBot(args.first(), configureInline = "configureInline" in args)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user