mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-30 11:25:44 +00:00
add support for sending of gifts to chats
This commit is contained in:
@@ -19,11 +19,13 @@ import kotlinx.serialization.builtins.serializer
|
||||
@Serializable
|
||||
data class SendGift internal constructor(
|
||||
@SerialName(userIdField)
|
||||
val userId: UserId,
|
||||
val userId: UserId? = null,
|
||||
@SerialName(chatIdField)
|
||||
val chatId: ChatIdentifier? = null,
|
||||
@SerialName(giftIdField)
|
||||
val giftId: GiftId,
|
||||
@SerialName(textField)
|
||||
override val text: String,
|
||||
override val text: String? = null,
|
||||
@SerialName(textParseModeField)
|
||||
override val parseMode: ParseMode?,
|
||||
@SerialName(textEntitiesField)
|
||||
@@ -32,7 +34,11 @@ data class SendGift internal constructor(
|
||||
val upgradableToUnique: Boolean = false
|
||||
) : SimpleRequest<Boolean>, TextedOutput {
|
||||
override val textSources: TextSourcesList? by lazy {
|
||||
rawEntities ?.asTextSources(text)
|
||||
rawEntities ?.let {
|
||||
text ?.let { _ ->
|
||||
it.asTextSources(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = "sendGift"
|
||||
@@ -44,6 +50,7 @@ data class SendGift internal constructor(
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = Boolean.serializer()
|
||||
|
||||
@Deprecated("Use factory function `toUser` instead", ReplaceWith("toUser(userId, giftId, text, parseMode, upgradableToUnique)"))
|
||||
constructor(
|
||||
userId: UserId,
|
||||
giftId: GiftId,
|
||||
@@ -59,17 +66,75 @@ data class SendGift internal constructor(
|
||||
upgradableToUnique = upgradableToUnique
|
||||
)
|
||||
|
||||
@Deprecated("Use factory function `toUser` instead", ReplaceWith("toUser(userId, giftId, textSources, upgradableToUnique)"))
|
||||
constructor(
|
||||
userId: UserId,
|
||||
giftId: GiftId,
|
||||
textSources: TextSourcesList,
|
||||
textSources: TextSourcesList? = null,
|
||||
upgradableToUnique: Boolean = false,
|
||||
) : this(
|
||||
userId = userId,
|
||||
giftId = giftId,
|
||||
text = textSources.makeSourceString(),
|
||||
text = textSources ?.makeSourceString(),
|
||||
parseMode = null,
|
||||
rawEntities = textSources.toRawMessageEntities(),
|
||||
rawEntities = textSources ?.toRawMessageEntities(),
|
||||
upgradableToUnique = upgradableToUnique
|
||||
)
|
||||
|
||||
companion object {
|
||||
fun toUser(
|
||||
userId: UserId,
|
||||
giftId: GiftId,
|
||||
text: String,
|
||||
parseMode: ParseMode?,
|
||||
upgradableToUnique: Boolean = false
|
||||
) = SendGift(
|
||||
userId = userId,
|
||||
giftId = giftId,
|
||||
text = text,
|
||||
parseMode = parseMode,
|
||||
rawEntities = null,
|
||||
upgradableToUnique = upgradableToUnique
|
||||
)
|
||||
fun toUser(
|
||||
userId: UserId,
|
||||
giftId: GiftId,
|
||||
textSources: TextSourcesList? = null,
|
||||
upgradableToUnique: Boolean = false,
|
||||
) = SendGift(
|
||||
userId = userId,
|
||||
giftId = giftId,
|
||||
text = textSources ?.makeSourceString(),
|
||||
parseMode = null,
|
||||
rawEntities = textSources ?.toRawMessageEntities(),
|
||||
upgradableToUnique = upgradableToUnique
|
||||
)
|
||||
fun toChat(
|
||||
chatId: ChatIdentifier,
|
||||
giftId: GiftId,
|
||||
text: String,
|
||||
parseMode: ParseMode?,
|
||||
upgradableToUnique: Boolean = false
|
||||
) = SendGift(
|
||||
chatId = chatId,
|
||||
giftId = giftId,
|
||||
text = text,
|
||||
parseMode = parseMode,
|
||||
rawEntities = null,
|
||||
upgradableToUnique = upgradableToUnique
|
||||
)
|
||||
fun toChat(
|
||||
chatId: ChatIdentifier,
|
||||
giftId: GiftId,
|
||||
textSources: TextSourcesList? = null,
|
||||
upgradableToUnique: Boolean = false,
|
||||
) = SendGift(
|
||||
chatId = chatId,
|
||||
giftId = giftId,
|
||||
text = textSources ?.makeSourceString(),
|
||||
parseMode = null,
|
||||
rawEntities = textSources ?.toRawMessageEntities(),
|
||||
upgradableToUnique = upgradableToUnique
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user