Merge pull request #581 from InsanusMokrassar/0.38.21

0.38.21
This commit is contained in:
InsanusMokrassar 2022-05-04 13:35:08 +06:00 committed by GitHub
commit 199856acce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 7 deletions

View File

@ -1,5 +1,11 @@
# TelegramBotAPI changelog
## 0.38.21
* `WebApps`:
* `WebAppInitData#queryId` now have correct js name of field
* New function `sendDataOrWorkWithQueryId`
## 0.38.20
* `BehaviourBuilder FSM`:

View File

@ -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

View File

@ -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)

View File

@ -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?