mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-02 06:39:41 +00:00
Merge branch 'master' into 1.0.0
This commit is contained in:
@@ -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))
|
||||
}
|
@@ -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)
|
||||
}
|
Reference in New Issue
Block a user