mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-09-28 03:14:39 +00:00
update examples for ktgbotapi 37.0.0
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
|
||||
DraftsBot demonstrates streaming a message draft before sending the finished
|
||||
message. It receives updates through long polling and uses the same built-in
|
||||
Lorem ipsum text for both examples.
|
||||
Lorem ipsum text for all examples. Bot API 10.3's stoppable generation controls
|
||||
and `stopped_message_generation` updates are included.
|
||||
|
||||
## Commands
|
||||
|
||||
@@ -10,18 +11,32 @@ Lorem ipsum text for both examples.
|
||||
500 ms, then sends the complete text as a normal message.
|
||||
- `/test_empty_draft` first publishes an empty draft, waits 1.5 seconds, streams
|
||||
the same prefixes, and then sends the complete text.
|
||||
- `/test_stoppable_draft` continuously streams progressively longer revisions
|
||||
with `canStop = true` and `keepOnStop = true`. Telegram displays a stop control;
|
||||
stopping keeps the most recent draft revision and causes the flow helper to
|
||||
return `false`. Before streaming, the handler subscribes to
|
||||
`waitMessageGenerationStopped` and filters the expectation by chat and draft
|
||||
ID, then logs the matched stop event. It deliberately sends no confirmation
|
||||
message, because sending one would immediately remove the draft retained by
|
||||
`keepOnStop`. If streaming ends because of another request failure and no
|
||||
matching update arrives within five seconds, the bot logs that distinction
|
||||
instead of waiting forever.
|
||||
|
||||
The bot advertises both commands in Telegram's command menu for all group chats.
|
||||
The handlers themselves are not restricted by chat type, so either command can
|
||||
also be entered manually in a private chat.
|
||||
The bot advertises all three commands in Telegram's command menu for private
|
||||
chats and filters each handler to private chats, as required by Telegram's draft
|
||||
methods.
|
||||
|
||||
The typed `onMessageGenerationStopped` handler logs the chat, optional topic ID,
|
||||
and draft ID from every generation-stopped update, independently of the scoped
|
||||
expectation used by `/test_stoppable_draft`. Both apply to text and rich-message
|
||||
drafts sent by this bot token.
|
||||
|
||||
## Setup
|
||||
|
||||
1. Obtain a bot token and keep it out of source control.
|
||||
2. Start a private chat with the bot, or add it to a group where you want to run
|
||||
the example.
|
||||
3. In groups, allow the bot to send messages. No administrator rights are
|
||||
otherwise required by this example.
|
||||
2. Start a private chat with the bot. Telegram doesn't accept a group or channel
|
||||
ID for `sendMessageDraft`.
|
||||
3. No administrator rights are required by this example.
|
||||
|
||||
The first program argument is required and must be the bot token. Omitting it
|
||||
causes startup to fail; any later arguments are ignored.
|
||||
@@ -34,8 +49,6 @@ From the repository root, run:
|
||||
./gradlew :DraftsBot:run --args="<BOT_TOKEN>"
|
||||
```
|
||||
|
||||
> **Known issue:** `DraftsBot/build.gradle` currently declares `TopicsHandlingKt` as the main class, while this bot's entry point is `DraftsBotKt`. The `run` task cannot start until that Gradle setting is corrected; it is left unchanged by this documentation-only update.
|
||||
|
||||
Every received update is printed to standard output. Unhandled polling errors
|
||||
are printed with their stack traces, and HTTP request, socket, and connection
|
||||
timeouts are each configured to 30 seconds.
|
||||
|
||||
Reference in New Issue
Block a user