mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
Compare commits
8 Commits
a2206b99a2
...
ae639d38e0
Author | SHA1 | Date | |
---|---|---|---|
ae639d38e0 | |||
0510f72859 | |||
233c789054 | |||
52f405c3b1 | |||
199856acce | |||
f36d642ec8 | |||
aa6e5b2284 | |||
32b83ac687 |
12
CHANGELOG.md
12
CHANGELOG.md
@ -47,6 +47,18 @@ __All the `tgbotapi.extensions.*` packages have been removed__
|
|||||||
* `BehaviourBuilder`:
|
* `BehaviourBuilder`:
|
||||||
* `SimpleFilter` now is a `fun interface` instead of just callback (fix of [#546](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/546))
|
* `SimpleFilter` now is a `fun interface` instead of just callback (fix of [#546](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/546))
|
||||||
|
|
||||||
|
## 0.38.22
|
||||||
|
|
||||||
|
* `Core`:
|
||||||
|
* New constant `tgWebAppStartParamField`
|
||||||
|
* All keyboards builders and rows blocks becomes not crossinline
|
||||||
|
|
||||||
|
## 0.38.21
|
||||||
|
|
||||||
|
* `WebApps`:
|
||||||
|
* `WebAppInitData#queryId` now have correct js name of field
|
||||||
|
* New function `sendDataOrWorkWithQueryId`
|
||||||
|
|
||||||
## 0.38.20
|
## 0.38.20
|
||||||
|
|
||||||
* `BehaviourBuilder FSM`:
|
* `BehaviourBuilder FSM`:
|
||||||
|
@ -96,6 +96,8 @@ val telegramInlineModeGifPermittedMimeTypes by lazy {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const val tgWebAppStartParamField = "tgWebAppStartParam"
|
||||||
|
|
||||||
const val chatIdField = "chat_id"
|
const val chatIdField = "chat_id"
|
||||||
const val senderChatIdField = "sender_chat_id"
|
const val senderChatIdField = "sender_chat_id"
|
||||||
const val messageIdField = "message_id"
|
const val messageIdField = "message_id"
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package dev.inmo.tgbotapi.utils.extensions
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.tgWebAppStartParamField
|
||||||
|
|
||||||
|
fun createWebAppStartParam(value: String) = tgWebAppStartParamField to value
|
@ -37,7 +37,7 @@ class InlineKeyboardRowBuilder : RowBuilder<InlineKeyboardButton>()
|
|||||||
* @see InlineKeyboardBuilder.row
|
* @see InlineKeyboardBuilder.row
|
||||||
*/
|
*/
|
||||||
inline fun inlineKeyboard(
|
inline fun inlineKeyboard(
|
||||||
crossinline block: InlineKeyboardBuilder.() -> Unit
|
block: InlineKeyboardBuilder.() -> Unit
|
||||||
) = InlineKeyboardBuilder().apply(block).build()
|
) = InlineKeyboardBuilder().apply(block).build()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,7 +52,7 @@ inline fun inlineKeyboard(
|
|||||||
* @see urlButton
|
* @see urlButton
|
||||||
*/
|
*/
|
||||||
inline fun InlineKeyboardBuilder.row(
|
inline fun InlineKeyboardBuilder.row(
|
||||||
crossinline block: InlineKeyboardRowBuilder.() -> Unit
|
block: InlineKeyboardRowBuilder.() -> Unit
|
||||||
) = add(InlineKeyboardRowBuilder().apply(block).row)
|
) = add(InlineKeyboardRowBuilder().apply(block).row)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,7 +44,7 @@ inline fun replyKeyboard(
|
|||||||
oneTimeKeyboard: Boolean? = null,
|
oneTimeKeyboard: Boolean? = null,
|
||||||
inputFieldPlaceholder: String? = null,
|
inputFieldPlaceholder: String? = null,
|
||||||
selective: Boolean? = null,
|
selective: Boolean? = null,
|
||||||
crossinline block: ReplyKeyboardBuilder.() -> Unit
|
block: ReplyKeyboardBuilder.() -> Unit
|
||||||
) = ReplyKeyboardBuilder().apply(block).build(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective)
|
) = ReplyKeyboardBuilder().apply(block).build(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,7 +56,7 @@ inline fun replyKeyboard(
|
|||||||
* @see requestPollButton
|
* @see requestPollButton
|
||||||
*/
|
*/
|
||||||
inline fun ReplyKeyboardBuilder.row(
|
inline fun ReplyKeyboardBuilder.row(
|
||||||
crossinline block: ReplyKeyboardRowBuilder.() -> Unit
|
block: ReplyKeyboardRowBuilder.() -> Unit
|
||||||
) = add(ReplyKeyboardRowBuilder().apply(block).row)
|
) = add(ReplyKeyboardRowBuilder().apply(block).row)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,3 +110,14 @@ inline fun ReplyKeyboardRowBuilder.webAppButton(
|
|||||||
text: String,
|
text: String,
|
||||||
webApp: WebAppInfo
|
webApp: WebAppInfo
|
||||||
) = add(WebAppKeyboardButton(text, webApp))
|
) = add(WebAppKeyboardButton(text, webApp))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and put [WebAppKeyboardButton]
|
||||||
|
*
|
||||||
|
* @see replyKeyboard
|
||||||
|
* @see ReplyKeyboardBuilder.row
|
||||||
|
*/
|
||||||
|
inline fun ReplyKeyboardRowBuilder.webAppButton(
|
||||||
|
text: String,
|
||||||
|
url: String
|
||||||
|
) = webAppButton(text, WebAppInfo(url))
|
||||||
|
@ -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
|
* 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
|
* system, so, you must use something like [answerWebAppQuery] by yourself to send the result
|
||||||
*/
|
*/
|
||||||
inline fun handleResult(
|
inline fun sendDataOrWorkWithQueryId(
|
||||||
onSendData: () -> String?,
|
onSendData: () -> String?,
|
||||||
onAnswerWebAppQuery: (WebAppQueryId) -> Unit
|
onAnswerWebAppQuery: (WebAppQueryId) -> Unit
|
||||||
) {
|
) {
|
||||||
webApp.initDataUnsafe.queryId ?.let {
|
val queryId = webApp.initDataUnsafe.queryId
|
||||||
onAnswerWebAppQuery(it)
|
|
||||||
} ?: webApp.sendData(onSendData() ?: return)
|
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)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package dev.inmo.tgbotapi.webapps
|
package dev.inmo.tgbotapi.webapps
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.types.MilliSeconds
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.WebAppQueryId
|
|
||||||
|
|
||||||
external interface WebAppInitData {
|
external interface WebAppInitData {
|
||||||
|
@JsName("query_id")
|
||||||
val queryId: WebAppQueryId?
|
val queryId: WebAppQueryId?
|
||||||
|
|
||||||
val user: WebAppUser?
|
val user: WebAppUser?
|
||||||
|
Loading…
Reference in New Issue
Block a user