1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-02 15:00:06 +00:00

Compare commits

..

No commits in common. "c2cc6ee1ec87c2f1232335b5612aed60fdd07d08" and "e74f339ae255bf8fa3252ee4277aba38686ac399" have entirely different histories.

32 changed files with 40 additions and 475 deletions

View File

@ -1,15 +1,5 @@
# TelegramBotAPI changelog
## 2.1.0
__This update contains including of [Telegram Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022)__
* Add support of functionality for `WebApp`s from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022)
* Add support of functionality for premium feature from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022)
* Add support of `addedToAttachmentMenu` in `CommonUser` from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022)
* Add support of `secret_token` in `SetWebhook` request from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022)
* Add support of `createInvoiceLink` request from [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022)
## 2.0.3
* `Core`:

View File

@ -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.1-blue)](https://core.telegram.org/bots/api-changelog#june-20-2022)
# 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.0-blue)](https://core.telegram.org/bots/api-changelog#april-16-2022)
| [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://github.com/InsanusMokrassar/TelegramBotAPI/workflows/Build/badge.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [![Small survey](https://img.shields.io/static/v1?label=Google&message=Survey&color=blue&logo=google-sheets)](https://docs.google.com/forms/d/e/1FAIpQLSctdJHT_aEniyYT0-IUAEfo1hsIlezX2owlkEAYX4KPl2V2_A/viewform?usp=sf_link) [![Chat in Telegram](https://img.shields.io/static/v1?label=Telegram&message=Chat&color=blue&logo=telegram)](https://t.me/InMoTelegramBotAPI) |
|:---:|

View File

@ -20,6 +20,6 @@ javax_activation_version=1.1.1
dokka_version=1.6.21
library_group=dev.inmo
library_version=2.1.0
library_version=2.0.3
github_release_plugin_version=2.4.1

View File

@ -1,31 +0,0 @@
package dev.inmo.tgbotapi.extensions.api.send.payments
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.send.payments.CreateInvoiceLink
import dev.inmo.tgbotapi.requests.send.payments.SendInvoice
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.CommonUser
import dev.inmo.tgbotapi.types.payments.LabeledPrice
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
suspend fun TelegramBot.createInvoiceLink(
title: String,
description: String,
payload: String,
providerToken: String,
currency: Currency,
prices: List<LabeledPrice>,
maxTipAmount: Int? = null,
suggestedTipAmounts: List<Int>? = null,
providerData: String? = null,
requireName: Boolean = false,
requirePhoneNumber: Boolean = false,
requireEmail: Boolean = false,
requireShippingAddress: Boolean = false,
shouldSendPhoneNumberToProvider: Boolean = false,
shouldSendEmailToProvider: Boolean = false,
priceDependOnShipAddress: Boolean = false
) = execute(
CreateInvoiceLink(title, description, payload, providerToken, currency, prices, maxTipAmount, suggestedTipAmounts ?.sorted(), providerData, requireName, requirePhoneNumber, requireEmail, requireShippingAddress, shouldSendPhoneNumberToProvider, shouldSendEmailToProvider, priceDependOnShipAddress)
)

View File

@ -13,11 +13,10 @@ suspend fun TelegramBot.setWebhookInfo(
ipAddress: String? = null,
maxAllowedConnections: Int? = null,
allowedUpdates: List<String>? = null,
dropPendingUpdates: Boolean? = null,
secretToken: String? = null
dropPendingUpdates: Boolean? = null
) = execute(
SetWebhook(
url, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates, secretToken
url, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates
)
)
@ -30,11 +29,10 @@ suspend fun TelegramBot.setWebhookInfo(
ipAddress: String? = null,
maxAllowedConnections: Int? = null,
allowedUpdates: List<String>? = null,
dropPendingUpdates: Boolean? = null,
secretToken: String? = null
dropPendingUpdates: Boolean? = null
) = execute(
SetWebhook(
url, certificate, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates, secretToken
url, certificate, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates
)
)
@ -47,10 +45,9 @@ suspend fun TelegramBot.setWebhookInfo(
ipAddress: String? = null,
maxAllowedConnections: Int? = null,
allowedUpdates: List<String>? = null,
dropPendingUpdates: Boolean? = null,
secretToken: String? = null
dropPendingUpdates: Boolean? = null
) = execute(
SetWebhook(
url, certificate, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates, secretToken
url, certificate, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates
)
)

View File

@ -1,105 +0,0 @@
package dev.inmo.tgbotapi.requests.send.payments
import dev.inmo.tgbotapi.abstracts.CommonSendInvoiceData
import dev.inmo.tgbotapi.abstracts.types.*
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.InvoiceContent
import dev.inmo.tgbotapi.types.payments.LabeledPrice
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
/**
* @param providerData - JSON-ENCODED FIELD
*/
@Serializable
data class CreateInvoiceLink(
@SerialName(titleField)
override val title: String,
@SerialName(descriptionField)
override val description: String,
@SerialName(payloadField)
override val payload: String,
@SerialName(providerTokenField)
override val providerToken: String,
@SerialName(currencyField)
override val currency: Currency,
@Serializable(LabeledPricesSerializer::class)
@SerialName(pricesField)
override val prices: List<LabeledPrice>,
@SerialName(maxTipAmountField)
override val maxTipAmount: Int? = null,
@SerialName(suggestedTipAmountsField)
override val suggestedTipAmounts: List<Int>? = null,
@SerialName(providerDataField)
override val providerData: String? = null,
@SerialName(requireNameField)
override val requireName: Boolean = false,
@SerialName(requirePhoneNumberField)
override val requirePhoneNumber: Boolean = false,
@SerialName(requireEmailField)
override val requireEmail: Boolean = false,
@SerialName(requireShippingAddressField)
override val requireShippingAddress: Boolean = false,
@SerialName(shouldSendPhoneNumberToProviderField)
override val shouldSendPhoneNumberToProvider: Boolean = false,
@SerialName(shouldSendEmailToProviderField)
override val shouldSendEmailToProvider: Boolean = false,
@SerialName(priceDependOnShipAddressField)
override val priceDependOnShipAddress: Boolean = false
) : CommonSendInvoiceData, SimpleRequest<String> {
override fun method(): String = "sendInvoice"
override val resultDeserializer: DeserializationStrategy<String>
get() = String.serializer()
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
@SerialName(photoUrlField)
override var photoUrl: String? = null
private set
@SerialName(photoSizeField)
override var photoSize: Long? = null
private set
@SerialName(photoWidthField)
override var photoWidth: Int? = null
private set
@SerialName(photoHeightField)
override var photoHeight: Int? = null
private set
init {
suggestedTipAmounts ?.let { _ ->
require(suggestedTipAmounts.size in suggestedTipAmountsLimit)
maxTipAmount ?.let { _ ->
require(
suggestedTipAmounts.none { it > maxTipAmount }
)
}
}
}
override fun setPhoto(
photoUrl: String,
photoSize: Long?,
photoWidth: Int?,
photoHeight: Int?
) {
this.photoUrl = photoUrl
this.photoSize = photoSize
this.photoWidth = photoWidth
this.photoHeight = photoHeight
}
override fun unsetPhoto() {
photoUrl = null
photoSize = null
photoWidth = null
photoHeight = null
}
}

View File

@ -20,8 +20,7 @@ class MultipartSetWebhookRequest(
ipAddress: String? = null,
maxAllowedConnections: Int? = null,
allowedUpdates: List<String>? = null,
dropPendingUpdates: Boolean? = null,
secretToken: String? = null
dropPendingUpdates: Boolean? = null
) : SetWebhookRequest(), MultipartRequest<Boolean> by MultipartRequestImpl(
SetWebhook(
correctWebhookUrl(url),
@ -29,8 +28,7 @@ class MultipartSetWebhookRequest(
ipAddress,
maxAllowedConnections,
allowedUpdates,
dropPendingUpdates,
secretToken
dropPendingUpdates
),
mapOf(certificateField to certificate)
)
@ -41,16 +39,14 @@ fun SetWebhook(
ipAddress: String? = null,
maxAllowedConnections: Int? = null,
allowedUpdates: List<String>? = null,
dropPendingUpdates: Boolean? = null,
secretToken: String? = null
dropPendingUpdates: Boolean? = null
): MultipartSetWebhookRequest = MultipartSetWebhookRequest(
correctWebhookUrl(url),
certificate,
ipAddress,
maxAllowedConnections,
allowedUpdates,
dropPendingUpdates,
secretToken
dropPendingUpdates
)
fun SetWebhook(
@ -59,16 +55,14 @@ fun SetWebhook(
ipAddress: String? = null,
maxAllowedConnections: Int? = null,
allowedUpdates: List<String>? = null,
dropPendingUpdates: Boolean? = null,
secretToken: String? = null
dropPendingUpdates: Boolean? = null
): SetWebhook = SetWebhook(
correctWebhookUrl(url),
certificate.fileId,
ipAddress,
maxAllowedConnections,
allowedUpdates,
dropPendingUpdates,
secretToken
dropPendingUpdates
)
/**
@ -85,11 +79,10 @@ fun SetWebhook(
ipAddress: String? = null,
maxAllowedConnections: Int? = null,
allowedUpdates: List<String>? = null,
dropPendingUpdates: Boolean? = null,
secretToken: String? = null
dropPendingUpdates: Boolean? = null
) = when (certificate) {
is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates, secretToken)
is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates, secretToken)
is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates)
is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates)
}
/**
@ -105,16 +98,14 @@ fun SetWebhook(
ipAddress: String? = null,
maxAllowedConnections: Int? = null,
allowedUpdates: List<String>? = null,
dropPendingUpdates: Boolean? = null,
secretToken: String? = null
dropPendingUpdates: Boolean? = null
) = SetWebhook(
correctWebhookUrl(url),
null,
ipAddress,
maxAllowedConnections,
allowedUpdates,
dropPendingUpdates,
secretToken
dropPendingUpdates
)
/**
@ -137,9 +128,7 @@ data class SetWebhook internal constructor(
@SerialName(allowedUpdatesField)
val allowedUpdates: List<String>? = null,
@SerialName(dropPendingUpdatesField)
val dropPendingUpdates: Boolean? = null,
@SerialName(secretTokenField)
val secretToken: String? = null
val dropPendingUpdates: Boolean? = null
) : SetWebhookRequest(), DataRequest<Boolean> {
override fun method(): String = "setWebhook"
override val resultDeserializer: DeserializationStrategy<Boolean>

View File

@ -117,8 +117,6 @@ const val isBotField = "is_bot"
const val firstNameField = "first_name"
const val lastNameField = "last_name"
const val languageCodeField = "language_code"
const val addedToAttachmentMenuField = "added_to_attachment_menu"
const val isPremiumField = "is_premium"
const val hasPrivateForwardsField = "has_private_forwards"
const val canJoinGroupsField = "can_join_groups"
const val canReadAllGroupMessagesField = "can_read_all_group_messages"
@ -126,7 +124,6 @@ const val supportInlineQueriesField = "supports_inline_queries"
const val textEntitiesField = "text_entities"
const val entitiesField = "entities"
const val stickerSetNameField = "set_name"
const val premiumAnimationField = "premium_animation"
const val stickerSetNameFullField = "sticker_set_name"
const val slowModeDelayField = "slow_mode_delay"
const val maskPositionField = "mask_position"
@ -158,7 +155,6 @@ const val switchPmParameterField = "switch_pm_parameter"
const val maxAllowedConnectionsField = "max_connections"
const val allowedUpdatesField = "allowed_updates"
const val dropPendingUpdatesField = "drop_pending_updates"
const val secretTokenField = "secret_token"
const val hasCustomCertificateField = "has_custom_certificate"
const val pendingUpdateCountField = "pending_update_count"
const val lastErrorDateField = "last_error_date"
@ -184,8 +180,6 @@ const val customTitleField = "custom_title"
const val optionIdsField = "option_ids"
const val ipAddressField = "ip_address"
const val linkedChatIdField = "linked_chat_id"
const val joinToSendMessagesField = "join_to_send_messages"
const val joinByRequestField = "join_by_request"
const val horizontalAccuracyField = "horizontal_accuracy"
const val revokeMessagesField = "revoke_messages"
const val messageAutoDeleteTimeField = "message_auto_delete_time"

View File

@ -32,16 +32,6 @@ sealed interface UsernameChat : Chat {
val username: Username?
}
@Serializable(PreviewChatSerializer::class)
sealed interface PossiblyPremiumChat : Chat {
val isPremium: Boolean
}
@Serializable(PreviewChatSerializer::class)
sealed interface AbleToAddInAttachmentMenuChat : Chat {
val addedToAttachmentMenu: Boolean
}
@Serializable(PreviewChatSerializer::class)
sealed interface Chat {
val id: ChatId

View File

@ -65,8 +65,7 @@ object PreviewChatSerializer : KSerializer<Chat> {
ChatType.ChannelChatType -> formatter.decodeFromJsonElement(ChannelChatImpl.serializer(), decodedJson)
is ChatType.UnknownChatType -> UnknownChatType(
formatter.decodeFromJsonElement(Long.serializer(), decodedJson[chatIdField] ?: JsonPrimitive(-1)).toChatId(),
decodedJson.toString(),
decodedJson
decodedJson.toString()
)
}
}
@ -78,10 +77,6 @@ object PreviewChatSerializer : KSerializer<Chat> {
is GroupChatImpl -> GroupChatImpl.serializer().serialize(encoder, value)
is SupergroupChatImpl -> SupergroupChatImpl.serializer().serialize(encoder, value)
is ChannelChatImpl -> ChannelChatImpl.serializer().serialize(encoder, value)
is CommonBot -> CommonBot.serializer().serialize(encoder, value)
is ExtendedBot -> ExtendedBot.serializer().serialize(encoder, value)
is CommonUser -> CommonUser.serializer().serialize(encoder, value)
is UnknownChatType -> JsonObject.serializer().serialize(encoder, value.rawJson)
}
}
}
@ -104,8 +99,7 @@ object ExtendedChatSerializer : KSerializer<ExtendedChat> {
ChatType.ChannelChatType -> formatter.decodeFromJsonElement(ExtendedChannelChatImpl.serializer(), decodedJson)
is ChatType.UnknownChatType -> UnknownExtendedChat(
formatter.decodeFromJsonElement(Long.serializer(), decodedJson[chatIdField] ?: JsonPrimitive(-1)).toChatId(),
decodedJson.toString(),
decodedJson
decodedJson.toString()
)
}
}
@ -116,7 +110,6 @@ object ExtendedChatSerializer : KSerializer<ExtendedChat> {
is ExtendedGroupChatImpl -> ExtendedGroupChatImpl.serializer().serialize(encoder, value)
is ExtendedSupergroupChatImpl -> ExtendedSupergroupChatImpl.serializer().serialize(encoder, value)
is ExtendedChannelChatImpl -> ExtendedChannelChatImpl.serializer().serialize(encoder, value)
is UnknownExtendedChat -> JsonObject.serializer().serialize(encoder, value.rawJson)
}
}
}

View File

@ -5,7 +5,6 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonObject
@Serializable
data class ExtendedChannelChatImpl(
@ -95,11 +94,7 @@ data class ExtendedSupergroupChatImpl(
@SerialName(linkedChatIdField)
override val linkedChannelChatId: ChatId? = null,
@SerialName(locationField)
override val location: ChatLocation? = null,
@SerialName(joinToSendMessagesField)
override val requiresJoinForMessaging: Boolean = false,
@SerialName(joinByRequestField)
override val requireAdminApproveToJoin: Boolean = false
override val location: ChatLocation? = null
) : ExtendedSupergroupChat
@Serializable
@ -124,8 +119,7 @@ data class ExtendedBot(
data class UnknownExtendedChat(
override val id: ChatId,
val raw: String,
val rawJson: JsonObject
val raw: String
) : ExtendedChat {
override val chatPhoto: ChatPhoto? = null
}

View File

@ -1,6 +1,7 @@
package dev.inmo.tgbotapi.types.chat
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.ExtendedChat
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
import kotlinx.serialization.Serializable
@ -38,16 +39,6 @@ sealed interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat {
val canSetStickerSet: Boolean
val linkedChannelChatId: ChatId?
val location: ChatLocation?
/**
* This field represents field "join_to_send_messages" from API
*/
val requiresJoinForMessaging: Boolean
/**
* This field represents field "join_by_request" from API
*/
val requireAdminApproveToJoin: Boolean
}
@Serializable(ExtendedChatSerializer::class)

View File

@ -80,12 +80,8 @@ data class CommonUser(
override val username: Username? = null,
@SerialName(languageCodeField)
@Serializable(IetfLanguageCodeSerializer::class)
override val ietfLanguageCode: IetfLanguageCode? = null,
@SerialName(isPremiumField)
override val isPremium: Boolean = false,
@SerialName(addedToAttachmentMenuField)
override val addedToAttachmentMenu: Boolean = false
) : User(), WithOptionalLanguageCode, PossiblyPremiumChat, AbleToAddInAttachmentMenuChat {
override val ietfLanguageCode: IetfLanguageCode? = null
) : User(), WithOptionalLanguageCode {
constructor(
id: UserId,
firstName: String,

View File

@ -1,10 +1,9 @@
package dev.inmo.tgbotapi.types.chat
import dev.inmo.tgbotapi.types.ChatId
import kotlinx.serialization.json.JsonObject
import dev.inmo.tgbotapi.types.chat.Chat
data class UnknownChatType(
override val id: ChatId,
val raw: String,
val rawJson: JsonObject
val raw: String
) : Chat

View File

@ -22,8 +22,7 @@ data class StickerSurrogate(
val emoji: String? = null,
val set_name: StickerSetName? = null,
val mask_position: MaskPosition? = null,
val file_size: Long? = null,
val premium_animation: File? = null
val file_size: Long? = null
)
// TODO:: Serializer
@ -32,7 +31,6 @@ sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile {
val emoji: String?
val maskPosition: MaskPosition?
val stickerSetName: StickerSetName?
val premiumAnimationFile: File?
val isAnimated
get() = this is AnimatedSticker
@ -55,7 +53,6 @@ object StickerSerializer : KSerializer<Sticker> {
surrogate.thumb,
surrogate.emoji,
surrogate.set_name,
surrogate.premium_animation,
surrogate.mask_position,
surrogate.file_size
)
@ -67,7 +64,6 @@ object StickerSerializer : KSerializer<Sticker> {
surrogate.thumb,
surrogate.emoji,
surrogate.set_name,
surrogate.premium_animation,
surrogate.mask_position,
surrogate.file_size
)
@ -79,7 +75,6 @@ object StickerSerializer : KSerializer<Sticker> {
surrogate.thumb,
surrogate.emoji,
surrogate.set_name,
surrogate.premium_animation,
surrogate.mask_position,
surrogate.file_size
)
@ -108,8 +103,6 @@ data class SimpleSticker(
override val emoji: String? = null,
@SerialName(stickerSetNameField)
override val stickerSetName: StickerSetName? = null,
@SerialName(premiumAnimationField)
override val premiumAnimationFile: File?,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null,
@SerialName(fileSizeField)
@ -131,8 +124,6 @@ data class AnimatedSticker(
override val emoji: String? = null,
@SerialName(stickerSetNameField)
override val stickerSetName: StickerSetName? = null,
@SerialName(premiumAnimationField)
override val premiumAnimationFile: File?,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null,
@SerialName(fileSizeField)
@ -154,8 +145,6 @@ data class VideoSticker(
override val emoji: String? = null,
@SerialName(stickerSetNameField)
override val stickerSetName: StickerSetName? = null,
@SerialName(premiumAnimationField)
override val premiumAnimationFile: File?,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null,
@SerialName(fileSizeField)

View File

@ -3,7 +3,6 @@
package dev.inmo.tgbotapi.extensions.utils
import dev.inmo.tgbotapi.abstracts.*
import dev.inmo.tgbotapi.requests.send.payments.CreateInvoiceLink
import dev.inmo.tgbotapi.requests.send.payments.SendInvoice
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.queries.callback.*
@ -236,24 +235,6 @@ inline fun Chat.asExtendedSupergroupChat(): ExtendedSupergroupChat? = this as? E
@PreviewFeature
inline fun Chat.requireExtendedSupergroupChat(): ExtendedSupergroupChat = this as ExtendedSupergroupChat
@PreviewFeature
inline fun <T> Chat.whenPossiblyPremiumChat(block: (PossiblyPremiumChat) -> T) = asPossiblyPremiumChat() ?.let(block)
@PreviewFeature
inline fun Chat.asPossiblyPremiumChat(): PossiblyPremiumChat? = this as? PossiblyPremiumChat
@PreviewFeature
inline fun Chat.requirePossiblyPremiumChat(): PossiblyPremiumChat = this as PossiblyPremiumChat
@PreviewFeature
inline fun <T> Chat.whenAbleToAddInAttachmentMenuChat(block: (AbleToAddInAttachmentMenuChat) -> T) = asAbleToAddInAttachmentMenuChat() ?.let(block)
@PreviewFeature
inline fun Chat.asAbleToAddInAttachmentMenuChat(): AbleToAddInAttachmentMenuChat? = this as? AbleToAddInAttachmentMenuChat
@PreviewFeature
inline fun Chat.requireAbleToAddInAttachmentMenuChat(): AbleToAddInAttachmentMenuChat = this as AbleToAddInAttachmentMenuChat
@PreviewFeature
inline fun <T> CallbackQuery.whenDataCallbackQuery(block: (DataCallbackQuery) -> T) = asDataCallbackQuery() ?.let(block)
@ -3274,16 +3255,7 @@ inline fun <T> CommonSendInvoiceData.whenSendInvoice(block: (SendInvoice) -> T)
inline fun CommonSendInvoiceData.asSendInvoice(): SendInvoice? = this as? SendInvoice
@PreviewFeature
inline fun CommonSendInvoiceData.requireSendInvoice(): SendInvoice = this as SendInvoice
@PreviewFeature
inline fun <T> CommonSendInvoiceData.whenCreateInvoiceLink(block: (CreateInvoiceLink) -> T) = asCreateInvoiceLink() ?.let(block)
@PreviewFeature
inline fun CommonSendInvoiceData.asCreateInvoiceLink(): CreateInvoiceLink? = this as? CreateInvoiceLink
@PreviewFeature
inline fun CommonSendInvoiceData.requireCreateInvoiceLink(): CreateInvoiceLink = this as CreateInvoiceLink
inline fun CommonSendInvoiceData.requireVoiceChatParticipantsInvited(): SendInvoice = this as SendInvoice
@PreviewFeature
inline fun <T> CommonSendInvoiceData.whenInputInvoiceMessageContent(block: (InputInvoiceMessageContent) -> T) = asInputInvoiceMessageContent() ?.let(block)

View File

@ -19,5 +19,3 @@ inline val Sticker.mask_position: MaskPosition?
get() = maskPosition
inline val Sticker.file_size: Long?
get() = fileSize
inline val Sticker.premium_animation: File?
get() = premiumAnimationFile

View File

@ -1,11 +0,0 @@
package dev.inmo.tgbotapi.webapps
external interface BackButton {
val isVisible: Boolean
fun onClick(callback: () -> Unit)
fun offClick(callback: () -> Unit)
fun show()
fun hide()
}

View File

@ -1,20 +0,0 @@
package dev.inmo.tgbotapi.webapps
import kotlinx.serialization.Serializable
sealed interface Color {
val value: String
@Serializable
value class BackgroundColor(override val value: String) : Color
@Serializable
value class Hex(override val value: String) : Color
companion object {
val BackgroundColor = BackgroundColor("bg_color")
val SecondaryBackgroundColor = BackgroundColor("secondary_bg_color")
@Suppress("NOTHING_TO_INLINE")
inline operator fun invoke(value: String) = Hex(value)
}
}

View File

@ -1,7 +1,4 @@
package dev.inmo.tgbotapi.webapps
import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo
typealias EventHandler = WebApp.() -> Unit
typealias ViewportChangedEventHandler = WebApp.(ViewportChangedData) -> Unit
typealias InvoiceClosedEventHandler = WebApp.(InvoiceClosedInfo) -> Unit

View File

@ -4,7 +4,4 @@ sealed class EventType(val typeName: String) {
object ThemeChanged : EventType("themeChanged")
object ViewportChanged : EventType("viewportChanged")
object MainButtonClicked : EventType("mainButtonClicked")
object BackButtonClicked : EventType("backButtonClicked")
object SettingsButtonClicked : EventType("settingsButtonClicked")
object InvoiceClosed : EventType("invoiceClosed")
}

View File

@ -1,3 +0,0 @@
package dev.inmo.tgbotapi.webapps
typealias HEXColor = String

View File

@ -23,7 +23,6 @@ external class MainButton {
fun hideProgress(): MainButton
internal fun onClick(eventHandler: () -> Unit): MainButton
internal fun offClick(eventHandler: () -> Unit): MainButton
internal fun setParams(params: Json): MainButton
}

View File

@ -2,32 +2,15 @@ package dev.inmo.tgbotapi.webapps
external interface ThemeParams {
@JsName("bg_color")
val backgroundColor: HEXColor?
@JsName("secondary_bg_color")
val secondaryBackgroundColor: HEXColor?
val backgroundColor: String?
@JsName("text_color")
val textColor: HEXColor?
val textColor: String?
@JsName("hint_color")
val hintColor: HEXColor?
val hintColor: String?
@JsName("link_color")
val linkColor: HEXColor?
val linkColor: String?
@JsName("button_color")
val buttonColor: HEXColor?
val buttonColor: String?
@JsName("button_text_color")
val buttonTextColor: HEXColor?
@JsName("bg_color")
val backgroundColorHex: Color.Hex?
@JsName("secondary_bg_color")
val secondaryBackgroundColorHex: Color.Hex?
@JsName("text_color")
val textColorHex: Color.Hex?
@JsName("hint_color")
val hintColorHex: Color.Hex?
@JsName("link_color")
val linkColorHex: Color.Hex?
@JsName("button_color")
val buttonColorHex: Color.Hex?
@JsName("button_text_color")
val buttonTextColorHex: Color.Hex?
val buttonTextColor: String?
}

View File

@ -1,21 +1,11 @@
package dev.inmo.tgbotapi.webapps
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback
import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo
external class WebApp {
val version: String
val initData: String
val initDataUnsafe: WebAppInitData
val headerColor: HEXColor?
fun setHeaderColor(color: Color.BackgroundColor)
val backgroundColor: HEXColor?
fun setBackgroundColor(color: Color.Hex)
fun setBackgroundColor(color: Color.BackgroundColor)
@JsName("colorScheme")
val colorSchemeRaw: String
val themeParams: ThemeParams
@ -27,34 +17,19 @@ external class WebApp {
@JsName("MainButton")
val mainButton: MainButton
@JsName("BackButton")
val backButton: BackButton
@JsName("HapticFeedback")
val hapticFeedback: HapticFeedback
internal fun onEvent(type: String, callback: () -> Unit)
@JsName("onEvent")
internal fun onEventWithViewportChangedData(type: String, callback: (ViewportChangedData) -> Unit)
@JsName("onEvent")
internal fun onEventWithInvoiceClosedInfo(type: String, callback: (InvoiceClosedInfo) -> Unit)
internal fun onEventWithBoolean(type: String, callback: (ViewportChangedData) -> Unit)
fun offEvent(type: String, callback: () -> Unit)
@JsName("offEvent")
fun offEventWithViewportChangedData(type: String, callback: (ViewportChangedData) -> Unit)
@JsName("offEvent")
fun offEventWithInvoiceClosedInfo(type: String, callback: (InvoiceClosedInfo) -> Unit)
fun offEventWithBoolean(type: String, callback: (ViewportChangedData) -> Unit)
fun sendData(data: String)
fun ready()
fun expand()
fun close()
fun isVersionAtLeast(version: String): Boolean
fun openLink(url: String)
fun openTelegramLink(url: String)
fun openInvoice(url: String, callback: (InvoiceClosedInfo) -> Unit = definedExternally)
}
val WebApp.colorScheme: ColorScheme
@ -82,19 +57,7 @@ fun WebApp.onEvent(type: EventType, eventHandler: EventHandler) = {
fun WebApp.onEvent(type: EventType.ViewportChanged, eventHandler: ViewportChangedEventHandler) = { it: ViewportChangedData ->
eventHandler(js("this").unsafeCast<WebApp>(), it)
}.also {
onEventWithViewportChangedData(
type.typeName,
callback = it
)
}
/**
* @return The callback which should be used in case you want to turn off events handling
*/
fun WebApp.onEvent(type: EventType.InvoiceClosed, eventHandler: InvoiceClosedEventHandler) = { it: InvoiceClosedInfo ->
eventHandler(js("this").unsafeCast<WebApp>(), it)
}.also {
onEventWithInvoiceClosedInfo(
onEventWithBoolean(
type.typeName,
callback = it
)
@ -112,18 +75,6 @@ fun WebApp.onMainButtonClicked(eventHandler: EventHandler) = onEvent(EventType.M
* @return The callback which should be used in case you want to turn off events handling
*/
fun WebApp.onViewportChanged(eventHandler: ViewportChangedEventHandler) = onEvent(EventType.ViewportChanged, eventHandler)
/**
* @return The callback which should be used in case you want to turn off events handling
*/
fun WebApp.onBackButtonClicked(eventHandler: EventHandler) = onEvent(EventType.BackButtonClicked, eventHandler)
/**
* @return The callback which should be used in case you want to turn off events handling
*/
fun WebApp.onSettingsButtonClicked(eventHandler: EventHandler) = onEvent(EventType.SettingsButtonClicked, eventHandler)
/**
* @return The callback which should be used in case you want to turn off events handling
*/
fun WebApp.onInvoiceClosed(eventHandler: InvoiceClosedEventHandler) = onEvent(EventType.InvoiceClosed, eventHandler)
fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).checkWebAppData(
initData,

View File

@ -1,14 +0,0 @@
package dev.inmo.tgbotapi.webapps
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.Username
import dev.inmo.tgbotapi.types.chat.PublicChat
external interface WebAppChat {
val id: ChatIdentifier
val type: String
val title: String
val username: Username?
@JsName("photo_url")
val photoUrl: String?
}

View File

@ -15,10 +15,5 @@ external interface WebAppInitData {
@JsName("auth_date")
val authDate: MilliSeconds
@JsName("can_send_after")
val canSendAfter: MilliSeconds
val chat: WebAppChat
val hash: String
}

View File

@ -1,7 +0,0 @@
package dev.inmo.tgbotapi.webapps.haptic
external interface HapticFeedback {
fun impactOccurred(style: HapticFeedbackStyle)
fun notificationOccurred(type: HapticFeedbackType)
fun selectionChanged()
}

View File

@ -1,17 +0,0 @@
package dev.inmo.tgbotapi.webapps.haptic
import dev.inmo.micro_utils.common.Warning
import kotlinx.serialization.Serializable
@Serializable
value class HapticFeedbackStyle @Warning("Do not use this constructor if available objects from companion cover your needs") constructor(
val name: String
) {
companion object {
val Light = HapticFeedbackStyle("light")
val Medium = HapticFeedbackStyle("medium")
val Heavy = HapticFeedbackStyle("heavy")
val Rigid = HapticFeedbackStyle("rigid")
val Soft = HapticFeedbackStyle("soft")
}
}

View File

@ -1,15 +0,0 @@
package dev.inmo.tgbotapi.webapps.haptic
import dev.inmo.micro_utils.common.Warning
import kotlinx.serialization.Serializable
@Serializable
value class HapticFeedbackType @Warning("Do not use this constructor if available objects from companion cover your needs") constructor(
val name: String
) {
companion object {
val Error = HapticFeedbackType("error")
val Success = HapticFeedbackType("success")
val Warning = HapticFeedbackType("warning")
}
}

View File

@ -1,16 +0,0 @@
package dev.inmo.tgbotapi.webapps.invoice
external interface InvoiceClosedInfo {
val url: String
val status: String
}
val InvoiceClosedInfo.statusTyped
get() = when (status) {
InvoiceStatus.Paid.name -> InvoiceStatus.Paid
InvoiceStatus.Cancelled.name -> InvoiceStatus.Cancelled
InvoiceStatus.Failed.name -> InvoiceStatus.Failed
InvoiceStatus.Pending.name -> InvoiceStatus.Pending
else -> InvoiceStatus.Unknown(status)
}

View File

@ -1,10 +0,0 @@
package dev.inmo.tgbotapi.webapps.invoice
sealed interface InvoiceStatus {
val name: String
object Paid : InvoiceStatus { override val name: String = "paid" }
object Cancelled : InvoiceStatus { override val name: String = "cancelled" }
object Failed : InvoiceStatus { override val name: String = "failed" }
object Pending : InvoiceStatus { override val name: String = "pending" }
value class Unknown(override val name: String) : InvoiceStatus
}