mirror of
https://github.com/InsanusMokrassar/docs.git
synced 2024-11-26 03:58:55 +00:00
add faq info for sub context
This commit is contained in:
parent
d15701b8e5
commit
fa924076be
32
docs/tgbotapi/guides/faq.md
Normal file
32
docs/tgbotapi/guides/faq.md
Normal 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)
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user