mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-15 13:19:30 +00:00
add paid media payload support
This commit is contained in:
@@ -28,6 +28,7 @@ fun SendPaidMedia(
|
||||
media: List<TelegramPaidMedia>,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
payload: PaidMediaPayload? = null,
|
||||
showCaptionAboveMedia: Boolean = false,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@@ -40,6 +41,7 @@ fun SendPaidMedia(
|
||||
chatId = chatId,
|
||||
starCount = starCount,
|
||||
media = media,
|
||||
payload = payload,
|
||||
text = text,
|
||||
parseMode = parseMode,
|
||||
rawEntities = null,
|
||||
@@ -78,6 +80,7 @@ fun SendPaidMedia(
|
||||
starCount: Int,
|
||||
media: List<TelegramPaidMedia>,
|
||||
entities: TextSourcesList,
|
||||
payload: PaidMediaPayload? = null,
|
||||
showCaptionAboveMedia: Boolean = false,
|
||||
threadId: MessageThreadId? = chatId.threadId,
|
||||
businessConnectionId: BusinessConnectionId? = chatId.businessConnectionId,
|
||||
@@ -90,6 +93,7 @@ fun SendPaidMedia(
|
||||
chatId = chatId,
|
||||
starCount = starCount,
|
||||
media = media,
|
||||
payload = payload,
|
||||
text = entities.makeString(),
|
||||
parseMode = null,
|
||||
rawEntities = entities.toRawMessageEntities(),
|
||||
@@ -140,6 +144,8 @@ data class SendPaidMediaData internal constructor(
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(captionEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@SerialName(payloadField)
|
||||
val payload: PaidMediaPayload? = null,
|
||||
@SerialName(showCaptionAboveMediaField)
|
||||
override val showCaptionAboveMedia: Boolean = false,
|
||||
@SerialName(messageThreadIdField)
|
||||
|
@@ -2,6 +2,8 @@ package dev.inmo.tgbotapi.types
|
||||
|
||||
import dev.inmo.tgbotapi.types.location.LiveLocation
|
||||
import dev.inmo.tgbotapi.utils.BuiltinMimeTypes
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.jvm.JvmInline
|
||||
|
||||
typealias ForwardSignature = String
|
||||
typealias ForwardSenderName = String
|
||||
@@ -24,6 +26,14 @@ typealias UnixTimeStamp = LongSeconds
|
||||
typealias Meters = Float
|
||||
typealias Degrees = Int
|
||||
|
||||
@Serializable
|
||||
@JvmInline
|
||||
value class PaidMediaPayload(val string: String) {
|
||||
override fun toString(): String {
|
||||
return string
|
||||
}
|
||||
}
|
||||
|
||||
val usernameRegex = Regex("@[\\w\\d_]+")
|
||||
|
||||
val degreesLimit = 1 .. 360
|
||||
@@ -490,6 +500,7 @@ const val currencyField = "currency"
|
||||
const val startParameterField = "start_parameter"
|
||||
const val totalAmountField = "total_amount"
|
||||
const val invoicePayloadField = "invoice_payload"
|
||||
const val paidMediaPayloadField = "paid_media_payload"
|
||||
const val shippingOptionIdField = "shipping_option_id"
|
||||
const val shippingQueryIdField = "shipping_query_id"
|
||||
const val preCheckoutQueryIdField = "pre_checkout_query_id"
|
||||
|
@@ -33,9 +33,9 @@ data class PaidMediaInfoContent(
|
||||
replyParameters: ReplyParameters?,
|
||||
replyMarkup: KeyboardMarkup?
|
||||
): Request<ContentMessage<PaidMediaInfoContent>> = SendPaidMedia(
|
||||
chatId,
|
||||
paidMediaInfo.stars,
|
||||
paidMediaInfo.media.mapNotNull {
|
||||
chatId = chatId,
|
||||
starCount = paidMediaInfo.stars,
|
||||
media = paidMediaInfo.media.mapNotNull {
|
||||
when (it) {
|
||||
is PaidMedia.Photo -> it.photo.biggest.toTelegramPaidMediaPhoto()
|
||||
is PaidMedia.Preview -> null
|
||||
@@ -45,9 +45,13 @@ data class PaidMediaInfoContent(
|
||||
}.ifEmpty {
|
||||
error("Unable to create resend for paid media content without any revealed content")
|
||||
},
|
||||
textSources,
|
||||
showCaptionAboveMedia,
|
||||
messageThreadId,
|
||||
businessConnectionId, disableNotification, protectContent, replyParameters, replyMarkup
|
||||
entities = textSources,
|
||||
showCaptionAboveMedia = showCaptionAboveMedia,
|
||||
threadId = messageThreadId,
|
||||
businessConnectionId = businessConnectionId,
|
||||
disableNotification = disableNotification,
|
||||
protectContent = protectContent,
|
||||
replyParameters = replyParameters,
|
||||
replyMarkup = replyMarkup
|
||||
)
|
||||
}
|
||||
|
@@ -0,0 +1,17 @@
|
||||
package dev.inmo.tgbotapi.types.message.payments
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.FromUser
|
||||
import dev.inmo.tgbotapi.types.PaidMediaPayload
|
||||
import dev.inmo.tgbotapi.types.chat.User
|
||||
import dev.inmo.tgbotapi.types.fromField
|
||||
import dev.inmo.tgbotapi.types.paidMediaPayloadField
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PaidMediaPurchased(
|
||||
@SerialName(fromField)
|
||||
override val from: User,
|
||||
@SerialName(paidMediaPayloadField)
|
||||
val payload: PaidMediaPayload
|
||||
) : FromUser
|
@@ -43,7 +43,9 @@ sealed interface TransactionPartner {
|
||||
@SerialName(invoicePayloadField)
|
||||
val invoicePayload: InvoicePayload? = null,
|
||||
@SerialName(paidMediaField)
|
||||
val paidMedia: List<PaidMedia>? = null
|
||||
val paidMedia: List<PaidMedia>? = null,
|
||||
@SerialName(paidMediaPayloadField)
|
||||
val paidMediaPayload: PaidMediaPayload? = null
|
||||
) : TransactionPartner {
|
||||
@EncodeDefault
|
||||
override val type: String = Companion.type
|
||||
|
@@ -0,0 +1,12 @@
|
||||
package dev.inmo.tgbotapi.types.update
|
||||
|
||||
import dev.inmo.tgbotapi.types.UpdateId
|
||||
import dev.inmo.tgbotapi.types.message.payments.PaidMediaPurchased
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class PaidMediaPurchasedUpdate(
|
||||
override val updateId: UpdateId,
|
||||
override val data: PaidMediaPurchased
|
||||
) : Update
|
@@ -13,6 +13,7 @@ import dev.inmo.tgbotapi.types.chat.ChatMessageReactionUpdated
|
||||
import dev.inmo.tgbotapi.types.chat.ChatMessageReactionsCountUpdated
|
||||
import dev.inmo.tgbotapi.types.chat.member.ChatMemberUpdated
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.payments.PaidMediaPurchased
|
||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||
import dev.inmo.tgbotapi.types.polls.Poll
|
||||
@@ -56,6 +57,7 @@ internal data class RawUpdate constructor(
|
||||
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
|
||||
private val edited_business_message: BusinessContentMessage<*>? = null,
|
||||
private val deleted_business_messages: BusinessMessagesDeleted? = null,
|
||||
private val purchased_paid_media: PaidMediaPurchased? = null,
|
||||
) {
|
||||
@Transient
|
||||
private var initedUpdate: Update? = null
|
||||
@@ -91,6 +93,7 @@ internal data class RawUpdate constructor(
|
||||
business_message != null -> BusinessMessageUpdate(updateId, business_message)
|
||||
edited_business_message != null -> EditBusinessMessageUpdate(updateId, edited_business_message)
|
||||
deleted_business_messages != null -> DeletedBusinessMessageUpdate(updateId, deleted_business_messages)
|
||||
purchased_paid_media != null -> PaidMediaPurchasedUpdate(updateId, purchased_paid_media)
|
||||
else -> UnknownUpdate(
|
||||
updateId,
|
||||
raw
|
||||
|
@@ -44,6 +44,7 @@ interface FlowsUpdatesFilter : UpdatesFilter {
|
||||
val businessMessageUpdatesFlow: Flow<BusinessMessageUpdate>
|
||||
val editBusinessMessageUpdatesFlow: Flow<EditBusinessMessageUpdate>
|
||||
val deleteBusinessMessageUpdatesFlow: Flow<DeletedBusinessMessageUpdate>
|
||||
val paidMediaPurchasedUpdatesFlow: Flow<PaidMediaPurchasedUpdate>
|
||||
val unknownUpdatesFlow: Flow<UnknownUpdate>
|
||||
}
|
||||
|
||||
@@ -71,6 +72,7 @@ abstract class AbstractFlowsUpdatesFilter : FlowsUpdatesFilter {
|
||||
override val businessMessageUpdatesFlow: Flow<BusinessMessageUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
||||
override val editBusinessMessageUpdatesFlow: Flow<EditBusinessMessageUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
||||
override val deleteBusinessMessageUpdatesFlow: Flow<DeletedBusinessMessageUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
||||
override val paidMediaPurchasedUpdatesFlow: Flow<PaidMediaPurchasedUpdate> by lazy { allUpdatesFlow.filterIsInstance() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user