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

Merge pull request #33 from InsanusMokrassar/0.13.0

0.13.0
This commit is contained in:
InsanusMokrassar 2019-04-16 21:27:58 -05:00 committed by GitHub
commit 95ae25a3fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 368 additions and 84 deletions

View File

@ -1,5 +1,24 @@
# TelegramBotAPI changelog
## 0.13.0 Telegram Polls
* 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`
* Request `SendPoll` added and `PollContent#createResend` now use it
* `ByInlineMessageId` is deprecated (use `InlineMessageAction` instead)
* `ByMessageId` is deprecated (use `MessageAction` instead)
* Most part of requests which are working with identifiers of messages now implement `MessageAction` directly or
by their parents
* `StopPoll` implemented
* All current `Chat` abstractions are deprecated and rewritten as typealiases. Use `Chat` abstractions from
`com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts` package
* Common Groups now may have pinned message
* `is_member` field added into `RestrictedChatMember`
* **BREAK CHANGES** Now `ForwardedMessages` can be `AnonymousForwardedMessage` and `PublicForwardedMessage`. Old
implementations now extend `PublicForwardedMessage`
## 0.12.0 Webhooks
* Added `DataRequest` interface which replace `Data` interface

View File

@ -10,9 +10,7 @@ solves or unuseful moments are describing by official [Telegram Bot API](https:/
## Compatibility
This version compatible with [July 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api#july-26-2018). That means that
most part of API has been implemented (according to last [August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api#august-27-2018))
except the Passport API which will be included as soon as possible. All included and supported API
This version compatible with [14th of April 2019 update of TelegramBotAPI](https://core.telegram.org/bots/api#april-14-2019). There is one exception of implemented functionality. It is Telegram Passport API, which was presented in [August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api#august-27-2018) update. It will be implemented as soon as possible. All included and supported API
can be found on [wiki](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Included-API).
## How to implement library?

View File

@ -1,4 +1,4 @@
project.version = "0.12.7"
project.version = "0.13.0"
project.group = "com.github.insanusmokrassar"
buildscript {

View File

@ -1,7 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineMessageIdentifier
interface ByInlineMessageId {
val inlineMessageId: InlineMessageIdentifier
}
@Deprecated(
"Deprecated for the reason of creating of more obvious type interface",
ReplaceWith("InlineMessageAction", "com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction")
)
typealias ByInlineMessageId = InlineMessageAction

View File

@ -1,7 +1,8 @@
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
@Deprecated(
"Deprecated for the reason of creating of more obvious type interface",
ReplaceWith("MessageAction", "com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction")
interface ByMessageId : ChatRequest {
val messageId: MessageIdentifier
}
)
typealias ByMessageId = MessageAction

View File

@ -0,0 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineMessageIdentifier
interface InlineMessageAction {
val inlineMessageId: InlineMessageIdentifier
}

View File

@ -0,0 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
interface MessageAction: ChatRequest {
val messageId: MessageIdentifier
}

View File

@ -1,5 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.*
@ -8,10 +9,10 @@ import kotlinx.serialization.internal.BooleanSerializer
@Serializable
data class DeleteMessage(
@SerialName(chatIdField)
val chatId: ChatIdentifier,
override val chatId: ChatIdentifier,
@SerialName(messageIdField)
val messageId: MessageIdentifier
) : SimpleRequest<Boolean> {
override val messageId: MessageIdentifier
) : SimpleRequest<Boolean>, MessageAction {
override fun method(): String = "deleteMessage"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer

View File

@ -1,5 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
@ -12,10 +13,14 @@ data class ForwardMessage(
@SerialName(chatIdField)
val toChatId: ChatIdentifier,
@SerialName(messageIdField)
val messageId: MessageIdentifier,
override val messageId: MessageIdentifier,
@SerialName(disableNotificationField)
val disableNotification: Boolean = false
): SimpleRequest<RawMessage> {
): SimpleRequest<RawMessage>, MessageAction {
@Transient
override val chatId: ChatIdentifier
get() = fromChatId
override fun method(): String = "forwardMessage"
override fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()

View File

@ -0,0 +1,22 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ReplyMarkup
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll
import kotlinx.serialization.*
@Serializable
data class StopPoll(
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(messageIdField)
override val messageId: MessageIdentifier,
@SerialName(replyMarkupField)
override val replyMarkup: InlineKeyboardMarkup?
) : MessageAction, SimpleRequest<Poll>, ReplyMarkup {
override fun method(): String = "stopPoll"
override fun resultSerializer(): KSerializer<Poll> = Poll.serializer()
}

View File

@ -1,7 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.modify
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.DisableNotification
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.*
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.*
@ -12,10 +11,10 @@ data class PinChatMessage (
@SerialName(chatIdField)
override val chatId: ChatIdentifier,
@SerialName(messageIdField)
val messageId: MessageIdentifier,
override val messageId: MessageIdentifier,
@SerialName(disableNotificationField)
override val disableNotification: Boolean = false
): ChatRequest, SimpleRequest<Boolean>, DisableNotification {
): ChatRequest, SimpleRequest<Boolean>, MessageAction, DisableNotification {
override fun method(): String = "pinChatMessage"
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
}

View File

@ -1,11 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
interface EditChatMessage : SimpleRequest<RawMessage> {
val chatId: ChatIdentifier
val messageId: MessageIdentifier
}
interface EditChatMessage : SimpleRequest<RawMessage>, MessageAction

View File

@ -1,6 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.games
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ByMessageId
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.SerialName
@ -14,4 +14,4 @@ data class GetGameHighScoresByChat (
override val chatId: ChatId,
@SerialName(messageIdField)
override val messageId: MessageIdentifier
) : GetGameHighScores, ByMessageId
) : GetGameHighScores, MessageAction

View File

@ -1,6 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.games
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ByInlineMessageId
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.SerialName
@ -12,4 +12,4 @@ data class GetGameHighScoresByInlineMessageId (
override val userId: UserId,
@SerialName(inlineMessageIdField)
override val inlineMessageId: InlineMessageIdentifier
) : GetGameHighScores, ByInlineMessageId
) : GetGameHighScores, InlineMessageAction

View File

@ -1,6 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.games
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ByMessageId
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.SerialName
@ -20,4 +20,4 @@ data class SetGameScoreByChatId (
override val force: Boolean = false,
@SerialName(disableEditMessageField)
override val disableEditMessage: Boolean = false
) : SetGameScore, ByMessageId
) : SetGameScore, MessageAction

View File

@ -1,6 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.requests.games
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ByInlineMessageId
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.SerialName
@ -18,4 +18,4 @@ data class SetGameScoreByInlineMessageId (
override val force: Boolean = false,
@SerialName(disableEditMessageField)
override val disableEditMessage: Boolean = false
) : SetGameScore, ByInlineMessageId
) : SetGameScore, InlineMessageAction

View File

@ -0,0 +1,45 @@
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
import kotlinx.serialization.Serializable
@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<RawMessage>,
ReplyingMarkupSendMessageRequest<RawMessage> {
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 fun resultSerializer(): KSerializer<RawMessage> = RawMessage.serializer()
}

View File

@ -26,6 +26,8 @@ data class RawChatMember(
private val canPinMessages: Boolean = false,
@SerialName(canPromoteMembersField)
private val canPromoteMembers: Boolean = false,
@SerialName(isMemberField)
private val isMember: Boolean = false,
@SerialName(canSendMessagesField)
private val canSendMessages: Boolean = false,
@SerialName(canSendMediaMessagesField)
@ -55,6 +57,7 @@ data class RawChatMember(
"restricted" -> RestrictedChatMember(
user,
until_date,
isMember,
canSendMessages,
canSendMediaMessages,
canSendOtherMessages,

View File

@ -6,6 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.User
data class RestrictedChatMember(
override val user: User,
override val untilDate: TelegramDate?,
val isMember: Boolean,
val canSendMessages: Boolean,
val canSendMediaMessages: Boolean,
val canSendOtherMessages: Boolean,

View File

@ -6,6 +6,7 @@ typealias InlineQueryIdentifier = String
typealias UpdateIdentifier = Long
typealias MediaGroupIdentifier = String
typealias ForwardSignature = String
typealias ForwardSenderName = String
typealias AuthorSignature = ForwardSignature
typealias CallbackQueryIdentifier = String
typealias PaymentQueryIdentifier = String
@ -15,6 +16,7 @@ typealias InvoicePayload = String
typealias ShippingOptionIdentifier = String
typealias StartParameter = String
typealias InlineMessageIdentifier = String
typealias PollIdentifier = String
val callbackQueryAnswerLength = 0 until 200
val captionLength = 0 until 1024
@ -29,6 +31,10 @@ val invoiceTitleLimit = 1 until 32
val invoiceDescriptionLimit = 1 until 256
val invoicePayloadBytesLimit = 1 until 128
val pollOptionTextLength = 1 .. 100
val pollQuestionTextLength = 1 until 256
val pollOptionsLimit = 2 .. 10
val livePeriodLimit = 60 .. 86400
val inlineQueryAnswerResultsLimit = 0 .. 50
@ -75,6 +81,8 @@ const val hasCustomCertificateField = "has_custom_certificate"
const val pendingUpdateCountField = "pending_update_count"
const val lastErrorDateField = "last_error_date"
const val lastErrorMessageField = "last_error_message"
const val votesCountField = "voter_count"
const val isClosedField = "is_closed"
const val photoUrlField = "photo_url"
@ -124,6 +132,7 @@ const val inputMessageContentField = "input_message_content"
const val hideUrlField = "hide_url"
const val isMemberField = "is_member"
const val canSendMessagesField = "can_send_messages"
const val canSendMediaMessagesField = "can_send_media_messages"
const val canSendOtherMessagesField = "can_send_other_messages"
@ -180,6 +189,8 @@ const val payloadField = "payload"
const val vcardField = "vcard"
const val resultsField = "results"
const val certificateField = "certificate"
const val questionField = "question"
const val optionsField = "options"
const val pointField = "point"
const val xShiftField = "x_shift"

View File

@ -4,7 +4,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
import kotlinx.serialization.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class InputMediaAnimation(

View File

@ -4,7 +4,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
import com.github.insanusmokrassar.TelegramBotAPI.types.mediaField
import kotlinx.serialization.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class InputMediaDocument(

View File

@ -1,14 +1,16 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
data class ChannelChat(
override val id: ChatId,
override val title: String? = null,
val username: Username? = null,
val description: String? = null,
override val username: Username? = null,
override val description: String? = null,
override val inviteLink: String? = null,
override val chatPhoto: ChatPhoto? = null,
val pinnedMessage: RawMessage?
) : PublicChat
override val pinnedMessage: RawMessage?
) : PublicChat, UsernameChat, DescriptionChat

View File

@ -1,9 +1,9 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
interface Chat {
val id: ChatId
val chatPhoto: ChatPhoto?
}
@Deprecated(
"Replaced into another package",
ReplaceWith("Chat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat")
)
typealias Chat = Chat

View File

@ -1,15 +1,9 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
interface GroupChat : PublicChat {
val allMembersAreAdmins: Boolean
}
data class GroupChatImpl(
override val id: ChatId,
override val title: String? = null,
override val allMembersAreAdmins: Boolean,
override val inviteLink: String? = null,
override val chatPhoto: ChatPhoto? = null) : GroupChat
@Deprecated(
"Replaced into another package",
ReplaceWith("GroupChat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat")
)
typealias GroupChat = GroupChat

View File

@ -0,0 +1,15 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
data class GroupChatImpl(
override val id: ChatId,
override val title: String? = null,
override val allMembersAreAdmins: Boolean,
override val inviteLink: String? = null,
override val chatPhoto: ChatPhoto? = null,
override val pinnedMessage: RawMessage? = null
) : GroupChat

View File

@ -1,11 +1,13 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UsernameChat
data class PrivateChat(
override val id: ChatId,
val username: Username? = null,
override val username: Username? = null,
val firstName: String? = null,
val lastName: String? = null,
override val chatPhoto: ChatPhoto? = null
) : Chat
) : Chat, UsernameChat

View File

@ -1,6 +1,9 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
interface PublicChat : Chat {
val title: String?
val inviteLink: String?
}
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
@Deprecated(
"Replaced into another package",
ReplaceWith("PublicChat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat")
)
typealias PublicChat = PublicChat

View File

@ -1,6 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

View File

@ -1,17 +1,19 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
data class SupergroupChat(
override val id: ChatId,
override val title: String? = null,
val username: Username? = null,
val description: String? = null,
override val username: Username? = null,
override val description: String? = null,
override val allMembersAreAdmins: Boolean,
override val inviteLink: String? = null,
override val chatPhoto: ChatPhoto? = null,
val pinnedMessage: RawMessage? = null,
override val pinnedMessage: RawMessage? = null,
val stickerSetName: String? = null,
val canSetStickerSet: Boolean
) : GroupChat
) : GroupChat, UsernameChat, DescriptionChat

View File

@ -0,0 +1,9 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto
interface Chat {
val id: ChatId
val chatPhoto: ChatPhoto?
}

View File

@ -0,0 +1,5 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
interface DescriptionChat : PublicChat {
val description: String?
}

View File

@ -0,0 +1,5 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
interface GroupChat : PublicChat {
val allMembersAreAdmins: Boolean
}

View File

@ -0,0 +1,9 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
interface PublicChat : Chat {
val title: String?
val inviteLink: String?
val pinnedMessage: RawMessage?
}

View File

@ -0,0 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.Username
interface UsernameChat : Chat {
val username: Username?
}

View File

@ -2,7 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.MediaGroupIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.MediaGroupMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent

View File

@ -2,7 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.AuthorSignature
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.CommonMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent

View File

@ -1,7 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaGroupContent
import org.joda.time.DateTime

View File

@ -2,7 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.User
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo

View File

@ -1,11 +1,19 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
sealed class ForwardedMessage {
abstract val messageId: MessageIdentifier
abstract val dateOfOriginal: TelegramDate
}
data class AnonymousForwardedMessage(
override val dateOfOriginal: TelegramDate,
val senderName: String
) : ForwardedMessage()
sealed class PublicForwardedMessage : ForwardedMessage() {
abstract val messageId: MessageIdentifier
abstract val from: User?
}
@ -13,7 +21,7 @@ data class CommonForwardedMessage(
override val messageId: MessageIdentifier,
override val dateOfOriginal: TelegramDate,
override val from: User
) : ForwardedMessage()
) : PublicForwardedMessage()
data class ForwardedFromChannelMessage(
override val messageId: MessageIdentifier,
@ -21,4 +29,4 @@ data class ForwardedFromChannelMessage(
override val from: User?,
val channelChat: Chat,
val signature: String? = null
) : ForwardedMessage()
) : PublicForwardedMessage()

View File

@ -1,7 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.GroupChat
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.GroupEvent
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage
import org.joda.time.DateTime

View File

@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntities
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntitiesSerializer
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
import com.github.insanusmokrassar.TelegramBotAPI.types.files.*
import com.github.insanusmokrassar.TelegramBotAPI.types.games.Game
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.*
@ -17,6 +18,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.Success
import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.abstracts.PaymentInfo
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.Invoice
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.SuccessfulPayment
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll
import kotlinx.serialization.*
import kotlin.reflect.KClass
@ -35,6 +37,7 @@ data class RawMessage(
private val forward_from_chat: RawChat? = null,
private val forward_from_message_id: MessageIdentifier? = null,
private val forward_signature: ForwardSignature? = null,
private val forward_sender_name: ForwardSenderName? = null,
private val forward_date: TelegramDate? = null,
private val reply_to_message: RawMessage? = null,
private val edit_date: TelegramDate? = null,
@ -59,6 +62,7 @@ data class RawMessage(
private val contact: Contact? = null,
private val location: Location? = null,
private val venue: Venue? = null,
private val poll: Poll? = null,
private val new_chat_members: List<User>? = null,
private val left_chat_member: User? = null,
private val new_chat_title: String? = null,
@ -122,14 +126,16 @@ data class RawMessage(
contact != null -> ContactContent(contact)
location != null -> LocationContent(location)
venue != null -> VenueContent(venue)
poll != null -> PollContent(poll)
else -> null
}
}
@Transient
private val forwarded: ForwardedMessage? by lazy {
forward_date ?: return@lazy null // According to the documentation, now any forwarded message contains this field
forward_from_message_id ?.let {
forward_date ?: throw IllegalStateException("For forwarded messages date of original message declared as set up required")
forward_from ?: throw IllegalStateException("For common forwarded messages author of original message declared as set up required")
forward_from_chat ?.let {
ForwardedFromChannelMessage(
forward_from_message_id,
@ -142,7 +148,11 @@ data class RawMessage(
forward_from_message_id,
forward_date,
forward_from
?: throw IllegalStateException("For common forwarded messages author of original message declared as set up required")
)
} ?: forward_sender_name ?.let {
AnonymousForwardedMessage(
forward_date,
forward_sender_name
)
}
}

View File

@ -1,7 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import org.joda.time.DateTime
interface Message {

View File

@ -0,0 +1,28 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.message.content
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendPoll
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll
data class PollContent(
val poll: Poll
) : MessageContent {
override fun createResend(
chatId: ChatIdentifier,
disableNotification: Boolean,
replyToMessageId: MessageIdentifier?,
replyMarkup: KeyboardMarkup?
): Request<RawMessage> = SendPoll(
chatId,
poll.question,
poll.options.map { it.text },
disableNotification,
replyToMessageId,
replyMarkup
)
}

View File

@ -0,0 +1,17 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.polls
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class Poll(
@SerialName(idField)
val id: PollIdentifier,
@SerialName(questionField)
val question: String,
@SerialName(optionsField)
val options: List<PollOption>,
@SerialName(isClosedField)
val closed: Boolean = false
)

View File

@ -0,0 +1,37 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.polls
import com.github.insanusmokrassar.TelegramBotAPI.types.textField
import com.github.insanusmokrassar.TelegramBotAPI.types.votesCountField
import kotlinx.serialization.*
import kotlinx.serialization.internal.StringDescriptor
@Serializable(PollOptionSerializer::class)
sealed class PollOption {
abstract val text: String
abstract val votes: Int
}
@Serializable
data class AnonymousPollOption (
@SerialName(textField)
override val text: String,
@SerialName(votesCountField)
override val votes: Int
) : PollOption()
object PollOptionSerializer : KSerializer<PollOption> {
override val descriptor: SerialDescriptor = StringDescriptor.withName(PollOption::class.simpleName ?: "PollOption")
override fun deserialize(decoder: Decoder): PollOption = AnonymousPollOption.serializer().deserialize(
decoder
)
override fun serialize(encoder: Encoder, obj: PollOption) {
when (obj) {
is AnonymousPollOption -> AnonymousPollOption.serializer().serialize(
encoder,
obj
)
}
}
}

View File

@ -0,0 +1,10 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.update
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
data class PollUpdate(
override val updateId: UpdateIdentifier,
override val data: Poll
) : Update

View File

@ -7,6 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.PreCheckoutQuery
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.ShippingQuery
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
import com.github.insanusmokrassar.TelegramBotAPI.types.updateIdField
import kotlinx.serialization.*
@ -25,7 +26,8 @@ data class RawUpdate constructor(
private val chosen_inline_result: RawChosenInlineResult? = null,
private val callback_query: RawCallbackQuery? = null,
private val shipping_query: ShippingQuery? = null,
private val pre_checkout_query: PreCheckoutQuery? = null
private val pre_checkout_query: PreCheckoutQuery? = null,
private val poll: Poll? = null
) {
@Transient
val asUpdate: Update by lazy {
@ -40,6 +42,7 @@ data class RawUpdate constructor(
callback_query != null -> CallbackQueryUpdate(updateId, callback_query.asCallbackQuery)
shipping_query != null -> ShippingQueryUpdate(updateId, shipping_query)
pre_checkout_query != null -> PreCheckoutQueryUpdate(updateId, pre_checkout_query)
poll != null -> PollUpdate(updateId, poll)
else -> throw IllegalArgumentException("Unsupported type of update")
}
}

View File

@ -1,7 +1,7 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils
import com.github.insanusmokrassar.TelegramBotAPI.types.MediaGroupIdentifier
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
import com.github.insanusmokrassar.TelegramBotAPI.types.message.ForwardedMessage
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.BaseMessageUpdate