From fa924076be215b9afcd507664cc79210fee4df0a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 14 Jun 2023 13:09:52 +0600 Subject: [PATCH] add faq info for sub context --- docs/tgbotapi/guides/faq.md | 32 ++++++++++++++++++++++++++++++++ mkdocs.yml | 1 + 2 files changed, 33 insertions(+) create mode 100644 docs/tgbotapi/guides/faq.md diff --git a/docs/tgbotapi/guides/faq.md b/docs/tgbotapi/guides/faq.md new file mode 100644 index 0000000..97b342e --- /dev/null +++ b/docs/tgbotapi/guides/faq.md @@ -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) diff --git a/mkdocs.yml b/mkdocs.yml index a55fea5..ece63fa 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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'