mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-27 19:17:12 +00:00
commit
0d7fa8a1ec
@ -1,5 +1,14 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 0.16.0 Bot API 4.3
|
||||
|
||||
* `LoginURL` and `LoginURLInlineKeyboardButton` has been added
|
||||
* `replyMarkup` field was added to the `CommonMessage` objects via `AbleToBeMarkedUp` interface
|
||||
* `SwitchInlineQueryCurrentChatInlineKeyboardButton#switchInlineQueryCurrentChat` field fixed
|
||||
* `InlineKeyboardButton` now is sealed class and all its possible realisations are inside of its class file
|
||||
* `String#asUsername` method renamed to `String#toUsername`
|
||||
* Several `toChatId` extensions added
|
||||
|
||||
## 0.15.0
|
||||
|
||||
* Old `UpdatesPoller` removed (was deprecated)
|
||||
|
@ -1,4 +1,4 @@
|
||||
project.version = "0.15.0"
|
||||
project.version = "0.16.0"
|
||||
project.group = "com.github.insanusmokrassar"
|
||||
|
||||
buildscript {
|
||||
|
@ -20,6 +20,8 @@ val ChatId.link: String
|
||||
typealias UserId = ChatId
|
||||
|
||||
fun Identifier.toChatId(): ChatId = ChatId(this)
|
||||
fun Int.toChatId(): ChatId = toLong().toChatId()
|
||||
fun Byte.toChatId(): ChatId = toLong().toChatId()
|
||||
|
||||
@Serializable(ChatIdentifierSerializer::class)
|
||||
data class Username(
|
||||
@ -32,7 +34,7 @@ data class Username(
|
||||
}
|
||||
}
|
||||
|
||||
fun String.asUsername(): Username = Username(this)
|
||||
fun String.toUsername(): Username = Username(this)
|
||||
|
||||
@Serializer(ChatIdentifier::class)
|
||||
internal class ChatIdentifierSerializer: KSerializer<ChatIdentifier> {
|
||||
|
@ -84,6 +84,14 @@ const val lastErrorDateField = "last_error_date"
|
||||
const val lastErrorMessageField = "last_error_message"
|
||||
const val votesCountField = "voter_count"
|
||||
const val isClosedField = "is_closed"
|
||||
const val loginUrlField = "login_url"
|
||||
const val forwardTextField = "forward_text"
|
||||
const val botUsernameField = "bot_username"
|
||||
const val switchInlineQueryCurrentChatField = "switch_inline_query_current_chat"
|
||||
const val switchInlineQueryField = "switch_inline_query"
|
||||
|
||||
|
||||
const val requestWriteAccessField = "request_write_access"
|
||||
|
||||
|
||||
const val photoUrlField = "photo_url"
|
||||
@ -192,6 +200,7 @@ const val resultsField = "results"
|
||||
const val certificateField = "certificate"
|
||||
const val questionField = "question"
|
||||
const val optionsField = "options"
|
||||
const val payField = "pay"
|
||||
|
||||
const val pointField = "point"
|
||||
const val xShiftField = "x_shift"
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class LoginURL(
|
||||
@SerialName(urlField)
|
||||
val url: String,
|
||||
@SerialName(forwardTextField)
|
||||
val forwardText: String? = null,
|
||||
@SerialName(botUsernameField)
|
||||
val botUsername: String? = null,
|
||||
@SerialName(requestWriteAccessField)
|
||||
val requestWriteAccess: Boolean? = null
|
||||
)
|
@ -1,14 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.callbackDataField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.textField
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class CallbackDataInlineKeyboardButton(
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(callbackDataField)
|
||||
val callbackData: String
|
||||
) : InlineKeyboardButton
|
@ -1,10 +1,53 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable(InlineKeyboardButtonSerializer::class)
|
||||
interface InlineKeyboardButton {
|
||||
val text: String
|
||||
sealed class InlineKeyboardButton {
|
||||
abstract val text: String
|
||||
}
|
||||
|
||||
object InlineKeyboardButtonSerializer : KSerializer<InlineKeyboardButton> by ContextSerializer(InlineKeyboardButton::class)
|
||||
//TODO:: add check that this button first in a row (it MUST be first in a row)
|
||||
@Serializable
|
||||
data class PayInlineKeyboardButton(
|
||||
override val text: String,
|
||||
@SerialName(payField)
|
||||
val pay: Boolean
|
||||
) : InlineKeyboardButton()
|
||||
|
||||
@Serializable
|
||||
data class CallbackDataInlineKeyboardButton(
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
@SerialName(callbackDataField)
|
||||
val callbackData: String
|
||||
) : InlineKeyboardButton()
|
||||
|
||||
@Serializable
|
||||
data class LoginURLInlineKeyboardButton(
|
||||
override val text: String,
|
||||
@SerialName(loginUrlField)
|
||||
val loginUrl: LoginURL
|
||||
) : InlineKeyboardButton()
|
||||
|
||||
@Serializable
|
||||
data class SwitchInlineQueryCurrentChatInlineKeyboardButton(
|
||||
override val text: String,
|
||||
@SerialName(switchInlineQueryCurrentChatField)
|
||||
val switchInlineQueryCurrentChat: String
|
||||
) : InlineKeyboardButton()
|
||||
|
||||
@Serializable
|
||||
data class SwitchInlineQueryInlineKeyboardButton(
|
||||
override val text: String,
|
||||
@SerialName(switchInlineQueryField)
|
||||
val switchInlineQuery: String
|
||||
) : InlineKeyboardButton()
|
||||
|
||||
@Serializable
|
||||
data class URLInlineKeyboardButton(
|
||||
override val text: String,
|
||||
@SerialName(urlField)
|
||||
val url: String
|
||||
) : InlineKeyboardButton()
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringDescriptor
|
||||
import kotlinx.serialization.json.*
|
||||
|
||||
object InlineKeyboardButtonSerializer : KSerializer<InlineKeyboardButton> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName("com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons.InlineKeyboardButton")
|
||||
|
||||
private fun resolveSerializer(json: JsonObject): KSerializer<out InlineKeyboardButton> {
|
||||
return when {
|
||||
json[callbackDataField] != null -> CallbackDataInlineKeyboardButton.serializer()
|
||||
json[loginUrlField] != null -> LoginURLInlineKeyboardButton.serializer()
|
||||
json[payField] != null -> PayInlineKeyboardButton.serializer()
|
||||
json[switchInlineQueryField] != null -> SwitchInlineQueryInlineKeyboardButton.serializer()
|
||||
json[switchInlineQueryCurrentChatField] != null -> SwitchInlineQueryCurrentChatInlineKeyboardButton.serializer()
|
||||
json[urlField] != null -> URLInlineKeyboardButton.serializer()
|
||||
else -> throw IllegalArgumentException("Can't find correct serializer for inline button serialized as $json")
|
||||
}
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): InlineKeyboardButton {
|
||||
val json = JsonElementSerializer.deserialize(decoder)
|
||||
|
||||
return Json.nonstrict.fromJson(resolveSerializer(json.jsonObject), json)
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, obj: InlineKeyboardButton) {
|
||||
when (obj) {
|
||||
is CallbackDataInlineKeyboardButton -> CallbackDataInlineKeyboardButton.serializer().serialize(encoder, obj)
|
||||
is LoginURLInlineKeyboardButton -> LoginURLInlineKeyboardButton.serializer().serialize(encoder, obj)
|
||||
is PayInlineKeyboardButton -> PayInlineKeyboardButton.serializer().serialize(encoder, obj)
|
||||
is SwitchInlineQueryInlineKeyboardButton -> SwitchInlineQueryInlineKeyboardButton.serializer().serialize(encoder, obj)
|
||||
is SwitchInlineQueryCurrentChatInlineKeyboardButton -> SwitchInlineQueryCurrentChatInlineKeyboardButton.serializer().serialize(encoder, obj)
|
||||
is URLInlineKeyboardButton -> URLInlineKeyboardButton.serializer().serialize(encoder, obj)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
//TODO:: add check that this button first in a row (it MUST be first in a row)
|
||||
@Serializable
|
||||
data class PayInlineKeyboardButton(
|
||||
override val text: String,
|
||||
val pay: Boolean
|
||||
) : InlineKeyboardButton
|
@ -1,11 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class SwitchInlineQueryCurrentChatInlineKeyboardButton(
|
||||
override val text: String,
|
||||
@SerialName("switch_inline_query_currentChat")
|
||||
val switchInlineQueryCurrentChat: String
|
||||
) : InlineKeyboardButton
|
@ -1,11 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class SwitchInlineQueryInlineKeyboardButton(
|
||||
override val text: String,
|
||||
@SerialName("switch_inline_query")
|
||||
val switchInlineQuery: String
|
||||
) : InlineKeyboardButton
|
@ -1,9 +0,0 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardButtons
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class URLInlineKeyboardButton(
|
||||
override val text: String,
|
||||
val url: String
|
||||
) : InlineKeyboardButton
|
@ -2,6 +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.buttons.InlineKeyboardMarkup
|
||||
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
|
||||
@ -16,5 +17,6 @@ data class ChannelMediaGroupMessage(
|
||||
override val content: MediaGroupContent,
|
||||
override val editDate: DateTime?,
|
||||
override val forwarded: ForwardedMessage?,
|
||||
override val replyTo: Message?
|
||||
override val replyTo: Message?,
|
||||
override val replyMarkup: InlineKeyboardMarkup?
|
||||
) : MediaGroupMessage
|
||||
|
@ -2,6 +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.buttons.InlineKeyboardMarkup
|
||||
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
|
||||
@ -16,5 +17,6 @@ data class ChannelMessage<T: MessageContent>(
|
||||
override val editDate: DateTime?,
|
||||
override val forwarded: ForwardedMessage?,
|
||||
override val replyTo: Message?,
|
||||
override val replyMarkup: InlineKeyboardMarkup?,
|
||||
val authorSignature: AuthorSignature?
|
||||
) : CommonMessage<T>
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
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
|
||||
@ -15,5 +16,6 @@ data class CommonMediaGroupMessage(
|
||||
override val content: MediaGroupContent,
|
||||
override val editDate: DateTime?,
|
||||
override val forwarded: ForwardedMessage?,
|
||||
override val replyTo: Message?
|
||||
override val replyTo: Message?,
|
||||
override val replyMarkup: InlineKeyboardMarkup?
|
||||
) : MediaGroupMessage, FromUserMessage
|
||||
|
@ -2,6 +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.buttons.InlineKeyboardMarkup
|
||||
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
|
||||
@ -17,5 +18,6 @@ data class CommonMessageImpl<T: MessageContent>(
|
||||
override val editDate: DateTime?,
|
||||
override val forwarded: ForwardedMessage?,
|
||||
override val replyTo: Message?,
|
||||
override val replyMarkup: InlineKeyboardMarkup?,
|
||||
val paymentInfo: PaymentInfo?
|
||||
) : Message, CommonMessage<T>, FromUserMessage
|
@ -3,6 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message
|
||||
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.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.*
|
||||
@ -82,7 +83,9 @@ data class RawMessage(
|
||||
private val connected_website: String? = null,
|
||||
|
||||
// passport property
|
||||
private val passport_data: Unit? = null
|
||||
private val passport_data: Unit? = null,
|
||||
|
||||
private val reply_markup: InlineKeyboardMarkup? = null
|
||||
) {
|
||||
@Transient
|
||||
private val content: MessageContent? by lazy {
|
||||
@ -227,7 +230,8 @@ data class RawMessage(
|
||||
},
|
||||
edit_date ?.asDate,
|
||||
forwarded,
|
||||
reply_to_message ?.asMessage
|
||||
reply_to_message ?.asMessage,
|
||||
reply_markup
|
||||
)
|
||||
else -> CommonMediaGroupMessage(
|
||||
messageId,
|
||||
@ -242,7 +246,8 @@ data class RawMessage(
|
||||
},
|
||||
edit_date ?.asDate,
|
||||
forwarded,
|
||||
reply_to_message ?.asMessage
|
||||
reply_to_message ?.asMessage,
|
||||
reply_markup
|
||||
)
|
||||
}
|
||||
} ?: when (chat) {
|
||||
@ -254,6 +259,7 @@ data class RawMessage(
|
||||
edit_date ?.asDate,
|
||||
forwarded,
|
||||
reply_to_message ?.asMessage,
|
||||
reply_markup,
|
||||
author_signature
|
||||
)
|
||||
else -> CommonMessageImpl(
|
||||
@ -265,6 +271,7 @@ data class RawMessage(
|
||||
edit_date ?.asDate,
|
||||
forwarded,
|
||||
reply_to_message ?.asMessage,
|
||||
reply_markup,
|
||||
paymentInfo
|
||||
)
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
|
||||
interface AbleToBeMarkedUp {
|
||||
val replyMarkup: InlineKeyboardMarkup?
|
||||
}
|
@ -6,4 +6,5 @@ interface CommonMessage<T: MessageContent> : Message,
|
||||
AbleToBeForwardedMessage,
|
||||
AbleToBeEditedMessage,
|
||||
AbleToReplyMessage,
|
||||
AbleToBeMarkedUp,
|
||||
ContentMessage<T>
|
||||
|
Loading…
Reference in New Issue
Block a user