add note about behaviour builder long polling

This commit is contained in:
InsanusMokrassar 2024-05-29 16:31:26 +06:00
parent 228c7704f5
commit 0931cbd97d

View File

@ -66,3 +66,62 @@ bot.buildBehaviour {
} }
} }
``` ```
## Long polling
In case you wish to start long polling, you have two options:
* Start long polling with `buildBehaviour` additional functions
* Start long polling from using the result of `buildBehaviour`
> NOTE: **More info**
>
> More info about updates retrieving you may read at the [Long Polling](../updates/long-polling.md) and [Webhooks](../updates/webhooks.md)
> articles
### Long polling from `buildBehaviour`
With prepared bot:
```kotlin
val bot = telegramBot("TOKEN")
bot.buildBehaviourWithLongPolling {
onCommand(
"start",
requireOnlyCommandInMessage = true // it is default, but you can overwrite it with `requireOnlyCommandInMessage = false`
) {
// ...
}
}
```
Without prepared bot:
```kotlin
telegramBotWithBehaviourAndLongPolling("TOKEN") {
onCommand(
"start",
requireOnlyCommandInMessage = true // it is default, but you can overwrite it with `requireOnlyCommandInMessage = false`
) {
// ...
}
}
```
### Long polling from the result of behaviour building
```kotlin
val bot = telegramBot("TOKEN")
val rootContext = bot.buildBehaviour {
onCommand(
"start",
requireOnlyCommandInMessage = true // it is default, but you can overwrite it with `requireOnlyCommandInMessage = false`
) {
// ...
}
}
bot.longPolling(rootContext) // start listening updates
```