Skip to content

Commit

Permalink
add handleResult
Browse files Browse the repository at this point in the history
  • Loading branch information
InsanusMokrassar committed May 4, 2022
1 parent 7ff6412 commit 1b5b3af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Hotfixes
* `WebApps`:
* New extension `TelegramBot#answerWebAppQuery`
* New function `handleResult`

## 0.38.19

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 1b5b3af

Please sign in to comment.