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

+4 -5
View File
@@ -4,7 +4,8 @@ A long-polling example that prints information about the bot and lets Telegram u
## Behavior
At startup, the application prints the results of `getMe` and `getChat` for the bot itself to standard output. It then handles two commands:
At startup, the application prints the `BotFullInfo` returned by `getMe`, including active usernames and bot settings.
It passes that object's `id` to `getChat` to print the bot's chat profile. It then handles two commands:
- `/setMyProfilePhoto` replies with `ok, send me new photo` and waits for the first photo sent in the same chat. It streams draft progress messages while downloading the photo to a temporary file, uploads it as a static bot profile photo, and replies when the change is complete. The photo may come from any user in that chat; it is not restricted to the user who sent the command.
- `/removeMyProfilePhoto` removes the bot's current profile photo and confirms success. On failure, it prints the exception and sends a generic error reply.
@@ -24,13 +25,13 @@ There is no `/start` handler, and ordinary messages are ignored unless the bot i
The first argument is always the required bot token. Optional arguments can follow it in any order:
- `debug` enables formatted default KSLog output.
- `testServer` makes the behavior and long-polling client use Telegram's Bot API test environment. The initial `getMe` and `getChat` diagnostics currently use a separate default-server client.
- `testServer` runs the startup diagnostics and polling against Telegram's Bot API test environment.
Other arguments are ignored. Argument matching is case-sensitive.
## Launch
The intended command from the repository root is:
Run from the repository root:
```bash
./gradlew :MyBot:run --args="<BOT_TOKEN>"
@@ -41,5 +42,3 @@ For example, to enable both optional modes:
```bash
./gradlew :MyBot:run --args="<BOT_TOKEN> debug testServer"
```
> **Known issue:** `MyBot/build.gradle` still declares the old `GetMeBotKt` main class, while the current source produces `MyBotKt`. Consequently, the `run` task cannot start until that build setting is corrected. It is left unchanged here because this example update is documentation-only.
+1 -1
View File
@@ -11,7 +11,7 @@ buildscript {
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName="GetMeBotKt"
application.mainClass = "MyBotKt"
dependencies {
+2 -5
View File
@@ -4,7 +4,6 @@ import dev.inmo.kslog.common.defaultMessageFormatter
import dev.inmo.kslog.common.setDefaultKSLog
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
import dev.inmo.micro_utils.coroutines.runCatchingLogging
import dev.inmo.tgbotapi.bot.ktor.telegramBot
import dev.inmo.tgbotapi.extensions.api.bot.getMe
import dev.inmo.tgbotapi.extensions.api.bot.removeMyProfilePhoto
import dev.inmo.tgbotapi.extensions.api.bot.setMyProfilePhoto
@@ -47,16 +46,14 @@ suspend fun main(vararg args: String) {
)
}
val bot = telegramBot(botToken)
telegramBotWithBehaviourAndLongPolling(
botToken,
CoroutineScope(Dispatchers.Default),
testServer = isTestServer,
) {
val me = bot.getMe()
val me = getMe()
println(me)
println(bot.getChat(me))
println(getChat(me.id))
onCommand("setMyProfilePhoto") { commandMessage ->
reply(commandMessage, "ok, send me new photo")