mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-25 18:17:13 +00:00
add SendPoll
This commit is contained in:
parent
e2267c1cb4
commit
d7bbb6dd85
@ -5,7 +5,8 @@
|
||||
* Type `PollOption` and `AnonymousPollOption` added
|
||||
* Type `Poll` added
|
||||
* Type `PollUpdate` added and implemented in `RawUpdate`. Now `PollUpdate` can be retrieved from `RawUpdate`
|
||||
* type `PollContent` added - now it can be a value of `ContentMessage#content`
|
||||
* Type `PollContent` added - now it can be a value of `ContentMessage#content`
|
||||
* Request `SendPoll` added and `PollContent#createResend` now use it
|
||||
|
||||
## 0.12.0 Webhooks
|
||||
|
||||
|
@ -0,0 +1,43 @@
|
||||
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.RawMessage
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.SerialName
|
||||
|
||||
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<RawMessage>,
|
||||
ReplyingMarkupSendMessageRequest<RawMessage> {
|
||||
|
||||
init {
|
||||
if (question.length !in pollQuectionTextLength) {
|
||||
throw IllegalArgumentException("The length of questions for polls must be in $pollQuectionTextLength 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 fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
|
||||
}
|
@ -32,6 +32,7 @@ val invoicePayloadBytesLimit = 1 until 128
|
||||
|
||||
val pollOptionTextLength = 1 .. 100
|
||||
val pollQuectionTextLength = 1 until 256
|
||||
val pollOptionsLimit = 2 .. 10
|
||||
|
||||
val livePeriodLimit = 60 .. 86400
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message.content
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendPoll
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
|
||||
@ -21,5 +22,12 @@ data class PollContent(
|
||||
disableNotification: Boolean,
|
||||
replyToMessageId: MessageIdentifier?,
|
||||
replyMarkup: KeyboardMarkup?
|
||||
): Request<RawMessage> = TODO()
|
||||
): Request<RawMessage> = SendPoll(
|
||||
chatId,
|
||||
poll.question,
|
||||
poll.options.map { it.text },
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
replyMarkup
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user