mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
commit
6daf98d47d
@ -1,5 +1,14 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 9.1.0
|
||||
|
||||
**This update contains adding of [Telegram Bot API 6.8](https://core.telegram.org/bots/api-changelog#august-18-2023) support**
|
||||
|
||||
* `Version`:
|
||||
* `Coroutines`: `1.7.2` -> `1.7.3`
|
||||
* `Ktor`: `2.3.2` -> `2.3.3`
|
||||
* `MicroUtils`: `0.19.7` -> `0.19.9`
|
||||
|
||||
## 9.0.0
|
||||
|
||||
**THIS UPDATE CONTAINS BREAKING CHANGES: USERNAMES OF BOTS NOW BECAME NULLABLE**
|
||||
|
@ -1,4 +1,4 @@
|
||||
# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-6.7-blue)](https://core.telegram.org/bots/api-changelog#april-21-2023)
|
||||
# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-6.8-blue)](https://core.telegram.org/bots/api-changelog#august-18-2023)
|
||||
|
||||
| Docs | [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue&logo=kotlin)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Mk&message=Docs&color=blue&logo=mkdocs)](https://docs.inmo.dev/tgbotapi/index.html) |
|
||||
|:----------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
|
||||
|
@ -6,4 +6,4 @@ kotlin.incremental=true
|
||||
kotlin.incremental.js=true
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=9.0.0
|
||||
library_version=9.1.0
|
||||
|
@ -2,18 +2,18 @@
|
||||
|
||||
kotlin = "1.8.22"
|
||||
kotlin-serialization = "1.5.1"
|
||||
kotlin-coroutines = "1.7.2"
|
||||
kotlin-coroutines = "1.7.3"
|
||||
|
||||
javax-activation = "1.1.1"
|
||||
|
||||
korlibs = "4.0.3"
|
||||
uuid = "0.7.1"
|
||||
ktor = "2.3.2"
|
||||
ktor = "2.3.3"
|
||||
|
||||
ksp = "1.8.22-1.0.11"
|
||||
kotlin-poet = "1.14.2"
|
||||
|
||||
microutils = "0.19.7"
|
||||
microutils = "0.19.9"
|
||||
|
||||
github-release-plugin = "2.4.1"
|
||||
dokka = "1.8.20"
|
||||
|
@ -0,0 +1,21 @@
|
||||
package dev.inmo.tgbotapi.extensions.api.chat.forum
|
||||
|
||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||
import dev.inmo.tgbotapi.requests.chat.forum.UnpinAllForumTopicMessages
|
||||
import dev.inmo.tgbotapi.requests.chat.forum.UnpinAllGeneralForumTopicMessages
|
||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.ForumTopic
|
||||
import dev.inmo.tgbotapi.types.MessageThreadId
|
||||
import dev.inmo.tgbotapi.types.chat.Chat
|
||||
|
||||
suspend fun TelegramBot.unpinAllGeneralForumTopicMessages(
|
||||
chatId: ChatIdentifier
|
||||
) = execute(
|
||||
UnpinAllGeneralForumTopicMessages(
|
||||
chatId
|
||||
)
|
||||
)
|
||||
|
||||
suspend fun TelegramBot.unpinAllGeneralForumTopicMessages(
|
||||
chat: Chat
|
||||
) = unpinAllGeneralForumTopicMessages(chat.id)
|
@ -62,6 +62,10 @@ suspend fun BehaviourContext.waitText(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitContent(initRequest, errorFactory).mapContent<TextContent>()
|
||||
suspend fun BehaviourContext.waitStory(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitContent(initRequest, errorFactory).mapContent<StoryContent>()
|
||||
suspend fun BehaviourContext.waitVenue(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
|
@ -74,6 +74,10 @@ suspend fun BehaviourContext.waitTextMessage(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitContentMessage(initRequest, errorFactory).mapWithContent<TextContent>()
|
||||
suspend fun BehaviourContext.waitStoryMessage(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitContentMessage(initRequest, errorFactory).mapWithContent<StoryContent>()
|
||||
suspend fun BehaviourContext.waitVenueMessage(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
|
@ -248,6 +248,30 @@ suspend fun <BC : BehaviourContext> BC.onText(
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
|
||||
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
|
||||
* to combinate several filters
|
||||
* @param [markerFactory] Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
|
||||
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
|
||||
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
|
||||
* data
|
||||
*/
|
||||
suspend fun <BC : BehaviourContext> BC.onStory(
|
||||
initialFilter: CommonMessageFilter<StoryContent>? = CommonMessageFilterExcludeMediaGroups,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, StoryMessage, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in StoryMessage, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, StoryMessage>
|
||||
) = onContentMessageWithType(
|
||||
initialFilter,
|
||||
subcontextUpdatesFilter,
|
||||
markerFactory,
|
||||
scenarioReceiver
|
||||
)
|
||||
|
||||
/**
|
||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
||||
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||
|
@ -0,0 +1,14 @@
|
||||
package dev.inmo.tgbotapi.requests.chat.forum
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class UnpinAllGeneralForumTopicMessages (
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
): ModifyForumRequest {
|
||||
override fun method(): String = "unpinAllGeneralForumTopicMessages"
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
@ -214,6 +214,7 @@ const val isPremiumField = "is_premium"
|
||||
const val hasPrivateForwardsField = "has_private_forwards"
|
||||
const val hasRestrictedVoiceAndVideoMessagesField = "has_restricted_voice_and_video_messages"
|
||||
const val emojiStatusCustomEmojiIdField = "emoji_status_custom_emoji_id"
|
||||
const val emojiStatusExpirationDateField = "emoji_status_expiration_date"
|
||||
const val iconCustomEmojiIdField = "icon_custom_emoji_id"
|
||||
const val canJoinGroupsField = "can_join_groups"
|
||||
const val canReadAllGroupMessagesField = "can_read_all_group_messages"
|
||||
@ -289,6 +290,7 @@ const val pinnedMessageField = "pinned_message"
|
||||
const val activeUsernamesField = "active_usernames"
|
||||
const val customTitleField = "custom_title"
|
||||
const val optionIdsField = "option_ids"
|
||||
const val voterChatField = "voter_chat"
|
||||
const val ipAddressField = "ip_address"
|
||||
const val linkedChatIdField = "linked_chat_id"
|
||||
const val hasHiddenMembersField = "has_hidden_members"
|
||||
|
@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import korlibs.time.DateTime
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
@ -78,7 +79,9 @@ data class ExtendedPrivateChatImpl(
|
||||
@SerialName(hasRestrictedVoiceAndVideoMessagesField)
|
||||
override val hasRestrictedVoiceAndVideoMessages: Boolean = false,
|
||||
@SerialName(emojiStatusCustomEmojiIdField)
|
||||
override val statusEmojiId: CustomEmojiId? = null
|
||||
override val statusEmojiId: CustomEmojiId? = null,
|
||||
@SerialName(emojiStatusExpirationDateField)
|
||||
override val statusEmojiExpiration: TelegramDate? = null
|
||||
) : ExtendedPrivateChat
|
||||
|
||||
typealias ExtendedUser = ExtendedPrivateChatImpl
|
||||
|
@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.chat
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
|
||||
import korlibs.time.DateTime
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable(ExtendedChatSerializer.Companion::class)
|
||||
@ -21,6 +22,7 @@ sealed interface ExtendedPrivateChat : PrivateChat, ExtendedChatWithUsername {
|
||||
val hasPrivateForwards: Boolean
|
||||
val hasRestrictedVoiceAndVideoMessages: Boolean
|
||||
val statusEmojiId: CustomEmojiId?
|
||||
val statusEmojiExpiration: TelegramDate?
|
||||
|
||||
val allowCreateUserIdLink: Boolean
|
||||
get() = hasPrivateForwards
|
||||
|
@ -31,6 +31,7 @@ import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
|
||||
import dev.inmo.tgbotapi.types.polls.Poll
|
||||
import dev.inmo.tgbotapi.types.request.ChatShared
|
||||
import dev.inmo.tgbotapi.types.request.UserShared
|
||||
import dev.inmo.tgbotapi.types.stories.Story
|
||||
import dev.inmo.tgbotapi.types.venue.Venue
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
@ -65,6 +66,7 @@ internal data class RawMessage(
|
||||
private val caption: String? = null,
|
||||
private val caption_entities: RawMessageEntities? = null,
|
||||
private val has_media_spoiler: Boolean? = null,
|
||||
private val story: Story? = null,
|
||||
private val audio: AudioFile? = null,
|
||||
private val document: DocumentFile? = null,
|
||||
private val animation: AnimationFile? = null,
|
||||
@ -134,6 +136,11 @@ internal data class RawMessage(
|
||||
} ?: emptyList()
|
||||
|
||||
when {
|
||||
story != null -> StoryContent(
|
||||
chat,
|
||||
messageId,
|
||||
story
|
||||
)
|
||||
text != null -> TextContent(text, (entities ?: emptyList()).asTextSources(text))
|
||||
audio != null -> AudioContent(
|
||||
audio,
|
||||
|
@ -0,0 +1,38 @@
|
||||
package dev.inmo.tgbotapi.types.message.content
|
||||
|
||||
import dev.inmo.tgbotapi.requests.ForwardMessage
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.MessageId
|
||||
import dev.inmo.tgbotapi.types.MessageThreadId
|
||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||
import dev.inmo.tgbotapi.types.chat.Chat
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.types.stories.Story
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class StoryContent(
|
||||
private val chat: Chat,
|
||||
private val messageId: MessageId,
|
||||
val story: Story
|
||||
) : MessageContent {
|
||||
override fun createResend(
|
||||
chatId: ChatIdentifier,
|
||||
messageThreadId: MessageThreadId?,
|
||||
disableNotification: Boolean,
|
||||
protectContent: Boolean,
|
||||
replyToMessageId: MessageId?,
|
||||
allowSendingWithoutReply: Boolean?,
|
||||
replyMarkup: KeyboardMarkup?
|
||||
): Request<out Message> {
|
||||
return ForwardMessage(
|
||||
chat.id,
|
||||
toChatId = chatId,
|
||||
messageId = messageId,
|
||||
threadId = messageThreadId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent
|
||||
)
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ typealias DiceMessage = CommonMessage<DiceContent>
|
||||
typealias ContactMessage = CommonMessage<ContactContent>
|
||||
typealias PollMessage = CommonMessage<PollContent>
|
||||
typealias TextMessage = CommonMessage<TextContent>
|
||||
typealias StoryMessage = CommonMessage<StoryContent>
|
||||
|
||||
typealias LocationMessage = CommonMessage<LocationContent>
|
||||
typealias LiveLocationMessage = CommonMessage<LiveLocationContent>
|
||||
|
@ -2,19 +2,95 @@ package dev.inmo.tgbotapi.types.polls
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.FromUser
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.ChannelChat
|
||||
import dev.inmo.tgbotapi.types.chat.CommonBot
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
@Serializable
|
||||
data class PollAnswer(
|
||||
@SerialName(pollIdField)
|
||||
val pollId: PollIdentifier,
|
||||
@SerialName(userField)
|
||||
override val user: User,
|
||||
@SerialName(optionIdsField)
|
||||
@Serializable(PollAnswer.Companion::class)
|
||||
sealed interface PollAnswer: FromUser {
|
||||
val pollId: PollIdentifier
|
||||
override val user: User
|
||||
val chosen: List<Int>
|
||||
) : FromUser {
|
||||
@Transient
|
||||
override val from: User
|
||||
get() = user
|
||||
|
||||
@Serializable
|
||||
data class Public(
|
||||
@SerialName(pollIdField)
|
||||
override val pollId: PollIdentifier,
|
||||
@SerialName(userField)
|
||||
override val user: User,
|
||||
@SerialName(optionIdsField)
|
||||
override val chosen: List<Int>,
|
||||
) : PollAnswer
|
||||
|
||||
@Serializable
|
||||
data class Anonymous(
|
||||
@SerialName(pollIdField)
|
||||
override val pollId: PollIdentifier,
|
||||
@SerialName(voterChatField)
|
||||
val voterChat: ChannelChat,
|
||||
@SerialName(optionIdsField)
|
||||
override val chosen: List<Int>
|
||||
) : PollAnswer {
|
||||
@SerialName(userField)
|
||||
override val user: User = defaultUser
|
||||
|
||||
companion object {
|
||||
val defaultUser = CommonBot(
|
||||
UserId(136817688L),
|
||||
"",
|
||||
"",
|
||||
Username("@Channel_Bot")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object : KSerializer<PollAnswer> {
|
||||
@Serializable
|
||||
private data class PollAnswerSurrogate(
|
||||
@SerialName(pollIdField)
|
||||
val pollId: PollIdentifier,
|
||||
@SerialName(optionIdsField)
|
||||
val chosen: List<Int>,
|
||||
@SerialName(userField)
|
||||
val user: User = Anonymous.defaultUser,
|
||||
@SerialName(voterChatField)
|
||||
val voterChat: ChannelChat? = null
|
||||
)
|
||||
operator fun invoke(
|
||||
pollId: PollIdentifier,
|
||||
user: User,
|
||||
chosen: List<Int>,
|
||||
) = Public(pollId, user, chosen)
|
||||
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = PollAnswerSurrogate.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): PollAnswer {
|
||||
val surrogate = PollAnswerSurrogate.serializer().deserialize(decoder)
|
||||
return if (surrogate.voterChat != null) {
|
||||
Anonymous(surrogate.pollId, surrogate.voterChat, surrogate.chosen)
|
||||
} else {
|
||||
Public(surrogate.pollId, surrogate.user, surrogate.chosen)
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: PollAnswer) {
|
||||
PollAnswerSurrogate.serializer().serialize(
|
||||
encoder,
|
||||
PollAnswerSurrogate(
|
||||
value.pollId,
|
||||
value.chosen,
|
||||
value.user,
|
||||
(value as? Anonymous) ?.voterChat
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.stories
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
class Story
|
@ -292,6 +292,7 @@ import dev.inmo.tgbotapi.types.message.content.ResendableContent
|
||||
import dev.inmo.tgbotapi.types.message.content.SpoilerableMediaContent
|
||||
import dev.inmo.tgbotapi.types.message.content.StaticLocationContent
|
||||
import dev.inmo.tgbotapi.types.message.content.StickerContent
|
||||
import dev.inmo.tgbotapi.types.message.content.StoryContent
|
||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
import dev.inmo.tgbotapi.types.message.content.TextedContent
|
||||
import dev.inmo.tgbotapi.types.message.content.TextedMediaContent
|
||||
@ -3480,6 +3481,15 @@ public inline fun ResendableContent.stickerContentOrThrow(): StickerContent = th
|
||||
public inline fun <T> ResendableContent.ifStickerContent(block: (StickerContent) -> T): T? =
|
||||
stickerContentOrNull() ?.let(block)
|
||||
|
||||
public inline fun ResendableContent.storyContentOrNull(): StoryContent? = this as?
|
||||
dev.inmo.tgbotapi.types.message.content.StoryContent
|
||||
|
||||
public inline fun ResendableContent.storyContentOrThrow(): StoryContent = this as
|
||||
dev.inmo.tgbotapi.types.message.content.StoryContent
|
||||
|
||||
public inline fun <T> ResendableContent.ifStoryContent(block: (StoryContent) -> T): T? =
|
||||
storyContentOrNull() ?.let(block)
|
||||
|
||||
public inline fun ResendableContent.textContentOrNull(): TextContent? = this as?
|
||||
dev.inmo.tgbotapi.types.message.content.TextContent
|
||||
|
||||
|
@ -21,6 +21,7 @@ fun Flow<ContentMessage<*>>.onlyPhotoContentMessages() = withContentType<PhotoCo
|
||||
fun Flow<ContentMessage<*>>.onlyPollContentMessages() = withContentType<PollContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyStickerContentMessages() = withContentType<StickerContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyTextContentMessages() = withContentType<TextContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyStoryContentMessages() = withContentType<StoryContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyVenueContentMessages() = withContentType<VenueContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyVideoContentMessages() = withContentType<VideoContent>()
|
||||
fun Flow<ContentMessage<*>>.onlyVideoNoteContentMessages() = withContentType<VideoNoteContent>()
|
||||
|
@ -120,6 +120,11 @@ fun FlowsUpdatesFilter.textMessages(
|
||||
scopeToIncludeChannels: CoroutineScope? = null
|
||||
) = filterContentMessages<TextContent>(scopeToIncludeChannels)
|
||||
|
||||
fun Flow<BaseSentMessageUpdate>.storyMessages() = filterContentMessages<StoryContent>()
|
||||
fun FlowsUpdatesFilter.storyMessages(
|
||||
scopeToIncludeChannels: CoroutineScope? = null
|
||||
) = filterContentMessages<StoryContent>(scopeToIncludeChannels)
|
||||
|
||||
fun Flow<BaseSentMessageUpdate>.venueMessages() = filterContentMessages<VenueContent>()
|
||||
fun FlowsUpdatesFilter.venueMessages(
|
||||
scopeToIncludeChannels: CoroutineScope? = null
|
||||
|
Loading…
Reference in New Issue
Block a user