mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI-examples.git
synced 2026-08-29 04:16:27 +00:00
update readmes
This commit is contained in:
75
ResenderBot/README.md
Normal file
75
ResenderBot/README.md
Normal file
@@ -0,0 +1,75 @@
|
||||
# ResenderBot
|
||||
|
||||
A multiplatform long-polling example that recreates received content in the same
|
||||
chat. Shared behavior lives in `ResenderBotLib`; JVM, browser/JS, and native entry
|
||||
points start it in platform-specific ways.
|
||||
|
||||
## Resend behavior
|
||||
|
||||
The bot defines no commands. For each content message, it shows a typing action and
|
||||
uses `createResend` to send equivalent content back to the originating chat. When
|
||||
present, it carries over the replied-to message metadata, text quote entities and
|
||||
position, and the message effect ID.
|
||||
|
||||
Business content sent by the business-connection owner is ignored; other delivered
|
||||
content messages are eligible. Processing is separated by chat. The bot prints each
|
||||
received update and each resend result, and reports its `getMe` result through the
|
||||
launcher's output callback.
|
||||
|
||||
## Source sets and launchers
|
||||
|
||||
- `ResenderBotLib/commonMain` provides the public `activateResenderBot` function and
|
||||
all Telegram handlers for JVM, JS, and native consumers.
|
||||
- `ResenderBotLib/jsMain` provides a browser form. Each submission starts another
|
||||
bot and displays callback output in its own page element; console output remains
|
||||
in the browser developer tools.
|
||||
- `jvm_launcher` provides a suspending CLI entry point and optional debug logging.
|
||||
- `native_launcher` wraps the shared suspending function in `runBlocking`. Its
|
||||
shared native template selects Linux x64/Arm64 or Windows x64 for the host.
|
||||
|
||||
## Setup and permissions
|
||||
|
||||
Create a bot, obtain its token, and keep it private. Start a private chat with the
|
||||
bot or add it to a chat where Telegram will deliver the desired content. The bot
|
||||
must be allowed to send each content type it should reproduce; no administrator-only
|
||||
methods are used. Long polling is used, so run only one launcher per token.
|
||||
|
||||
The browser form handles the token in client-side code and uses a plain text input.
|
||||
Use it only on a trusted local page, submit once, and close the page when finished.
|
||||
Linux native builds also require the repository's documented libcurl dependency.
|
||||
|
||||
## Run from the repository root
|
||||
|
||||
### JVM
|
||||
|
||||
The first argument is the required token. `debug` is recognized only as the second
|
||||
argument; later arguments are ignored.
|
||||
|
||||
```bash
|
||||
./gradlew :ResenderBot:jvm_launcher:run --args="BOT_TOKEN"
|
||||
./gradlew :ResenderBot:jvm_launcher:run --args="BOT_TOKEN debug"
|
||||
```
|
||||
|
||||
### Browser/JS
|
||||
|
||||
```bash
|
||||
./gradlew :ResenderBot:ResenderBotLib:jsBrowserDevelopmentRun
|
||||
```
|
||||
|
||||
Enter the token in the page form and select **Start bot**. There are no browser
|
||||
command-line arguments.
|
||||
|
||||
### Kotlin/Native
|
||||
|
||||
Build the host-specific debug executable, then pass the required token directly to
|
||||
it. Additional native arguments are ignored.
|
||||
|
||||
```bash
|
||||
./gradlew :ResenderBot:native_launcher:linkDebugExecutableNative
|
||||
./ResenderBot/native_launcher/build/bin/native/debugExecutable/native_launcher.kexe "BOT_TOKEN"
|
||||
```
|
||||
|
||||
On Windows, run
|
||||
`ResenderBot\\native_launcher\\build\\bin\\native\\debugExecutable\\native_launcher.exe "BOT_TOKEN"`
|
||||
after the same Gradle link task. macOS hosts are not configured by the native
|
||||
launcher template.
|
||||
@@ -20,6 +20,16 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
|
||||
/**
|
||||
* Starts the shared long-polling resender and suspends until polling stops.
|
||||
*
|
||||
* Eligible content is recreated in its source chat with reply/quote metadata and
|
||||
* message effects preserved. Business messages sent by the business-connection
|
||||
* owner are skipped.
|
||||
*
|
||||
* @param token bot token used for polling and API requests.
|
||||
* @param print output callback for bot information and resend diagnostics.
|
||||
*/
|
||||
suspend fun activateResenderBot(
|
||||
token: String,
|
||||
print: (Any) -> Unit
|
||||
|
||||
@@ -4,6 +4,10 @@ import org.w3c.dom.*
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.Default)
|
||||
|
||||
/**
|
||||
* Installs the browser token form and starts one resender for each submission.
|
||||
* Callback output from each instance is displayed in its associated page element.
|
||||
*/
|
||||
fun main() {
|
||||
document.addEventListener(
|
||||
"DOMContentLoaded",
|
||||
|
||||
@@ -3,6 +3,12 @@ import dev.inmo.kslog.common.LogLevel
|
||||
import dev.inmo.kslog.common.defaultMessageFormatter
|
||||
import dev.inmo.kslog.common.setDefaultKSLog
|
||||
|
||||
/**
|
||||
* Starts the JVM resender launcher.
|
||||
*
|
||||
* [args] must contain the bot token first. An optional exact `debug` value in the
|
||||
* second position enables diagnostic logging; later elements are ignored.
|
||||
*/
|
||||
suspend fun main(args: Array<String>) {
|
||||
val isDebug = args.getOrNull(1) == "debug"
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import kotlinx.coroutines.runBlocking
|
||||
|
||||
/**
|
||||
* Starts the native resender launcher with the first element of [args] as its bot
|
||||
* token. Later elements are ignored.
|
||||
*/
|
||||
fun main(vararg args: String) {
|
||||
runBlocking {
|
||||
activateResenderBot(args.first()) {
|
||||
|
||||
Reference in New Issue
Block a user