-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ff6412
commit 1b5b3af
Showing
3 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/SendData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |