diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/inline/SavePreparedInlineMessage.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/inline/SavePreparedInlineMessage.kt new file mode 100644 index 0000000000..4358140cdc --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/inline/SavePreparedInlineMessage.kt @@ -0,0 +1,45 @@ +package dev.inmo.tgbotapi.extensions.api.inline + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.answers.InlineQueryAnswersResultsSerializer +import dev.inmo.tgbotapi.requests.inline.SavePreparedInlineMessage +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult +import dev.inmo.tgbotapi.types.InlineQueries.prepared.PreparedInlineMessage +import dev.inmo.tgbotapi.types.chat.User +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +public suspend fun TelegramBot.savePreparedInlineMessage( + userId: UserId, + result: InlineQueryResult, + allowSendToUsers: Boolean = false, + allowSendToBots: Boolean = false, + allowSendToGroups: Boolean = false, + allowSendToChannels: Boolean = false, +): PreparedInlineMessage = execute( + SavePreparedInlineMessage( + userId = userId, + result = result, + allowSendToUsers = allowSendToUsers, + allowSendToBots = allowSendToBots, + allowSendToGroups = allowSendToGroups, + allowSendToChannels = allowSendToChannels + ) +) + +public suspend fun TelegramBot.savePreparedInlineMessage( + user: User, + result: InlineQueryResult, + allowSendToUsers: Boolean = false, + allowSendToBots: Boolean = false, + allowSendToGroups: Boolean = false, + allowSendToChannels: Boolean = false, +): PreparedInlineMessage = savePreparedInlineMessage( + userId = user.id, + result = result, + allowSendToUsers = allowSendToUsers, + allowSendToBots = allowSendToBots, + allowSendToGroups = allowSendToGroups, + allowSendToChannels = allowSendToChannels +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/inline/SavePreparedInlineMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/inline/SavePreparedInlineMessage.kt new file mode 100644 index 0000000000..114dfe3e14 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/inline/SavePreparedInlineMessage.kt @@ -0,0 +1,35 @@ +package dev.inmo.tgbotapi.requests.inline + +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.requests.answers.InlineQueryAnswersResultsSerializer +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.InlineQueryResult +import dev.inmo.tgbotapi.types.InlineQueries.prepared.PreparedInlineMessage +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.SerializationStrategy + +@Serializable +data class SavePreparedInlineMessage( + @SerialName(idField) + val userId: UserId, + @Serializable(InlineQueryAnswersResultsSerializer::class) + @SerialName(resultField) + val result: InlineQueryResult, + @SerialName(allowUserChatsField) + val allowSendToUsers: Boolean = false, + @SerialName(allowBotChatsField) + val allowSendToBots: Boolean = false, + @SerialName(allowGroupChatsField) + val allowSendToGroups: Boolean = false, + @SerialName(allowChannelChatsField) + val allowSendToChannels: Boolean = false, +) : SimpleRequest { + override fun method(): String = "savePreparedInlineMessage" + + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + override val resultDeserializer: DeserializationStrategy + get() = PreparedInlineMessage.serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/prepared/PreparedInlineMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/prepared/PreparedInlineMessage.kt new file mode 100644 index 0000000000..6a1a9a1737 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/InlineQueries/prepared/PreparedInlineMessage.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.types.InlineQueries.prepared + +import dev.inmo.tgbotapi.types.PreparedMessageId +import dev.inmo.tgbotapi.types.TelegramDate +import dev.inmo.tgbotapi.types.expirationDateField +import dev.inmo.tgbotapi.types.idField +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class PreparedInlineMessage( + @SerialName(idField) + val id: PreparedMessageId, + @SerialName(expirationDateField) + val expirationDate: TelegramDate, +)