diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/answers/AnswerWebAppQuery.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/answers/AnswerWebAppQuery.kt new file mode 100644 index 0000000000..edd92b0089 --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/answers/AnswerWebAppQuery.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.extensions.api.answers + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.answers.AnswerWebAppQuery +import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult +import dev.inmo.tgbotapi.types.WebAppQueryId + +suspend fun TelegramBot.answerWebAppQuery( + webAppQueryId: WebAppQueryId, + result: InlineQueryResult +) = execute(AnswerWebAppQuery(webAppQueryId, result)) + +suspend fun TelegramBot.answer( + webAppQueryId: WebAppQueryId, + result: InlineQueryResult +) = execute(AnswerWebAppQuery(webAppQueryId, result)) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerWebAppQuery.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerWebAppQuery.kt new file mode 100644 index 0000000000..ceacda665f --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerWebAppQuery.kt @@ -0,0 +1,21 @@ +package dev.inmo.tgbotapi.requests.answers + +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult +import dev.inmo.tgbotapi.types.webapps.query.SentWebAppMessage +import kotlinx.serialization.* + +@Serializable +data class AnswerWebAppQuery( + @SerialName(webAppQueryIdField) + val webAppQueryId: WebAppQueryId, + @SerialName(resultField) + val result: InlineQueryResult +) : SimpleRequest { + override fun method(): String = "answerWebAppQuery" + override val resultDeserializer: DeserializationStrategy + get() = SentWebAppMessage.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index f81d042e8b..316a14588c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -27,6 +27,7 @@ typealias FoursquareType = String typealias GooglePlaceId = String typealias GooglePlaceType = String typealias MembersLimit = Int +typealias WebAppQueryId = String typealias Seconds = Int typealias MilliSeconds = Long @@ -133,6 +134,7 @@ const val inlineMessageIdField = "inline_message_id" const val callbackDataField = "callback_data" const val callbackGameField = "callback_game" const val callbackQueryIdField = "callback_query_id" +const val webAppQueryIdField = "web_app_query_id" const val inlineQueryIdField = "inline_query_id" const val inlineKeyboardField = "inline_keyboard" const val showAlertField = "show_alert" @@ -324,6 +326,7 @@ const val pricesField = "prices" const val payloadField = "payload" const val vcardField = "vcard" const val resultsField = "results" +const val resultField = "result" const val certificateField = "certificate" const val questionField = "question" const val optionsField = "options" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/webapps/query/SentWebAppMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/webapps/query/SentWebAppMessage.kt new file mode 100644 index 0000000000..800041c005 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/webapps/query/SentWebAppMessage.kt @@ -0,0 +1,9 @@ +package dev.inmo.tgbotapi.types.webapps.query + +import dev.inmo.tgbotapi.types.InlineMessageIdentifier +import kotlinx.serialization.Serializable + +@Serializable +data class SentWebAppMessage( + val inlineMessageId: InlineMessageIdentifier? = null +)