mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-09-20 17:46:08 +00:00
51 lines
2.4 KiB
Kotlin
51 lines
2.4 KiB
Kotlin
package com.github.insanusmokrassar.TelegramBotAPI.requests.send
|
|
|
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.ReplyingMarkupSendMessageRequest
|
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.SendMessageRequest
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.PollContent
|
|
import kotlinx.serialization.*
|
|
|
|
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>>
|
|
= TelegramBotAPIMessageDeserializationStrategyClass()
|
|
|
|
@Serializable
|
|
data class SendPoll(
|
|
@SerialName(chatIdField)
|
|
override val chatId: ChatIdentifier,
|
|
@SerialName(questionField)
|
|
val question: String,
|
|
@SerialName(optionsField)
|
|
val options: List<String>,
|
|
@SerialName(disableNotificationField)
|
|
override val disableNotification: Boolean = false,
|
|
@SerialName(replyToMessageIdField)
|
|
override val replyToMessageId: MessageIdentifier? = null,
|
|
@SerialName(replyMarkupField)
|
|
override val replyMarkup: KeyboardMarkup? = null
|
|
) : SendMessageRequest<ContentMessage<PollContent>>,
|
|
ReplyingMarkupSendMessageRequest<ContentMessage<PollContent>> {
|
|
|
|
init {
|
|
if (question.length !in pollQuestionTextLength) {
|
|
throw IllegalArgumentException("The length of questions for polls must be in $pollQuestionTextLength range, but was ${question.length}")
|
|
}
|
|
options.forEach {
|
|
if (it.length !in pollOptionTextLength) {
|
|
throw IllegalArgumentException("The length of question option text for polls must be in $pollOptionTextLength range, but was ${it.length}")
|
|
}
|
|
}
|
|
if (options.size !in pollOptionsLimit) {
|
|
throw IllegalArgumentException("The amount of question options for polls must be in $pollOptionsLimit range, but was ${options.size}")
|
|
}
|
|
}
|
|
|
|
override fun method(): String = "sendPoll"
|
|
override val resultDeserializer: DeserializationStrategy<ContentMessage<PollContent>>
|
|
get() = commonResultDeserializer
|
|
override val requestSerializer: SerializationStrategy<*>
|
|
get() = serializer()
|
|
} |