mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-12-04 13:26:57 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 233c789054 | |||
| 52f405c3b1 | |||
| 199856acce | |||
| f36d642ec8 | |||
| aa6e5b2284 | |||
| 32b83ac687 | |||
| 90e0b1ac81 | |||
| 1b5b3af45b | |||
| 7ff6412ec5 | |||
| bd23d3fbdb | |||
| 08147fc33b | |||
| ba4c153659 |
20
CHANGELOG.md
20
CHANGELOG.md
@@ -1,5 +1,25 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 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
|
||||
|
||||
* `BehaviourBuilder FSM`:
|
||||
* Hotfixes
|
||||
* `WebApps`:
|
||||
* New extension `TelegramBot#answerWebAppQuery`
|
||||
* New function `handleResult`
|
||||
|
||||
## 0.38.19
|
||||
|
||||
* `BehaviourBuilder`:
|
||||
|
||||
@@ -20,6 +20,6 @@ javax_activation_version=1.1.1
|
||||
dokka_version=1.6.10
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=0.38.19
|
||||
library_version=0.38.22
|
||||
|
||||
github_release_plugin_version=2.3.7
|
||||
|
||||
@@ -28,7 +28,9 @@ interface BehaviourContextWithFSM<T : State> : BehaviourContext, StatesMachine<T
|
||||
handlers: List<BehaviourWithFSMStateHandlerHolder<*, T>>
|
||||
): T? {
|
||||
return handlers.firstOrNull { it.checkHandleable(state) } ?.run {
|
||||
handleState(contextUpdatesFlow, state)
|
||||
doInSubContext(updatesUpstreamFlow = contextUpdatesFlow) {
|
||||
handleState(state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,20 +34,11 @@ class BehaviourWithFSMStateHandlerHolder<I : O, O : State>(
|
||||
|
||||
/**
|
||||
* Handling of state :)
|
||||
*
|
||||
* @param contextUpdatesFlow This [Flow] will be used as source of updates. By contract, this [Flow] must be common
|
||||
* for all [State]s of incoming [state] [State.context] and for the whole chain inside of [BehaviourContextWithFSM]
|
||||
*/
|
||||
suspend fun BehaviourContextWithFSM<in O>.handleState(
|
||||
contextUpdatesFlow: Flow<Update>,
|
||||
state: O
|
||||
): O? {
|
||||
val subscope = scope.LinkedSupervisorScope()
|
||||
return with(copy(scope = subscope, upstreamUpdatesFlow = contextUpdatesFlow)) {
|
||||
with(delegateTo) {
|
||||
handleState(state as I)
|
||||
}
|
||||
}
|
||||
): O? = with(delegateTo) {
|
||||
handleState(state as I)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -96,6 +96,8 @@ val telegramInlineModeGifPermittedMimeTypes by lazy {
|
||||
)
|
||||
}
|
||||
|
||||
const val tgWebAppStartParamField = "tgWebAppStartParam"
|
||||
|
||||
const val chatIdField = "chat_id"
|
||||
const val senderChatIdField = "sender_chat_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
|
||||
*/
|
||||
inline fun inlineKeyboard(
|
||||
crossinline block: InlineKeyboardBuilder.() -> Unit
|
||||
block: InlineKeyboardBuilder.() -> Unit
|
||||
) = InlineKeyboardBuilder().apply(block).build()
|
||||
|
||||
/**
|
||||
@@ -52,7 +52,7 @@ inline fun inlineKeyboard(
|
||||
* @see urlButton
|
||||
*/
|
||||
inline fun InlineKeyboardBuilder.row(
|
||||
crossinline block: InlineKeyboardRowBuilder.() -> Unit
|
||||
block: InlineKeyboardRowBuilder.() -> Unit
|
||||
) = add(InlineKeyboardRowBuilder().apply(block).row)
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,7 +44,7 @@ inline fun replyKeyboard(
|
||||
oneTimeKeyboard: Boolean? = null,
|
||||
inputFieldPlaceholder: String? = null,
|
||||
selective: Boolean? = null,
|
||||
crossinline block: ReplyKeyboardBuilder.() -> Unit
|
||||
block: ReplyKeyboardBuilder.() -> Unit
|
||||
) = ReplyKeyboardBuilder().apply(block).build(resizeKeyboard, oneTimeKeyboard, inputFieldPlaceholder, selective)
|
||||
|
||||
/**
|
||||
@@ -56,7 +56,7 @@ inline fun replyKeyboard(
|
||||
* @see requestPollButton
|
||||
*/
|
||||
inline fun ReplyKeyboardBuilder.row(
|
||||
crossinline block: ReplyKeyboardRowBuilder.() -> Unit
|
||||
block: ReplyKeyboardRowBuilder.() -> Unit
|
||||
) = add(ReplyKeyboardRowBuilder().apply(block).row)
|
||||
|
||||
/**
|
||||
@@ -110,3 +110,14 @@ inline fun ReplyKeyboardRowBuilder.webAppButton(
|
||||
text: String,
|
||||
webApp: WebAppInfo
|
||||
) = 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))
|
||||
|
||||
@@ -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,33 @@
|
||||
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 sendDataOrWorkWithQueryId(
|
||||
onSendData: () -> String?,
|
||||
onAnswerWebAppQuery: (WebAppQueryId) -> Unit
|
||||
) {
|
||||
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)
|
||||
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user