From 32b83ac6875dcc7509b973475785c2d152eb992c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 May 2022 12:51:14 +0600 Subject: [PATCH 1/3] start 0.38.21 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7390ed2954..665fb5c847 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.38.21 + ## 0.38.20 * `BehaviourBuilder FSM`: diff --git a/gradle.properties b/gradle.properties index f9b76a73b9..41eec25c51 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.20 +library_version=0.38.21 github_release_plugin_version=2.3.7 From aa6e5b22841f0de32ec1c19c1618ebd1f4ace94d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 May 2022 12:58:06 +0600 Subject: [PATCH 2/3] fix of WebAppInitData#queryId js name --- CHANGELOG.md | 3 +++ .../jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppInitData.kt | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 665fb5c847..50bdf79304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.38.21 +* `WebApps`: + * `WebAppInitData#queryId` now have correct js name of field + ## 0.38.20 * `BehaviourBuilder FSM`: diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppInitData.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppInitData.kt index a00181ab91..a561cfb89a 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppInitData.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebAppInitData.kt @@ -1,9 +1,9 @@ package dev.inmo.tgbotapi.webapps -import dev.inmo.tgbotapi.types.MilliSeconds -import dev.inmo.tgbotapi.types.WebAppQueryId +import dev.inmo.tgbotapi.types.* external interface WebAppInitData { + @JsName("query_id") val queryId: WebAppQueryId? val user: WebAppUser? From f36d642ec8fd3614aecb3b4c6096e103b9cf056e Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 4 May 2022 13:05:54 +0600 Subject: [PATCH 3/3] sendDataOrWorkWithQueryId --- CHANGELOG.md | 1 + .../dev/inmo/tgbotapi/webapps/SendData.kt | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50bdf79304..fe957764ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * `WebApps`: * `WebAppInitData#queryId` now have correct js name of field + * New function `sendDataOrWorkWithQueryId` ## 0.38.20 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 index 5f469cfd0f..bd6ebb191f 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SendData.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SendData.kt @@ -8,11 +8,26 @@ import dev.inmo.tgbotapi.types.WebAppQueryId * 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( +inline fun sendDataOrWorkWithQueryId( onSendData: () -> String?, onAnswerWebAppQuery: (WebAppQueryId) -> Unit ) { - webApp.initDataUnsafe.queryId ?.let { - onAnswerWebAppQuery(it) - } ?: webApp.sendData(onSendData() ?: return) + val queryId = webApp.initDataUnsafe.queryId + + if (queryId == null) { + webApp.sendData(onSendData() ?: return) + } else { + onAnswerWebAppQuery(queryId) + } } + +/** + * @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 +) = sendDataOrWorkWithQueryId(onSendData, onAnswerWebAppQuery)