From 08147fc33b9c32db7be22b00b5ecda0ca96a5d86 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 3 May 2022 23:11:02 +0600 Subject: [PATCH 1/4] start 0.38.20 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ececa0b868..fe13a60008 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.38.20 + ## 0.38.19 * `BehaviourBuilder`: diff --git a/gradle.properties b/gradle.properties index 0401f4f412..f9b76a73b9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,6 +20,6 @@ javax_activation_version=1.1.1 dokka_version=1.6.10 library_group=dev.inmo -library_version=0.38.19 +library_version=0.38.20 github_release_plugin_version=2.3.7 From bd23d3fbdba575378ed710e53f633c3e619fc32f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 3 May 2022 23:12:03 +0600 Subject: [PATCH 2/4] hotfixes --- CHANGELOG.md | 3 +++ .../behaviour_builder/BehaviourContextWithFSM.kt | 4 +++- .../BehaviourWithFSMStateHandlerHolder.kt | 13 ++----------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe13a60008..3e046ea721 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.38.20 +* `BehaviourBuilder FSM`: + * Hotfixes + ## 0.38.19 * `BehaviourBuilder`: diff --git a/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt b/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt index 6212a4134a..2bb6b3ea89 100644 --- a/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt +++ b/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContextWithFSM.kt @@ -28,7 +28,9 @@ interface BehaviourContextWithFSM : BehaviourContext, StatesMachine> ): T? { return handlers.firstOrNull { it.checkHandleable(state) } ?.run { - handleState(contextUpdatesFlow, state) + doInSubContext(updatesUpstreamFlow = contextUpdatesFlow) { + handleState(state) + } } } diff --git a/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourWithFSMStateHandlerHolder.kt b/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourWithFSMStateHandlerHolder.kt index 788c1cf3c1..fa3bdbd0e2 100644 --- a/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourWithFSMStateHandlerHolder.kt +++ b/tgbotapi.behaviour_builder.fsm/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourWithFSMStateHandlerHolder.kt @@ -34,20 +34,11 @@ class BehaviourWithFSMStateHandlerHolder( /** * Handling of state :) - * - * @param contextUpdatesFlow This [Flow] will be used as source of updates. By contract, this [Flow] must be common - * for all [State]s of incoming [state] [State.context] and for the whole chain inside of [BehaviourContextWithFSM] */ suspend fun BehaviourContextWithFSM.handleState( - contextUpdatesFlow: Flow, state: O - ): O? { - val subscope = scope.LinkedSupervisorScope() - return with(copy(scope = subscope, upstreamUpdatesFlow = contextUpdatesFlow)) { - with(delegateTo) { - handleState(state as I) - } - } + ): O? = with(delegateTo) { + handleState(state as I) } } From 7ff6412ec58bd4217106adf0b3f4bed66045b5a7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 May 2022 10:50:08 +0600 Subject: [PATCH 3/4] TelegramBot#answerWebAppQuery --- CHANGELOG.md | 2 ++ .../dev/inmo/tgbotapi/webapps/AnswerWebAppQuery.kt | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/AnswerWebAppQuery.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e046ea721..c0df72cb80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * `BehaviourBuilder FSM`: * Hotfixes +* `WebApps`: + * New extension `TelegramBot#answerWebAppQuery` ## 0.38.19 diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/AnswerWebAppQuery.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/AnswerWebAppQuery.kt new file mode 100644 index 0000000000..c77aa0b763 --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/AnswerWebAppQuery.kt @@ -0,0 +1,11 @@ +package dev.inmo.tgbotapi.webapps + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.answers.AnswerWebAppQuery +import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult + +suspend fun TelegramBot.answerWebAppQuery( + result: InlineQueryResult +) = webApp.initDataUnsafe.queryId ?.let { + execute(AnswerWebAppQuery(it, result)) +} From 1b5b3af45bb333b10df530b0440886ebc077f5c1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 May 2022 11:01:26 +0600 Subject: [PATCH 4/4] add handleResult --- CHANGELOG.md | 1 + .../requests/answers/AnswerWebAppQuery.kt | 3 +++ .../dev/inmo/tgbotapi/webapps/SendData.kt | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SendData.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index c0df72cb80..7390ed2954 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Hotfixes * `WebApps`: * New extension `TelegramBot#answerWebAppQuery` + * New function `handleResult` ## 0.38.19 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerWebAppQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerWebAppQuery.kt index ceacda665f..859959aebb 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerWebAppQuery.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerWebAppQuery.kt @@ -6,6 +6,9 @@ import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQ import dev.inmo.tgbotapi.types.webapps.query.SentWebAppMessage import kotlinx.serialization.* +/** + * @param webAppQueryId [dev.inmo.tgbotapi.webapps.WebAppInitData.queryId] + */ @Serializable data class AnswerWebAppQuery( @SerialName(webAppQueryIdField) diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SendData.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SendData.kt new file mode 100644 index 0000000000..5f469cfd0f --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SendData.kt @@ -0,0 +1,18 @@ +package dev.inmo.tgbotapi.webapps + +import dev.inmo.tgbotapi.types.WebAppQueryId + +/** + * @param onSendData Should return the data which must be used in [WebApp.sendData]. If returns null, data will not be sent + * @param onAnswerWebAppQuery In case if [WebAppInitData.queryId] is presented in [WebApp.initDataUnsafe], will be called + * that callback. Before and after calling of this callback will not be used any method of answering to the telegram + * system, so, you must use something like [answerWebAppQuery] by yourself to send the result + */ +inline fun handleResult( + onSendData: () -> String?, + onAnswerWebAppQuery: (WebAppQueryId) -> Unit +) { + webApp.initDataUnsafe.queryId ?.let { + onAnswerWebAppQuery(it) + } ?: webApp.sendData(onSendData() ?: return) +}