mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-08-28 11:56:25 +00:00
update readmes
This commit is contained in:
@@ -1,9 +1,41 @@
|
||||
# Drafts bot
|
||||
# DraftsBot
|
||||
|
||||
The main purpose of this bot is just to answer "Oh, hi, " and add user mention here
|
||||
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.
|
||||
|
||||
## Launch
|
||||
## Commands
|
||||
|
||||
- `/test_draft_flow` publishes progressively longer 50-character prefixes every
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
## 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.
|
||||
|
||||
The first program argument is required and must be the bot token. Omitting it
|
||||
causes startup to fail; any later arguments are ignored.
|
||||
|
||||
## Run
|
||||
|
||||
From the repository root, run:
|
||||
|
||||
```bash
|
||||
../gradlew run --args="BOT_TOKEN"
|
||||
./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.
|
||||
|
||||
@@ -37,10 +37,19 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.isActive
|
||||
|
||||
/** Sample text streamed as a draft and then sent as the completed message. */
|
||||
const val testText = """
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
"""
|
||||
|
||||
/**
|
||||
* Starts DraftsBot with long polling and registers the draft demonstration commands.
|
||||
*
|
||||
* The first element of [args] must be the bot token; subsequent elements are ignored.
|
||||
* This function remains suspended until the polling job completes.
|
||||
*
|
||||
* @throws NoSuchElementException when no bot token is supplied
|
||||
*/
|
||||
suspend fun main(vararg args: String) {
|
||||
telegramBotWithBehaviourAndLongPolling(
|
||||
args.first(),
|
||||
|
||||
Reference in New Issue
Block a user