From 402d91f9f2e83879940e3629bb67c8aca49947ff Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 17 Apr 2022 20:30:18 +0600 Subject: [PATCH] add support of SentWebAppMessage --- .../api/answers/AnswerWebAppQuery.kt | 16 ++++++++++++++ .../requests/answers/AnswerWebAppQuery.kt | 21 +++++++++++++++++++ .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 3 +++ .../types/webapps/query/SentWebAppMessage.kt | 9 ++++++++ 4 files changed, 49 insertions(+) create mode 100644 tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/answers/AnswerWebAppQuery.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/answers/AnswerWebAppQuery.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/webapps/query/SentWebAppMessage.kt 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 9d9a3c8d66..e9a307d03c 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" @@ -317,6 +319,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 +)