diff --git a/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SetMessageReactions.kt b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SetMessageReactions.kt new file mode 100644 index 0000000000..c94fdeff1f --- /dev/null +++ b/tgbotapi.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SetMessageReactions.kt @@ -0,0 +1,55 @@ +package dev.inmo.tgbotapi.extensions.api.send + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.send.SendAction +import dev.inmo.tgbotapi.requests.send.SetMessageReactions +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.MessageId +import dev.inmo.tgbotapi.types.MessageThreadId +import dev.inmo.tgbotapi.types.actions.* +import dev.inmo.tgbotapi.types.chat.Chat +import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.reactions.Reaction +import dev.inmo.tgbotapi.types.threadId + +suspend fun TelegramBot.setMessageReactions( + chatId: ChatIdentifier, + messageId: MessageId, + reactions: List, + big: Boolean = false +) = execute( + SetMessageReactions(chatId, messageId, reactions, big) +) + +suspend fun TelegramBot.setMessageReaction( + chatId: ChatIdentifier, + messageId: MessageId, + reaction: Reaction?, + big: Boolean = false +) = setMessageReactions(chatId, messageId, listOfNotNull(reaction), big) + +suspend fun TelegramBot.setMessageReactions( + chat: Chat, + messageId: MessageId, + reactions: List, + big: Boolean = false +) = setMessageReactions(chat.id, messageId, reactions, big) + +suspend fun TelegramBot.setMessageReaction( + chat: Chat, + messageId: MessageId, + reaction: Reaction?, + big: Boolean = false +) = setMessageReaction(chat.id, messageId, reaction, big) + +suspend fun TelegramBot.setMessageReactions( + message: Message, + reactions: List, + big: Boolean = false +) = setMessageReactions(message.chat, message.messageId, reactions, big) + +suspend fun TelegramBot.setMessageReaction( + message: Message, + reaction: Reaction?, + big: Boolean = false +) = setMessageReaction(message.chat, message.messageId, reaction, big) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SetMessageReactions.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SetMessageReactions.kt new file mode 100644 index 0000000000..2603a6be56 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/SetMessageReactions.kt @@ -0,0 +1,31 @@ +package dev.inmo.tgbotapi.requests.send + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.reactions.Reaction +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.builtins.serializer + +@Serializable +data class SetMessageReactions( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(messageIdField) + val messageId: MessageId, + @SerialName(reactionField) + val reactions: List, + @SerialName(isBigField) + val big: Boolean = false +) : SimpleRequest, ChatRequest { + override fun method(): String = "setMessageReaction" + + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() +} \ No newline at end of file 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 43f7e212b6..02cdbf293c 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 @@ -463,6 +463,8 @@ const val userChatIdField = "user_chat_id" const val userField = "user" const val dateField = "date" const val reactionsField = "reactions" +const val reactionField = "reaction" +const val isBigField = "is_big" const val oldReactionField = "old_reaction" const val newReactionField = "new_reaction" const val chatField = "chat"