add faq info for sub context

This commit is contained in:
InsanusMokrassar 2023-06-14 13:09:52 +06:00
parent d15701b8e5
commit fa924076be
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,32 @@
# FAQ
## How to filter updates in some part of `BehaviourBuilder`?
You may create subcontext with
`BehaviourBuilder.`[`createSubContext`](https://tgbotapi.inmo.dev/tgbotapi.behaviour_builder/dev.inmo.tgbotapi.extensions.behaviour_builder/create-sub-context.html)
and pass there `updatesUpstreamFlow` parameter with any operations over parent behaviour builder:
```kotlin
buildBehaviourWithLongPolling {
createSubContext(
updatesUpstreamFlow = filter { /* some condition */ }
) {
onCommand() //...
}
}
```
### Additional info
* [Flows docs](https://kotlinlang.org/docs/flow.html#intermediate-flow-operators)
* [BehaviourBuilder](../logic/behaviour-builder.md)
### Cases
* Filtering of chats and users:
```kotlin
updatesUpstreamFlow = filter { it.sourceChat() ?.id == requiredChatId || it.sourceUser() ?.id == requiredUserId }
```
* **See**:
* [Update.sourceChat](https://tgbotapi.inmo.dev/tgbotapi.utils/dev.inmo.tgbotapi.extensions.utils.extensions/source-chat.html)
* [Update.sourceUser](https://tgbotapi.inmo.dev/tgbotapi.utils/dev.inmo.tgbotapi.extensions.utils.extensions/source-user.html)

View File

@ -18,6 +18,7 @@ nav:
- 'tgbotapi/introduction/first-bot.md'
- Guides:
- 'tgbotapi/guides/keyboards.md'
- 'tgbotapi/guides/faq.md'
- Updates retrieving:
- 'tgbotapi/updates/updates-filters.md'
- 'tgbotapi/updates/long-polling.md'