mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-03 15:19:30 +00:00
Merge branch '25.0.0' into api-v9.0-gifts
This commit is contained in:
@@ -330,6 +330,57 @@ public final class dev/inmo/tgbotapi/extensions/api/bot/SetMyShortDescriptionKt
|
||||
public static synthetic fun setMyShortDescription$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Ldev/inmo/micro_utils/language_codes/IetfLang;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/business/DeleteBusinessMessagesGeneratedVariationKt {
|
||||
public static final fun deleteBusinessMessages-wC12z2M (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/business/DeleteBusinessMessagesKt {
|
||||
public static final fun deleteBusinessMessages-wC12z2M (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Ljava/util/List;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/business/GetBusinessAccountStarBalanceKt {
|
||||
public static final fun getBusinessAccountStarBalance-spp27rg (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/business/ReadBusinessMessageGeneratedVariationKt {
|
||||
public static final fun readBusinessMessage-1MWLODE (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Ldev/inmo/tgbotapi/types/chat/Chat;JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/business/ReadBusinessMessageKt {
|
||||
public static final fun readBusinessMessage-kYJnN-U (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;JJLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static final fun readBusinessMessage-wC12z2M (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Ldev/inmo/tgbotapi/types/message/abstracts/AccessibleMessage;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/business/RemoveBusinessAccountProfilePhotoKt {
|
||||
public static final fun removeBusinessAccountProfilePhoto-spp27rg (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/business/SetBusinessAccountBioKt {
|
||||
public static final fun setBusinessAccountBio-wC12z2M (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/business/SetBusinessAccountNameKt {
|
||||
public static final fun setBusinessAccountName-XzFA9qU (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun setBusinessAccountName-XzFA9qU$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/business/SetBusinessAccountProfilePhotoKt {
|
||||
public static final fun setBusinessAccountProfilePhoto-XzFA9qU (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Ldev/inmo/tgbotapi/requests/business_connection/InputProfilePhoto;ZLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun setBusinessAccountProfilePhoto-XzFA9qU$default (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Ldev/inmo/tgbotapi/requests/business_connection/InputProfilePhoto;ZLkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/business/SetBusinessAccountUsernameGeneratedVariationKt {
|
||||
public static final fun setBusinessAccountUsername-wC12z2M (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/business/SetBusinessAccountUsernameKt {
|
||||
public static final fun setBusinessAccountUsername-_dB6Ko0 (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/business/TransferBusinessAccountStarBalanceKt {
|
||||
public static final fun transferBusinessAccountStarBalance-wC12z2M (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ljava/lang/String;ILkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class dev/inmo/tgbotapi/extensions/api/chat/ExportChatInviteLinkKt {
|
||||
public static final fun exportChatInviteLink (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/ChatIdentifier;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static final fun exportChatInviteLink (Ldev/inmo/tgbotapi/bot/RequestsExecutor;Ldev/inmo/tgbotapi/types/chat/PublicChat;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
|
@@ -654,6 +654,8 @@ public final class dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/W
|
||||
public static synthetic fun waitNewChatPhotoEvents$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun waitNewChatTitleEvents (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun waitNewChatTitleEvents$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun waitPaidMessagePriceChanged (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun waitPaidMessagePriceChanged$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun waitPinnedMessageEvents (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun waitPinnedMessageEvents$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun waitPrivateEvents (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
@@ -743,6 +745,8 @@ public final class dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/W
|
||||
public static synthetic fun waitNewChatPhotoEventsMessages$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun waitNewChatTitleEventsMessages (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun waitNewChatTitleEventsMessages$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun waitPaidMessagePriceChangedMessages (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun waitPaidMessagePriceChangedMessages$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun waitPinnedMessageEventsMessages (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun waitPinnedMessageEventsMessages$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun waitPrivateEventsMessages (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/requests/abstracts/Request;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
@@ -1348,6 +1352,8 @@ public final class dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handl
|
||||
public static synthetic fun onNewChatPhoto$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;Lkotlin/jvm/functions/Function4;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun onNewChatTitle (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;Lkotlin/jvm/functions/Function4;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun onNewChatTitle$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;Lkotlin/jvm/functions/Function4;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun onPaidMessagePriceChanged (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;Lkotlin/jvm/functions/Function4;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun onPaidMessagePriceChanged$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;Lkotlin/jvm/functions/Function4;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun onPinnedMessage (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;Lkotlin/jvm/functions/Function4;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun onPinnedMessage$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;Lkotlin/jvm/functions/Function4;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun onPrivateEvent (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/SimpleFilter;Lkotlin/jvm/functions/Function4;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/marker_factories/MarkerFactory;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
|
@@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.utils.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.PaidMessagePriceChanged
|
||||
import dev.inmo.tgbotapi.types.chat.ChatBackground
|
||||
import dev.inmo.tgbotapi.types.giveaway.GiveawayCreated
|
||||
import dev.inmo.tgbotapi.types.giveaway.GiveawayPrivateResults
|
||||
@@ -248,3 +249,8 @@ suspend fun BehaviourContext.waitGiveawayCompletedWithPrivateWinners(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitGiveawayCompleted(initRequest, errorFactory)
|
||||
|
||||
suspend fun BehaviourContext.waitPaidMessagePriceChanged(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEvents<PaidMessagePriceChanged>(initRequest, errorFactory)
|
||||
|
@@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||
import dev.inmo.tgbotapi.extensions.utils.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.PaidMessagePriceChanged
|
||||
import dev.inmo.tgbotapi.types.chat.ChatBackground
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||
@@ -224,3 +225,8 @@ suspend fun BehaviourContext.waitChatBackgroundSetEventsMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEventsMessages<ChatBackground>(initRequest, errorFactory)
|
||||
|
||||
suspend fun BehaviourContext.waitPaidMessagePriceChangedMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEventsMessages<PaidMessagePriceChanged>(initRequest, errorFactory)
|
||||
|
@@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.Mar
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
||||
import dev.inmo.tgbotapi.extensions.utils.baseSentMessageUpdateOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.chatEventMessageOrNull
|
||||
import dev.inmo.tgbotapi.types.PaidMessagePriceChanged
|
||||
import dev.inmo.tgbotapi.types.chat.ChatBackground
|
||||
import dev.inmo.tgbotapi.types.giveaway.GiveawayCreated
|
||||
import dev.inmo.tgbotapi.types.giveaway.GiveawayPrivateResults
|
||||
@@ -1045,3 +1046,25 @@ suspend fun <BC : BehaviourContext> BC.onGiveawayCompletedWithPrivateWinners(
|
||||
additionalSubcontextInitialAction: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, Update, ChatEventMessage<GiveawayPrivateResults>>? = null,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<GiveawayPrivateResults>>
|
||||
) = onGiveawayCompleted(initialFilter, subcontextUpdatesFilter, markerFactory, additionalSubcontextInitialAction, 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] **Pass null to handle requests fully parallel**. 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.onPaidMessagePriceChanged(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<PaidMessagePriceChanged>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<PaidMessagePriceChanged>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<PaidMessagePriceChanged>, Any>? = ByChatMessageMarkerFactory,
|
||||
additionalSubcontextInitialAction: CustomBehaviourContextAndTwoTypesReceiver<BC, Unit, Update, ChatEventMessage<PaidMessagePriceChanged>>? = null,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<PaidMessagePriceChanged>>
|
||||
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, additionalSubcontextInitialAction, scenarioReceiver)
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -615,6 +615,9 @@ const val mediaField = "media"
|
||||
|
||||
const val mainFrameTimestampField = "main_frame_timestamp"
|
||||
|
||||
const val paidMessageStarCountField = "paid_message_star_count"
|
||||
const val paidStarCountField = "paid_star_count"
|
||||
|
||||
const val disableEditMessageField = "disable_edit_message"
|
||||
const val scoreField = "score"
|
||||
const val forceField = "force"
|
||||
|
@@ -0,0 +1,11 @@
|
||||
package dev.inmo.tgbotapi.types
|
||||
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PaidMessagePriceChanged(
|
||||
@SerialName(paidMessageStarCountField)
|
||||
val cost: Int
|
||||
) : CommonEvent
|
@@ -11,6 +11,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||
import kotlinx.serialization.SerialName
|
||||
|
||||
data class BusinessContentMessageImpl<T: MessageContent>(
|
||||
override val messageId: MessageId,
|
||||
@@ -28,6 +29,8 @@ data class BusinessContentMessageImpl<T: MessageContent>(
|
||||
override val mediaGroupId: MediaGroupId?,
|
||||
override val senderBusinessBot: PreviewBot?,
|
||||
override val fromOffline: Boolean,
|
||||
@SerialName(paidMessageStarCountField)
|
||||
override val cost: Int? = null,
|
||||
) : BusinessContentMessage<T> {
|
||||
constructor(
|
||||
messageId: MessageId,
|
||||
|
@@ -9,6 +9,7 @@ import dev.inmo.tgbotapi.types.chat.PreviewChat
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||
import kotlinx.serialization.SerialName
|
||||
|
||||
data class ChannelContentMessageImpl<T: MessageContent>(
|
||||
override val messageId: MessageId,
|
||||
@@ -25,6 +26,8 @@ data class ChannelContentMessageImpl<T: MessageContent>(
|
||||
override val authorSignature: AuthorSignature?,
|
||||
override val mediaGroupId: MediaGroupId?,
|
||||
override val fromOffline: Boolean,
|
||||
@SerialName(paidMessageStarCountField)
|
||||
override val cost: Int? = null,
|
||||
) : ChannelContentMessage<T> {
|
||||
constructor(
|
||||
messageId: MessageId,
|
||||
|
@@ -8,6 +8,7 @@ import dev.inmo.tgbotapi.types.chat.CommonBot
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||
import kotlinx.serialization.SerialName
|
||||
|
||||
data class ConnectedFromChannelGroupContentMessageImpl<T : MessageContent>(
|
||||
override val chat: PreviewGroupChat,
|
||||
@@ -24,6 +25,8 @@ data class ConnectedFromChannelGroupContentMessageImpl<T : MessageContent>(
|
||||
override val authorSignature: AuthorSignature?,
|
||||
override val mediaGroupId: MediaGroupId?,
|
||||
override val fromOffline: Boolean,
|
||||
@SerialName(paidMessageStarCountField)
|
||||
override val cost: Int? = null,
|
||||
) : ConnectedFromChannelGroupContentMessage<T> {
|
||||
|
||||
constructor(
|
||||
@@ -41,8 +44,23 @@ data class ConnectedFromChannelGroupContentMessageImpl<T : MessageContent>(
|
||||
authorSignature: AuthorSignature?,
|
||||
mediaGroupId: MediaGroupId?,
|
||||
fromOffline: Boolean,
|
||||
cost: Int? = null,
|
||||
) : this(
|
||||
chat, channel, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId, fromOffline
|
||||
chat = chat,
|
||||
channel = channel,
|
||||
messageId = messageId,
|
||||
date = date,
|
||||
forwardOrigin = forwardInfo.messageOrigin(),
|
||||
editDate = editDate,
|
||||
hasProtectedContent = hasProtectedContent,
|
||||
replyInfo = replyTo ?.let { ReplyInfo.Internal(it) },
|
||||
replyMarkup = replyMarkup,
|
||||
content = content,
|
||||
senderBot = senderBot,
|
||||
authorSignature = authorSignature,
|
||||
mediaGroupId = mediaGroupId,
|
||||
fromOffline = fromOffline,
|
||||
cost = cost,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -61,6 +79,8 @@ data class UnconnectedFromChannelGroupContentMessageImpl<T: MessageContent>(
|
||||
override val authorSignature: AuthorSignature?,
|
||||
override val mediaGroupId: MediaGroupId?,
|
||||
override val fromOffline: Boolean,
|
||||
@SerialName(paidMessageStarCountField)
|
||||
override val cost: Int? = null,
|
||||
) : UnconnectedFromChannelGroupContentMessage<T> {
|
||||
constructor(
|
||||
chat: PreviewGroupChat,
|
||||
@@ -77,8 +97,23 @@ data class UnconnectedFromChannelGroupContentMessageImpl<T: MessageContent>(
|
||||
authorSignature: AuthorSignature?,
|
||||
mediaGroupId: MediaGroupId?,
|
||||
fromOffline: Boolean,
|
||||
cost: Int? = null,
|
||||
) : this(
|
||||
chat, channel, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId, fromOffline
|
||||
chat = chat,
|
||||
channel = channel,
|
||||
messageId = messageId,
|
||||
date = date,
|
||||
forwardOrigin = forwardInfo.messageOrigin(),
|
||||
editDate = editDate,
|
||||
hasProtectedContent = hasProtectedContent,
|
||||
replyInfo = replyTo ?.let { ReplyInfo.Internal(it) },
|
||||
replyMarkup = replyMarkup,
|
||||
content = content,
|
||||
senderBot = senderBot,
|
||||
authorSignature = authorSignature,
|
||||
mediaGroupId = mediaGroupId,
|
||||
fromOffline = fromOffline,
|
||||
cost = cost,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -96,6 +131,8 @@ data class AnonymousGroupContentMessageImpl<T : MessageContent>(
|
||||
override val authorSignature: AuthorSignature?,
|
||||
override val mediaGroupId: MediaGroupId?,
|
||||
override val fromOffline: Boolean,
|
||||
@SerialName(paidMessageStarCountField)
|
||||
override val cost: Int? = null,
|
||||
) : AnonymousGroupContentMessage<T> {
|
||||
constructor(
|
||||
chat: PreviewGroupChat,
|
||||
@@ -111,8 +148,22 @@ data class AnonymousGroupContentMessageImpl<T : MessageContent>(
|
||||
authorSignature: AuthorSignature?,
|
||||
mediaGroupId: MediaGroupId?,
|
||||
fromOffline: Boolean,
|
||||
cost: Int? = null,
|
||||
) : this(
|
||||
chat, messageId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId, fromOffline
|
||||
chat = chat,
|
||||
messageId = messageId,
|
||||
date = date,
|
||||
forwardOrigin = forwardInfo.messageOrigin(),
|
||||
editDate = editDate,
|
||||
hasProtectedContent = hasProtectedContent,
|
||||
replyInfo = replyTo ?.let { ReplyInfo.Internal(it) },
|
||||
replyMarkup = replyMarkup,
|
||||
content = content,
|
||||
senderBot = senderBot,
|
||||
authorSignature = authorSignature,
|
||||
mediaGroupId = mediaGroupId,
|
||||
fromOffline = fromOffline,
|
||||
cost = cost,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -131,6 +182,8 @@ data class CommonGroupContentMessageImpl<T : MessageContent>(
|
||||
override val mediaGroupId: MediaGroupId?,
|
||||
override val senderBoostsCount: Int?,
|
||||
override val fromOffline: Boolean,
|
||||
@SerialName(paidMessageStarCountField)
|
||||
override val cost: Int? = null,
|
||||
) : CommonGroupContentMessage<T> {
|
||||
constructor(
|
||||
chat: PreviewGroupChat,
|
||||
@@ -147,8 +200,23 @@ data class CommonGroupContentMessageImpl<T : MessageContent>(
|
||||
mediaGroupId: MediaGroupId?,
|
||||
senderBoostsCount: Int?,
|
||||
fromOffline: Boolean,
|
||||
cost: Int? = null,
|
||||
) : this(
|
||||
chat, messageId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId, senderBoostsCount, fromOffline
|
||||
chat = chat,
|
||||
messageId = messageId,
|
||||
from = from,
|
||||
date = date,
|
||||
forwardOrigin = forwardInfo.messageOrigin(),
|
||||
editDate = editDate,
|
||||
hasProtectedContent = hasProtectedContent,
|
||||
replyInfo = replyTo ?.let { ReplyInfo.Internal(it) },
|
||||
replyMarkup = replyMarkup,
|
||||
content = content,
|
||||
senderBot = senderBot,
|
||||
mediaGroupId = mediaGroupId,
|
||||
senderBoostsCount = senderBoostsCount,
|
||||
fromOffline = fromOffline,
|
||||
cost = cost,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -168,6 +236,8 @@ data class FromChannelForumContentMessageImpl<T: MessageContent>(
|
||||
override val authorSignature: AuthorSignature?,
|
||||
override val mediaGroupId: MediaGroupId?,
|
||||
override val fromOffline: Boolean,
|
||||
@SerialName(paidMessageStarCountField)
|
||||
override val cost: Int? = null,
|
||||
) : FromChannelForumContentMessage<T> {
|
||||
constructor(
|
||||
chat: PreviewForumChat,
|
||||
@@ -185,8 +255,24 @@ data class FromChannelForumContentMessageImpl<T: MessageContent>(
|
||||
authorSignature: AuthorSignature?,
|
||||
mediaGroupId: MediaGroupId?,
|
||||
fromOffline: Boolean,
|
||||
cost: Int? = null,
|
||||
) : this(
|
||||
chat, channel, messageId, threadId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId, fromOffline
|
||||
chat = chat,
|
||||
channel = channel,
|
||||
messageId = messageId,
|
||||
threadId = threadId,
|
||||
date = date,
|
||||
forwardOrigin = forwardInfo.messageOrigin(),
|
||||
editDate = editDate,
|
||||
hasProtectedContent = hasProtectedContent,
|
||||
replyInfo = replyTo ?.let { ReplyInfo.Internal(it) },
|
||||
replyMarkup = replyMarkup,
|
||||
content = content,
|
||||
senderBot = senderBot,
|
||||
authorSignature = authorSignature,
|
||||
mediaGroupId = mediaGroupId,
|
||||
fromOffline = fromOffline,
|
||||
cost = cost,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -205,6 +291,8 @@ data class AnonymousForumContentMessageImpl<T : MessageContent>(
|
||||
override val authorSignature: AuthorSignature?,
|
||||
override val mediaGroupId: MediaGroupId?,
|
||||
override val fromOffline: Boolean,
|
||||
@SerialName(paidMessageStarCountField)
|
||||
override val cost: Int? = null,
|
||||
) : AnonymousForumContentMessage<T> {
|
||||
constructor(
|
||||
chat: PreviewForumChat,
|
||||
@@ -221,8 +309,23 @@ data class AnonymousForumContentMessageImpl<T : MessageContent>(
|
||||
authorSignature: AuthorSignature?,
|
||||
mediaGroupId: MediaGroupId?,
|
||||
fromOffline: Boolean,
|
||||
cost: Int? = null,
|
||||
) : this(
|
||||
chat, messageId, threadId, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, authorSignature, mediaGroupId, fromOffline
|
||||
chat = chat,
|
||||
messageId = messageId,
|
||||
threadId = threadId,
|
||||
date = date,
|
||||
forwardOrigin = forwardInfo.messageOrigin(),
|
||||
editDate = editDate,
|
||||
hasProtectedContent = hasProtectedContent,
|
||||
replyInfo = replyTo ?.let { ReplyInfo.Internal(it) },
|
||||
replyMarkup = replyMarkup,
|
||||
content = content,
|
||||
senderBot = senderBot,
|
||||
authorSignature = authorSignature,
|
||||
mediaGroupId = mediaGroupId,
|
||||
fromOffline = fromOffline,
|
||||
cost = cost,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -242,6 +345,8 @@ data class CommonForumContentMessageImpl<T : MessageContent>(
|
||||
override val mediaGroupId: MediaGroupId?,
|
||||
override val senderBoostsCount: Int?,
|
||||
override val fromOffline: Boolean,
|
||||
@SerialName(paidMessageStarCountField)
|
||||
override val cost: Int? = null,
|
||||
) : CommonForumContentMessage<T> {
|
||||
constructor(
|
||||
chat: PreviewForumChat,
|
||||
@@ -259,7 +364,23 @@ data class CommonForumContentMessageImpl<T : MessageContent>(
|
||||
mediaGroupId: MediaGroupId?,
|
||||
senderBoostsCount: Int?,
|
||||
fromOffline: Boolean,
|
||||
cost: Int? = null,
|
||||
) : this(
|
||||
chat, messageId, threadId, from, date, forwardInfo.messageOrigin(), editDate, hasProtectedContent, replyTo ?.let { ReplyInfo.Internal(it) }, replyMarkup, content, senderBot, mediaGroupId, senderBoostsCount, fromOffline
|
||||
chat = chat,
|
||||
messageId = messageId,
|
||||
threadId = threadId,
|
||||
from = from,
|
||||
date = date,
|
||||
forwardOrigin = forwardInfo.messageOrigin(),
|
||||
editDate = editDate,
|
||||
hasProtectedContent = hasProtectedContent,
|
||||
replyInfo = replyTo ?.let { ReplyInfo.Internal(it) },
|
||||
replyMarkup = replyMarkup,
|
||||
content = content,
|
||||
senderBot = senderBot,
|
||||
mediaGroupId = mediaGroupId,
|
||||
senderBoostsCount = senderBoostsCount,
|
||||
fromOffline = fromOffline,
|
||||
cost = cost,
|
||||
)
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ import dev.inmo.tgbotapi.types.chat.User
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||
import kotlinx.serialization.SerialName
|
||||
|
||||
data class PrivateContentMessageImpl<T: MessageContent>(
|
||||
override val messageId: MessageId,
|
||||
@@ -24,7 +25,9 @@ data class PrivateContentMessageImpl<T: MessageContent>(
|
||||
override val senderBot: CommonBot?,
|
||||
override val mediaGroupId: MediaGroupId?,
|
||||
override val fromOffline: Boolean,
|
||||
override val effectId: EffectId?
|
||||
override val effectId: EffectId?,
|
||||
@SerialName(paidStarCountField)
|
||||
override val cost: Int? = null
|
||||
) : PrivateContentMessage<T> {
|
||||
constructor(
|
||||
messageId: MessageId,
|
||||
|
@@ -110,6 +110,9 @@ internal data class RawMessage(
|
||||
|
||||
private val is_from_offline: Boolean = false,
|
||||
|
||||
private val paid_star_count: Int? = null,
|
||||
private val paid_message_price_changed: PaidMessagePriceChanged? = null,
|
||||
|
||||
// Voice Chat Service Messages
|
||||
private val video_chat_scheduled: VideoChatScheduled? = null,
|
||||
private val video_chat_started: VideoChatStarted? = null,
|
||||
@@ -163,7 +166,7 @@ internal data class RawMessage(
|
||||
private val giveaway_completed: GiveawayPrivateResults? = null,
|
||||
|
||||
// Gifts
|
||||
private val gift: GiftInfo? = null
|
||||
private val gift: GiftInfo? = null,
|
||||
) {
|
||||
private val checkedFrom = from ?.takeIf { !it.isFakeTelegramUser() }
|
||||
private val content: MessageContent? by lazy {
|
||||
@@ -286,6 +289,7 @@ internal data class RawMessage(
|
||||
giveaway_completed != null -> giveaway_completed
|
||||
boost_added != null -> boost_added
|
||||
chat_background_set != null -> chat_background_set
|
||||
paid_message_price_changed != null -> paid_message_price_changed
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@@ -299,7 +303,7 @@ internal data class RawMessage(
|
||||
}
|
||||
|
||||
try {
|
||||
chatEvent?.let { chatEvent ->
|
||||
chatEvent ?.let { chatEvent ->
|
||||
when (chat) {
|
||||
is PreviewSupergroupChat -> CommonSupergroupEventMessage(
|
||||
messageId,
|
||||
@@ -354,7 +358,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
authorSignature = author_signature,
|
||||
mediaGroupId = media_group_id,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
is PreviewForumChat -> if (messageThreadId != null) {
|
||||
val chatId = ChatIdWithThreadId(
|
||||
@@ -380,7 +385,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
authorSignature = author_signature,
|
||||
mediaGroupId = media_group_id,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
is PreviewGroupChat -> AnonymousForumContentMessageImpl(
|
||||
chat = actualForumChat,
|
||||
@@ -396,7 +402,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
authorSignature = author_signature,
|
||||
mediaGroupId = media_group_id,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
null -> CommonForumContentMessageImpl(
|
||||
chat = actualForumChat,
|
||||
@@ -413,7 +420,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
mediaGroupId = media_group_id,
|
||||
senderBoostsCount = sender_boost_count,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@@ -433,7 +441,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
authorSignature = author_signature,
|
||||
mediaGroupId = media_group_id,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
} else {
|
||||
UnconnectedFromChannelGroupContentMessageImpl(
|
||||
@@ -450,7 +459,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
authorSignature = author_signature,
|
||||
mediaGroupId = media_group_id,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
}
|
||||
is GroupChat -> AnonymousGroupContentMessageImpl(
|
||||
@@ -466,7 +476,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
authorSignature = author_signature,
|
||||
mediaGroupId = media_group_id,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
null -> CommonGroupContentMessageImpl(
|
||||
chat = chat,
|
||||
@@ -482,7 +493,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
mediaGroupId = media_group_id,
|
||||
senderBoostsCount = sender_boost_count,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -502,7 +514,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
authorSignature = author_signature,
|
||||
mediaGroupId = media_group_id,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
} else {
|
||||
UnconnectedFromChannelGroupContentMessageImpl(
|
||||
@@ -519,7 +532,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
authorSignature = author_signature,
|
||||
mediaGroupId = media_group_id,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
}
|
||||
is PreviewGroupChat -> AnonymousGroupContentMessageImpl(
|
||||
@@ -535,7 +549,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
authorSignature = author_signature,
|
||||
mediaGroupId = media_group_id,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
null -> CommonGroupContentMessageImpl(
|
||||
chat = chat,
|
||||
@@ -551,7 +566,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
mediaGroupId = media_group_id,
|
||||
senderBoostsCount = sender_boost_count,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -570,7 +586,8 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
mediaGroupId = media_group_id,
|
||||
fromOffline = is_from_offline,
|
||||
effectId = effect_id
|
||||
effectId = effect_id,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
} else {
|
||||
BusinessContentMessageImpl(
|
||||
@@ -591,18 +608,19 @@ internal data class RawMessage(
|
||||
senderBot = via_bot,
|
||||
mediaGroupId = media_group_id,
|
||||
senderBusinessBot = sender_business_bot,
|
||||
fromOffline = is_from_offline
|
||||
fromOffline = is_from_offline,
|
||||
cost = paid_star_count,
|
||||
)
|
||||
}
|
||||
else -> error("Unknown type of chat: $chat")
|
||||
}
|
||||
} ?: passport_data ?.let{
|
||||
PassportMessage(
|
||||
messageId,
|
||||
chat,
|
||||
checkedFrom ?: from ?: error("For passport must be provided user, but got null"),
|
||||
date.asDate,
|
||||
passport_data
|
||||
messageId = messageId,
|
||||
chat = chat,
|
||||
from = checkedFrom ?: from ?: error("For passport must be provided user, but got null"),
|
||||
date = date.asDate,
|
||||
passportData = passport_data,
|
||||
)
|
||||
} ?: error("Was not found supported type of data")
|
||||
} catch (e: Exception) {
|
||||
|
@@ -10,4 +10,5 @@ sealed interface CommonMessage<out T: MessageContent> : AccessibleMessage,
|
||||
PossiblyBusinessMessage,
|
||||
PossiblyOfflineMessage,
|
||||
PossiblyMediaGroupMessage<T>,
|
||||
PossiblyPaidMessage,
|
||||
ContentMessage<T>
|
||||
|
@@ -0,0 +1,5 @@
|
||||
package dev.inmo.tgbotapi.types.message.abstracts
|
||||
|
||||
interface PossiblyPaidMessage : Message {
|
||||
val cost: Int?
|
||||
}
|
@@ -29,7 +29,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
|
||||
senderBot = sourceMessage.senderBot,
|
||||
authorSignature = sourceMessage.authorSignature,
|
||||
mediaGroupId = sourceMessage.mediaGroupId,
|
||||
fromOffline = sourceMessage.fromOffline
|
||||
fromOffline = sourceMessage.fromOffline,
|
||||
cost = sourceMessage.cost,
|
||||
)
|
||||
is BusinessContentMessage -> BusinessContentMessageImpl(
|
||||
messageId = sourceMessage.messageId,
|
||||
@@ -46,7 +47,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
|
||||
senderBot = sourceMessage.senderBot,
|
||||
mediaGroupId = sourceMessage.mediaGroupId,
|
||||
senderBusinessBot = sourceMessage.senderBusinessBot,
|
||||
fromOffline = sourceMessage.fromOffline
|
||||
fromOffline = sourceMessage.fromOffline,
|
||||
cost = sourceMessage.cost,
|
||||
)
|
||||
is PrivateContentMessage -> PrivateContentMessageImpl(
|
||||
messageId = sourceMessage.messageId,
|
||||
@@ -62,7 +64,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
|
||||
senderBot = sourceMessage.senderBot,
|
||||
mediaGroupId = sourceMessage.mediaGroupId,
|
||||
fromOffline = sourceMessage.fromOffline,
|
||||
effectId = sourceMessage.effectId
|
||||
effectId = sourceMessage.effectId,
|
||||
cost = sourceMessage.cost,
|
||||
)
|
||||
is AnonymousGroupContentMessage -> AnonymousGroupContentMessageImpl(
|
||||
chat = sourceMessage.chat,
|
||||
@@ -77,7 +80,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
|
||||
senderBot = sourceMessage.senderBot,
|
||||
authorSignature = sourceMessage.authorSignature,
|
||||
mediaGroupId = sourceMessage.mediaGroupId,
|
||||
fromOffline = sourceMessage.fromOffline
|
||||
fromOffline = sourceMessage.fromOffline,
|
||||
cost = sourceMessage.cost,
|
||||
)
|
||||
is CommonGroupContentMessage -> CommonGroupContentMessageImpl(
|
||||
chat = sourceMessage.chat,
|
||||
@@ -93,7 +97,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
|
||||
senderBot = sourceMessage.senderBot,
|
||||
mediaGroupId = sourceMessage.mediaGroupId,
|
||||
senderBoostsCount = sourceMessage.senderBoostsCount,
|
||||
fromOffline = sourceMessage.fromOffline
|
||||
fromOffline = sourceMessage.fromOffline,
|
||||
cost = sourceMessage.cost,
|
||||
)
|
||||
is ConnectedFromChannelGroupContentMessage -> ConnectedFromChannelGroupContentMessageImpl(
|
||||
chat = sourceMessage.chat,
|
||||
@@ -109,7 +114,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
|
||||
senderBot = sourceMessage.senderBot,
|
||||
authorSignature = sourceMessage.authorSignature,
|
||||
mediaGroupId = sourceMessage.mediaGroupId,
|
||||
fromOffline = sourceMessage.fromOffline
|
||||
fromOffline = sourceMessage.fromOffline,
|
||||
cost = sourceMessage.cost,
|
||||
)
|
||||
is UnconnectedFromChannelGroupContentMessage -> UnconnectedFromChannelGroupContentMessageImpl(
|
||||
chat = sourceMessage.chat,
|
||||
@@ -125,7 +131,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
|
||||
senderBot = sourceMessage.senderBot,
|
||||
authorSignature = sourceMessage.authorSignature,
|
||||
mediaGroupId = sourceMessage.mediaGroupId,
|
||||
fromOffline = sourceMessage.fromOffline
|
||||
fromOffline = sourceMessage.fromOffline,
|
||||
cost = sourceMessage.cost,
|
||||
)
|
||||
is AnonymousForumContentMessage -> AnonymousForumContentMessageImpl(
|
||||
chat = sourceMessage.chat,
|
||||
@@ -141,7 +148,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
|
||||
senderBot = sourceMessage.senderBot,
|
||||
authorSignature = sourceMessage.authorSignature,
|
||||
mediaGroupId = sourceMessage.mediaGroupId,
|
||||
fromOffline = sourceMessage.fromOffline
|
||||
fromOffline = sourceMessage.fromOffline,
|
||||
cost = sourceMessage.cost,
|
||||
)
|
||||
is CommonForumContentMessage -> CommonForumContentMessageImpl(
|
||||
chat = sourceMessage.chat,
|
||||
@@ -158,7 +166,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
|
||||
senderBot = sourceMessage.senderBot,
|
||||
mediaGroupId = sourceMessage.mediaGroupId,
|
||||
senderBoostsCount = sourceMessage.senderBoostsCount,
|
||||
fromOffline = sourceMessage.fromOffline
|
||||
fromOffline = sourceMessage.fromOffline,
|
||||
cost = sourceMessage.cost,
|
||||
)
|
||||
is FromChannelForumContentMessage -> FromChannelForumContentMessageImpl(
|
||||
chat = sourceMessage.chat,
|
||||
@@ -175,7 +184,8 @@ fun <T : MediaGroupPartContent> List<PossiblySentViaBotCommonMessage<T>>.asMedia
|
||||
senderBot = sourceMessage.senderBot,
|
||||
authorSignature = sourceMessage.authorSignature,
|
||||
mediaGroupId = sourceMessage.mediaGroupId,
|
||||
fromOffline = sourceMessage.fromOffline
|
||||
fromOffline = sourceMessage.fromOffline,
|
||||
cost = sourceMessage.cost,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@@ -1794,6 +1794,7 @@ public final class dev/inmo/tgbotapi/extensions/utils/ClassCastsNewKt {
|
||||
public static final fun ifPaidMediaInfoContent (Ldev/inmo/tgbotapi/types/message/content/ResendableContent;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
public static final fun ifPaidMediaPurchased (Ldev/inmo/tgbotapi/abstracts/OptionallyWithUser;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
public static final fun ifPaidMediaPurchasedUpdate (Ldev/inmo/tgbotapi/types/update/abstracts/Update;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
public static final fun ifPaidMessagePriceChanged (Ldev/inmo/tgbotapi/types/message/ChatEvents/abstracts/ChatEvent;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
public static final fun ifPassport (Ldev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElement;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
public static final fun ifPassportElementErrorDataField (Ldev/inmo/tgbotapi/types/passport/PassportElementError;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
public static final fun ifPassportElementErrorFile (Ldev/inmo/tgbotapi/types/passport/PassportElementError;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
@@ -1834,6 +1835,7 @@ public final class dev/inmo/tgbotapi/extensions/utils/ClassCastsNewKt {
|
||||
public static final fun ifPossiblyForwardedMessage (Ldev/inmo/tgbotapi/types/message/abstracts/Message;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
public static final fun ifPossiblyMediaGroupMessage (Ldev/inmo/tgbotapi/types/message/abstracts/Message;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
public static final fun ifPossiblyOfflineMessage (Ldev/inmo/tgbotapi/types/message/abstracts/Message;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
public static final fun ifPossiblyPaidMessage (Ldev/inmo/tgbotapi/types/message/abstracts/Message;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
public static final fun ifPossiblyPaymentMessage (Ldev/inmo/tgbotapi/types/message/abstracts/Message;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
public static final fun ifPossiblyPremiumChat (Ldev/inmo/tgbotapi/types/chat/Chat;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
public static final fun ifPossiblySentViaBotCommonMessage (Ldev/inmo/tgbotapi/types/message/abstracts/Message;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
|
||||
@@ -2222,6 +2224,8 @@ public final class dev/inmo/tgbotapi/extensions/utils/ClassCastsNewKt {
|
||||
public static final fun paidMediaPurchasedOrThrow (Ldev/inmo/tgbotapi/abstracts/OptionallyWithUser;)Ldev/inmo/tgbotapi/types/message/payments/PaidMediaPurchased;
|
||||
public static final fun paidMediaPurchasedUpdateOrNull (Ldev/inmo/tgbotapi/types/update/abstracts/Update;)Ldev/inmo/tgbotapi/types/update/PaidMediaPurchasedUpdate;
|
||||
public static final fun paidMediaPurchasedUpdateOrThrow (Ldev/inmo/tgbotapi/types/update/abstracts/Update;)Ldev/inmo/tgbotapi/types/update/PaidMediaPurchasedUpdate;
|
||||
public static final fun paidMessagePriceChangedOrNull (Ldev/inmo/tgbotapi/types/message/ChatEvents/abstracts/ChatEvent;)Ldev/inmo/tgbotapi/types/PaidMessagePriceChanged;
|
||||
public static final fun paidMessagePriceChangedOrThrow (Ldev/inmo/tgbotapi/types/message/ChatEvents/abstracts/ChatEvent;)Ldev/inmo/tgbotapi/types/PaidMessagePriceChanged;
|
||||
public static final fun paidOrNull (Ldev/inmo/tgbotapi/types/reactions/Reaction;)Ldev/inmo/tgbotapi/types/reactions/Reaction$Paid;
|
||||
public static final fun paidOrThrow (Ldev/inmo/tgbotapi/types/reactions/Reaction;)Ldev/inmo/tgbotapi/types/reactions/Reaction$Paid;
|
||||
public static final fun passportElementErrorDataFieldOrNull (Ldev/inmo/tgbotapi/types/passport/PassportElementError;)Ldev/inmo/tgbotapi/types/passport/PassportElementErrorDataField;
|
||||
@@ -2304,6 +2308,8 @@ public final class dev/inmo/tgbotapi/extensions/utils/ClassCastsNewKt {
|
||||
public static final fun possiblyMediaGroupMessageOrThrow (Ldev/inmo/tgbotapi/types/message/abstracts/Message;)Ldev/inmo/tgbotapi/types/message/abstracts/PossiblyMediaGroupMessage;
|
||||
public static final fun possiblyOfflineMessageOrNull (Ldev/inmo/tgbotapi/types/message/abstracts/Message;)Ldev/inmo/tgbotapi/types/message/abstracts/PossiblyOfflineMessage;
|
||||
public static final fun possiblyOfflineMessageOrThrow (Ldev/inmo/tgbotapi/types/message/abstracts/Message;)Ldev/inmo/tgbotapi/types/message/abstracts/PossiblyOfflineMessage;
|
||||
public static final fun possiblyPaidMessageOrNull (Ldev/inmo/tgbotapi/types/message/abstracts/Message;)Ldev/inmo/tgbotapi/types/message/abstracts/PossiblyPaidMessage;
|
||||
public static final fun possiblyPaidMessageOrThrow (Ldev/inmo/tgbotapi/types/message/abstracts/Message;)Ldev/inmo/tgbotapi/types/message/abstracts/PossiblyPaidMessage;
|
||||
public static final fun possiblyPaymentMessageOrNull (Ldev/inmo/tgbotapi/types/message/abstracts/Message;)Ldev/inmo/tgbotapi/types/message/abstracts/PossiblyPaymentMessage;
|
||||
public static final fun possiblyPaymentMessageOrThrow (Ldev/inmo/tgbotapi/types/message/abstracts/Message;)Ldev/inmo/tgbotapi/types/message/abstracts/PossiblyPaymentMessage;
|
||||
public static final fun possiblyPremiumChatOrNull (Ldev/inmo/tgbotapi/types/chat/Chat;)Ldev/inmo/tgbotapi/types/chat/PossiblyPremiumChat;
|
||||
|
@@ -80,6 +80,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent.InputVenueMessa
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery
|
||||
import dev.inmo.tgbotapi.types.PaidMessagePriceChanged
|
||||
import dev.inmo.tgbotapi.types.PrimaryInviteLink
|
||||
import dev.inmo.tgbotapi.types.ReplyInfo
|
||||
import dev.inmo.tgbotapi.types.SecondaryChatInviteLink
|
||||
@@ -308,6 +309,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.PossiblyEditedMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyForwardedMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyOfflineMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyPaidMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyPaymentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.PossiblySentViaBotCommonMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyTopicMessage
|
||||
@@ -3292,6 +3294,15 @@ public inline fun <T>
|
||||
TelegramMedia.ifWithCustomizableCaptionTelegramMedia(block: (WithCustomizableCaptionTelegramMedia) -> T):
|
||||
T? = withCustomizableCaptionTelegramMediaOrNull() ?.let(block)
|
||||
|
||||
public inline fun ChatEvent.paidMessagePriceChangedOrNull(): PaidMessagePriceChanged? = this as?
|
||||
dev.inmo.tgbotapi.types.PaidMessagePriceChanged
|
||||
|
||||
public inline fun ChatEvent.paidMessagePriceChangedOrThrow(): PaidMessagePriceChanged = this as
|
||||
dev.inmo.tgbotapi.types.PaidMessagePriceChanged
|
||||
|
||||
public inline fun <T> ChatEvent.ifPaidMessagePriceChanged(block: (PaidMessagePriceChanged) -> T): T?
|
||||
= paidMessagePriceChangedOrNull() ?.let(block)
|
||||
|
||||
public inline fun ChatEvent.chatBackgroundOrNull(): ChatBackground? = this as?
|
||||
dev.inmo.tgbotapi.types.chat.ChatBackground
|
||||
|
||||
@@ -4058,6 +4069,15 @@ public inline fun Message.possiblyOfflineMessageOrThrow(): PossiblyOfflineMessag
|
||||
public inline fun <T> Message.ifPossiblyOfflineMessage(block: (PossiblyOfflineMessage) -> T): T? =
|
||||
possiblyOfflineMessageOrNull() ?.let(block)
|
||||
|
||||
public inline fun Message.possiblyPaidMessageOrNull(): PossiblyPaidMessage? = this as?
|
||||
dev.inmo.tgbotapi.types.message.abstracts.PossiblyPaidMessage
|
||||
|
||||
public inline fun Message.possiblyPaidMessageOrThrow(): PossiblyPaidMessage = this as
|
||||
dev.inmo.tgbotapi.types.message.abstracts.PossiblyPaidMessage
|
||||
|
||||
public inline fun <T> Message.ifPossiblyPaidMessage(block: (PossiblyPaidMessage) -> T): T? =
|
||||
possiblyPaidMessageOrNull() ?.let(block)
|
||||
|
||||
public inline fun Message.possiblyPaymentMessageOrNull(): PossiblyPaymentMessage? = this as?
|
||||
dev.inmo.tgbotapi.types.message.abstracts.PossiblyPaymentMessage
|
||||
|
||||
|
@@ -12,6 +12,8 @@ import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo
|
||||
import dev.inmo.tgbotapi.webapps.location.LocationManager
|
||||
import dev.inmo.tgbotapi.webapps.orientation.DeviceOrientation
|
||||
import dev.inmo.tgbotapi.webapps.popup.*
|
||||
import dev.inmo.tgbotapi.webapps.storage.DeviceStorage
|
||||
import dev.inmo.tgbotapi.webapps.storage.SecureStorage
|
||||
import dev.inmo.tgbotapi.webapps.stories.StoryShareParams
|
||||
|
||||
external class WebApp {
|
||||
@@ -104,6 +106,13 @@ external class WebApp {
|
||||
@JsName("SettingsButton")
|
||||
val settingsButton: SettingsButton
|
||||
|
||||
@JsName("DeviceStorage")
|
||||
val deviceStorage: DeviceStorage
|
||||
|
||||
@JsName("SecureStorage")
|
||||
val secureStorage: SecureStorage
|
||||
|
||||
|
||||
internal fun onEvent(type: String, callback: () -> Unit)
|
||||
|
||||
fun offEvent(type: String, callback: () -> Unit)
|
||||
|
@@ -0,0 +1,167 @@
|
||||
package dev.inmo.tgbotapi.webapps.storage
|
||||
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.Deferred
|
||||
|
||||
/**
|
||||
* This object is used to access the device's local storage.
|
||||
*
|
||||
* See [https://core.telegram.org/bots/webapps#devicestorage](https://core.telegram.org/bots/webapps#devicestorage) for more information.
|
||||
*/
|
||||
external interface DeviceStorage {
|
||||
/**
|
||||
* Stores a key-value pair.
|
||||
*
|
||||
* @param key The key to store the value under.
|
||||
* @param value The value to store.
|
||||
* @param callback A callback function that is called when the operation is complete. The first argument is an error object, if any, and the second argument is a boolean indicating whether the operation was successful.
|
||||
*/
|
||||
fun setItem(key: String, value: String, callback: (Throwable?, Boolean?) -> Unit): DeviceStorage
|
||||
|
||||
/**
|
||||
* Retrieves the value associated with a key.
|
||||
*
|
||||
* @param key The key to retrieve the value for.
|
||||
* @param callback A callback function that is called when the operation is complete. The first argument is an error object, if any, and the second argument is the value associated with the key, or null if the key is not found.
|
||||
*/
|
||||
fun getItem(key: String, callback: (Throwable?, String?) -> Unit): DeviceStorage
|
||||
|
||||
/**
|
||||
* Removes the key-value pair associated with a key.
|
||||
*
|
||||
* @param key The key to remove.
|
||||
* @param callback A callback function that is called when the operation is complete. The first argument is an error object, if any, and the second argument is a boolean indicating whether the operation was successful.
|
||||
*/
|
||||
fun removeItem(key: String, callback: (Throwable?, Boolean?) -> Unit): DeviceStorage
|
||||
|
||||
/**
|
||||
* Clears all key-value pairs from the storage.
|
||||
*
|
||||
* @param callback A callback function that is called when the operation is complete. The first argument is an error object, if any, and the second argument is a boolean indicating whether the operation was successful.
|
||||
*/
|
||||
fun clear(callback: (Throwable?, Boolean?) -> Unit): DeviceStorage
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a key-value pair. This function uses a [CompletableDeferred] to handle the asynchronous callback and returns a [Result] object.
|
||||
*
|
||||
* @param key The key to store the value under.
|
||||
* @param value The value to store.
|
||||
* @return A [Result] object containing the result of the operation.
|
||||
*/
|
||||
suspend fun DeviceStorage.setWithResult(key: String, value: String): Result<Boolean> {
|
||||
val deferred = CompletableDeferred<Result<Boolean>>()
|
||||
|
||||
setItem(key, value) { error, result ->
|
||||
if (error == null) {
|
||||
deferred.complete(Result.success(result ?: false))
|
||||
} else {
|
||||
deferred.complete(Result.failure(error))
|
||||
}
|
||||
}
|
||||
|
||||
return deferred.await()
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the value associated with a key. This function uses a [CompletableDeferred] to handle the asynchronous callback and returns a [Result] object.
|
||||
*
|
||||
* @param key The key to retrieve the value for.
|
||||
* @return A [Result] object containing the result of the operation.
|
||||
*/
|
||||
suspend fun DeviceStorage.getWithResult(key: String): Result<String?> {
|
||||
val deferred = CompletableDeferred<Result<String?>>()
|
||||
|
||||
getItem(key) { error, result ->
|
||||
if (error == null) {
|
||||
deferred.complete(Result.success(result))
|
||||
} else {
|
||||
deferred.complete(Result.failure(error))
|
||||
}
|
||||
}
|
||||
|
||||
return deferred.await()
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the key-value pair associated with a key. This function uses a [CompletableDeferred] to handle the asynchronous callback and returns a [Result] object.
|
||||
*
|
||||
* @param key The key to remove.
|
||||
* @return A [Result] object containing the result of the operation.
|
||||
*/
|
||||
suspend fun DeviceStorage.removeWithResult(key: String): Result<Boolean> {
|
||||
val deferred = CompletableDeferred<Result<Boolean>>()
|
||||
|
||||
removeItem(key) { error, result ->
|
||||
if (error == null) {
|
||||
deferred.complete(Result.success(result ?: false))
|
||||
} else {
|
||||
deferred.complete(Result.failure(error))
|
||||
}
|
||||
}
|
||||
|
||||
return deferred.await()
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all key-value pairs from the storage. This function uses a [CompletableDeferred] to handle the asynchronous callback and returns a [Result] object.
|
||||
*
|
||||
* @return A [Result] object containing the result of the operation.
|
||||
*/
|
||||
suspend fun DeviceStorage.clearWithResult(): Result<Boolean> {
|
||||
val deferred = CompletableDeferred<Result<Boolean>>()
|
||||
|
||||
clear { error, result ->
|
||||
if (error == null) {
|
||||
deferred.complete(Result.success(result ?: false))
|
||||
} else {
|
||||
deferred.complete(Result.failure(error))
|
||||
}
|
||||
}
|
||||
|
||||
return deferred.await()
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a key-value pair. This function suspends until the result is available and returns the result directly or throws an exception if an error occurred.
|
||||
*
|
||||
* @param key The key to store the value under.
|
||||
* @param value The value to store.
|
||||
* @return Boolean indicating whether the operation was successful.
|
||||
* @throws Throwable If an error occurs during the operation.
|
||||
*/
|
||||
suspend fun DeviceStorage.setItem(key: String, value: String): Boolean {
|
||||
return setWithResult(key, value).getOrThrow()
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the value associated with a key. This function suspends until the result is available and returns the result directly or throws an exception if an error occurred.
|
||||
*
|
||||
* @param key The key to retrieve the value for.
|
||||
* @return The value associated with the key, or null if the key is not found.
|
||||
* @throws Throwable If an error occurs during the operation.
|
||||
*/
|
||||
suspend fun DeviceStorage.getItem(key: String): String? {
|
||||
return getWithResult(key).getOrThrow()
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the key-value pair associated with a key. This function suspends until the result is available and returns the result directly or throws an exception if an error occurred.
|
||||
*
|
||||
* @param key The key to remove.
|
||||
* @return Boolean indicating whether the operation was successful.
|
||||
* @throws Throwable If an error occurs during the operation.
|
||||
*/
|
||||
suspend fun DeviceStorage.removeItem(key: String): Boolean {
|
||||
return removeWithResult(key).getOrThrow()
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all key-value pairs from the storage. This function suspends until the result is available and returns the result directly or throws an exception if an error occurred.
|
||||
*
|
||||
* @return Boolean indicating whether the operation was successful.
|
||||
* @throws Throwable If an error occurs during the operation.
|
||||
*/
|
||||
suspend fun DeviceStorage.clear(): Boolean {
|
||||
return clearWithResult().getOrThrow()
|
||||
}
|
@@ -0,0 +1,231 @@
|
||||
package dev.inmo.tgbotapi.webapps.storage
|
||||
|
||||
import dev.inmo.micro_utils.common.Either
|
||||
import dev.inmo.micro_utils.common.either
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
|
||||
/**
|
||||
* This class provides access to the secure local storage, which is persistent and
|
||||
* tied to the user's Telegram account. Data stored in secure storage is accessible
|
||||
* only to the Web App that saved it.
|
||||
*
|
||||
* Use this storage to save sensitive data like access tokens or user preferences
|
||||
* that should persist across sessions. Keep in mind that storage size is limited
|
||||
* to 2 kilobytes.
|
||||
*
|
||||
* For non-sensitive data, consider using [DeviceStorage].
|
||||
*
|
||||
* @see [https://core.telegram.org/bots/webapps#securestorage](https://core.telegram.org/bots/webapps#securestorage)
|
||||
*/
|
||||
external class SecureStorage {
|
||||
/**
|
||||
* Stores a key-value pair in secure storage.
|
||||
*
|
||||
* @param key The key to store the value under.
|
||||
* @param value The value to store.
|
||||
* @param callback A callback function that is called when the operation is complete.
|
||||
* The first argument is an error object, if any, and the second argument is a boolean
|
||||
* indicating whether the operation was successful.
|
||||
*/
|
||||
fun setItem(key: String, value: String, callback: (error: Throwable?, isSuccessful: Boolean) -> Unit)
|
||||
|
||||
/**
|
||||
* Retrieves the value associated with a key from secure storage.
|
||||
*
|
||||
* @param key The key to retrieve the value for.
|
||||
* @param callback A callback function that is called when the operation is complete.
|
||||
* The first argument is an error object, if any, the second argument is the value
|
||||
* associated with the key, or null if the key is not found, and the third argument
|
||||
* indicates whether the value can be restored.
|
||||
*/
|
||||
fun getItem(key: String, callback: (error: Throwable?, value: String?, canBeRestored: Boolean?) -> Unit)
|
||||
|
||||
/**
|
||||
* Restores the value associated with a key in secure storage. This is useful if the
|
||||
* value was previously removed using [removeItem] and needs to be retrieved again.
|
||||
* Note that restoring a value is only possible if it hasn't been overwritten
|
||||
* by a new value for the same key.
|
||||
*
|
||||
* @param key The key to restore the value for.
|
||||
* @param callback A callback function that is called when the operation is complete.
|
||||
* The first argument is an error object, if any, and the second argument is the restored
|
||||
* value, or null if the key is not found or cannot be restored.
|
||||
*/
|
||||
fun restoreItem(key: String, callback: (error: Throwable?, value: String?) -> Unit)
|
||||
|
||||
/**
|
||||
* Removes the key-value pair associated with a key from secure storage.
|
||||
*
|
||||
* @param key The key to remove.
|
||||
* @param callback A callback function that is called when the operation is complete.
|
||||
* The first argument is an error object, if any, and the second argument is a boolean
|
||||
* indicating whether the operation was successful.
|
||||
*/
|
||||
fun removeItem(key: String, callback: (error: Throwable?, isSuccessful: Boolean) -> Unit)
|
||||
|
||||
/**
|
||||
* Clears all key-value pairs from the secure storage.
|
||||
*
|
||||
* @param callback A callback function that is called when the operation is complete.
|
||||
* The first argument is an error object, if any, and the second argument is a boolean
|
||||
* indicating whether the operation was successful.
|
||||
*/
|
||||
fun clear(callback: (error: Throwable?, isSuccessful: Boolean) -> Unit)
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a key-value pair in secure storage using a [CompletableDeferred] and returns a [Result].
|
||||
*
|
||||
* @param key The key to store the value under.
|
||||
* @param value The value to store.
|
||||
* @return A [Result] object containing the result of the operation.
|
||||
*/
|
||||
suspend fun SecureStorage.setWithResult(key: String, value: String): Result<Boolean> {
|
||||
val deferred = CompletableDeferred<Result<Boolean>>()
|
||||
setItem(key, value) { error, isSuccessful ->
|
||||
if (error == null) {
|
||||
deferred.complete(Result.success(isSuccessful))
|
||||
} else {
|
||||
deferred.complete(Result.failure(error))
|
||||
}
|
||||
}
|
||||
return deferred.await()
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the value associated with a key from secure storage using a [CompletableDeferred] and returns a [Result].
|
||||
* This suspending function encapsulates the asynchronous operation of retrieving a value
|
||||
* and provides a structured way to handle both successful retrieval and potential errors.
|
||||
* It uses a [CompletableDeferred] to manage the asynchronous result.
|
||||
*
|
||||
* @param key The key to retrieve the value for.
|
||||
* @return A [Result] object containing the retrieved value (which can be null if the key is not found)
|
||||
* or a [Throwable] representing the error that occurred.
|
||||
*/
|
||||
suspend fun SecureStorage.getWithResult(key: String): Result<Either<String?, Boolean>> {
|
||||
val deferred = CompletableDeferred<Result<Either<String?, Boolean>>>()
|
||||
getItem(key) { error, value, canBeRestored ->
|
||||
when {
|
||||
error != null -> deferred.complete(Result.failure(error))
|
||||
value != null -> deferred.complete(Result.success(value.either()))
|
||||
else -> deferred.complete(Result.success((canBeRestored == true).either()))
|
||||
}
|
||||
}
|
||||
return deferred.await()
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the value associated with a key in secure storage using a [CompletableDeferred] and returns a [Result].
|
||||
*
|
||||
* @param key The key to restore the value for.
|
||||
* @return A [Result] object containing the result of the operation.
|
||||
*/
|
||||
suspend fun SecureStorage.restoreWithResult(key: String): Result<String?> {
|
||||
val deferred = CompletableDeferred<Result<String?>>()
|
||||
restoreItem(key) { error, value ->
|
||||
if (error == null) {
|
||||
deferred.complete(Result.success(value))
|
||||
} else {
|
||||
deferred.complete(Result.failure(error))
|
||||
}
|
||||
}
|
||||
return deferred.await()
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the key-value pair associated with a key from secure storage using a [CompletableDeferred] and returns a [Result].
|
||||
*
|
||||
* @param key The key to remove.
|
||||
* @return A [Result] object containing the result of the operation.
|
||||
*/
|
||||
suspend fun SecureStorage.removeWithResult(key: String): Result<Boolean> {
|
||||
val deferred = CompletableDeferred<Result<Boolean>>()
|
||||
removeItem(key) { error, isSuccessful ->
|
||||
if (error == null) {
|
||||
deferred.complete(Result.success(isSuccessful))
|
||||
} else {
|
||||
deferred.complete(Result.failure(error))
|
||||
}
|
||||
}
|
||||
return deferred.await()
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all key-value pairs from the secure storage using a [CompletableDeferred] and returns a [Result].
|
||||
*
|
||||
* @return A [Result] object containing the result of the operation.
|
||||
*/
|
||||
suspend fun SecureStorage.clearWithResult(): Result<Boolean> {
|
||||
val deferred = CompletableDeferred<Result<Boolean>>()
|
||||
clear { error, isSuccessful ->
|
||||
if (error == null) {
|
||||
deferred.complete(Result.success(isSuccessful))
|
||||
} else {
|
||||
deferred.complete(Result.failure(error))
|
||||
}
|
||||
}
|
||||
return deferred.await()
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores a key-value pair in secure storage. This suspending function handles the result directly
|
||||
* and throws an exception if an error occurs.
|
||||
*
|
||||
* @param key The key to store the value under.
|
||||
* @param value The value to store.
|
||||
* @return True if the operation was successful.
|
||||
* @throws Throwable If an error occurs during the operation.
|
||||
*/
|
||||
suspend fun SecureStorage.setItem(key: String, value: String): Boolean {
|
||||
return setWithResult(key, value).getOrThrow()
|
||||
}
|
||||
/**
|
||||
* Retrieves the value associated with a key from secure storage. This function uses a callback-based approach
|
||||
* for handling the asynchronous result of the operation.
|
||||
*
|
||||
* @param key The key to retrieve the value for.
|
||||
* @param callback A callback function that is called when the operation is complete.
|
||||
* The first argument is an error object (a [Throwable] if an error occurred, or null otherwise),
|
||||
* the second argument is the retrieved value (a [String] or null if the key is not found),
|
||||
* and the third argument is a boolean indicating whether the value can be restored
|
||||
* (useful if the value was previously removed and might be restorable).
|
||||
*/
|
||||
|
||||
suspend fun SecureStorage.getItem(key: String): Either<String?, Boolean> {
|
||||
return getWithResult(key).getOrThrow()
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the value associated with a key in secure storage. This suspending function handles
|
||||
* the result directly and throws an exception if an error occurs.
|
||||
*
|
||||
* @param key The key to restore the value for.
|
||||
* @return The restored value, or null if the key is not found or cannot be restored.
|
||||
* @throws Throwable If an error occurs during the operation.
|
||||
*/
|
||||
suspend fun SecureStorage.restoreItem(key: String): String? {
|
||||
return restoreWithResult(key).getOrThrow()
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the key-value pair associated with a key from secure storage.
|
||||
* This suspending function handles the result directly and throws an exception if an error occurs.
|
||||
*
|
||||
* @param key The key to remove.
|
||||
* @return True if the operation was successful.
|
||||
* @throws Throwable If an error occurs during the operation.
|
||||
*/
|
||||
suspend fun SecureStorage.removeItem(key: String): Boolean {
|
||||
return removeWithResult(key).getOrThrow()
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all key-value pairs from secure storage. This suspending function handles the result
|
||||
* directly and throws an exception if an error occurs.
|
||||
*
|
||||
* @return True if the operation was successful.
|
||||
* @throws Throwable If an error occurs during the operation.
|
||||
*/
|
||||
suspend fun SecureStorage.clear(): Boolean {
|
||||
return clearWithResult().getOrThrow()
|
||||
}
|
Reference in New Issue
Block a user