tgbotapi/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendPoll.kt

47 lines
2.1 KiB
Kotlin
Raw Normal View History

2019-04-16 08:16:13 +00:00
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.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
2019-05-12 11:15:31 +00:00
import kotlinx.serialization.*
2019-04-16 08:16:13 +00:00
2019-04-16 11:40:41 +00:00
@Serializable
2019-04-16 08:16:13 +00:00
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<Message>,
ReplyingMarkupSendMessageRequest<Message> {
2019-04-16 08:16:13 +00:00
init {
2019-04-16 11:22:18 +00:00
if (question.length !in pollQuestionTextLength) {
throw IllegalArgumentException("The length of questions for polls must be in $pollQuestionTextLength range, but was ${question.length}")
2019-04-16 08:16:13 +00:00
}
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"
2019-12-02 08:35:37 +00:00
override val resultDeserializer: DeserializationStrategy<Message>
get() = TelegramBotAPIMessageDeserializationStrategy
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
2019-04-16 08:16:13 +00:00
}