1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00

add support of setMessageReactions

This commit is contained in:
InsanusMokrassar 2023-12-31 16:27:35 +06:00
parent 63975cc88e
commit 3026c8708d
3 changed files with 88 additions and 0 deletions

View File

@ -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<Reaction>,
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<Reaction>,
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<Reaction>,
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)

View File

@ -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<Reaction>,
@SerialName(isBigField)
val big: Boolean = false
) : SimpleRequest<Boolean>, ChatRequest {
override fun method(): String = "setMessageReaction"
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = Boolean.serializer()
}

View File

@ -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"