mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 19:48:43 +00:00
commit
141281f96d
@ -1,5 +1,10 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
## 3.1.1
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* Complete Bot API 6.2 implementation
|
||||||
|
|
||||||
## 3.1.0
|
## 3.1.0
|
||||||
|
|
||||||
**This update contains including of Bot API 6.2**
|
**This update contains including of Bot API 6.2**
|
||||||
|
@ -6,4 +6,4 @@ kotlin.incremental=true
|
|||||||
kotlin.incremental.js=true
|
kotlin.incremental.js=true
|
||||||
|
|
||||||
library_group=dev.inmo
|
library_group=dev.inmo
|
||||||
library_version=3.1.0
|
library_version=3.1.1
|
||||||
|
@ -164,6 +164,7 @@ const val languageCodeField = "language_code"
|
|||||||
const val addedToAttachmentMenuField = "added_to_attachment_menu"
|
const val addedToAttachmentMenuField = "added_to_attachment_menu"
|
||||||
const val isPremiumField = "is_premium"
|
const val isPremiumField = "is_premium"
|
||||||
const val hasPrivateForwardsField = "has_private_forwards"
|
const val hasPrivateForwardsField = "has_private_forwards"
|
||||||
|
const val hasRestrictedVoiceAndVideoMessagesField = "has_restricted_voice_and_video_messages"
|
||||||
const val canJoinGroupsField = "can_join_groups"
|
const val canJoinGroupsField = "can_join_groups"
|
||||||
const val canReadAllGroupMessagesField = "can_read_all_group_messages"
|
const val canReadAllGroupMessagesField = "can_read_all_group_messages"
|
||||||
const val supportInlineQueriesField = "supports_inline_queries"
|
const val supportInlineQueriesField = "supports_inline_queries"
|
||||||
|
@ -62,7 +62,9 @@ data class ExtendedPrivateChatImpl(
|
|||||||
@SerialName(bioField)
|
@SerialName(bioField)
|
||||||
override val bio: String = "",
|
override val bio: String = "",
|
||||||
@SerialName(hasPrivateForwardsField)
|
@SerialName(hasPrivateForwardsField)
|
||||||
override val hasPrivateForwards: Boolean = false
|
override val hasPrivateForwards: Boolean = false,
|
||||||
|
@SerialName(hasRestrictedVoiceAndVideoMessagesField)
|
||||||
|
override val hasRestrictedVoiceAndVideoMessages: Boolean = false
|
||||||
) : ExtendedPrivateChat
|
) : ExtendedPrivateChat
|
||||||
|
|
||||||
typealias ExtendedUser = ExtendedPrivateChatImpl
|
typealias ExtendedUser = ExtendedPrivateChatImpl
|
||||||
|
@ -19,6 +19,7 @@ sealed interface ExtendedGroupChat : GroupChat, ExtendedPublicChat {
|
|||||||
sealed interface ExtendedPrivateChat : PrivateChat, ExtendedChat {
|
sealed interface ExtendedPrivateChat : PrivateChat, ExtendedChat {
|
||||||
val bio: String
|
val bio: String
|
||||||
val hasPrivateForwards: Boolean
|
val hasPrivateForwards: Boolean
|
||||||
|
val hasRestrictedVoiceAndVideoMessages: Boolean
|
||||||
|
|
||||||
val allowCreateUserIdLink: Boolean
|
val allowCreateUserIdLink: Boolean
|
||||||
get() = hasPrivateForwards
|
get() = hasPrivateForwards
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
package dev.inmo.tgbotapi.webapps
|
||||||
|
|
||||||
|
typealias AlertCallback = () -> Unit
|
@ -0,0 +1,3 @@
|
|||||||
|
package dev.inmo.tgbotapi.webapps
|
||||||
|
|
||||||
|
typealias ConfirmCallback = (confirmed: Boolean) -> Unit
|
@ -5,3 +5,4 @@ import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo
|
|||||||
typealias EventHandler = WebApp.() -> Unit
|
typealias EventHandler = WebApp.() -> Unit
|
||||||
typealias ViewportChangedEventHandler = WebApp.(ViewportChangedData) -> Unit
|
typealias ViewportChangedEventHandler = WebApp.(ViewportChangedData) -> Unit
|
||||||
typealias InvoiceClosedEventHandler = WebApp.(InvoiceClosedInfo) -> Unit
|
typealias InvoiceClosedEventHandler = WebApp.(InvoiceClosedInfo) -> Unit
|
||||||
|
typealias PopupClosedEventHandler = WebApp.(String?) -> Unit
|
||||||
|
@ -7,4 +7,5 @@ sealed class EventType(val typeName: String) {
|
|||||||
object BackButtonClicked : EventType("backButtonClicked")
|
object BackButtonClicked : EventType("backButtonClicked")
|
||||||
object SettingsButtonClicked : EventType("settingsButtonClicked")
|
object SettingsButtonClicked : EventType("settingsButtonClicked")
|
||||||
object InvoiceClosed : EventType("invoiceClosed")
|
object InvoiceClosed : EventType("invoiceClosed")
|
||||||
|
object PopupClosed : EventType("popupClosed")
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.webapps
|
|||||||
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||||
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback
|
import dev.inmo.tgbotapi.webapps.haptic.HapticFeedback
|
||||||
import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo
|
import dev.inmo.tgbotapi.webapps.invoice.InvoiceClosedInfo
|
||||||
|
import dev.inmo.tgbotapi.webapps.popup.*
|
||||||
|
|
||||||
external class WebApp {
|
external class WebApp {
|
||||||
val version: String
|
val version: String
|
||||||
@ -24,6 +25,15 @@ external class WebApp {
|
|||||||
val viewportHeight: Float
|
val viewportHeight: Float
|
||||||
val viewportStableHeight: Float
|
val viewportStableHeight: Float
|
||||||
|
|
||||||
|
|
||||||
|
val isClosingConfirmationEnabled: Boolean
|
||||||
|
fun enableClosingConfirmation()
|
||||||
|
fun disableClosingConfirmation()
|
||||||
|
|
||||||
|
fun showPopup(params: PopupParams, callback: ClosePopupCallback? = definedExternally)
|
||||||
|
fun showAlert(message: String, callback: AlertCallback? = definedExternally)
|
||||||
|
fun showConfirm(message: String, callback: ConfirmCallback? = definedExternally)
|
||||||
|
|
||||||
@JsName("MainButton")
|
@JsName("MainButton")
|
||||||
val mainButton: MainButton
|
val mainButton: MainButton
|
||||||
|
|
||||||
@ -38,6 +48,8 @@ external class WebApp {
|
|||||||
internal fun onEventWithViewportChangedData(type: String, callback: (ViewportChangedData) -> Unit)
|
internal fun onEventWithViewportChangedData(type: String, callback: (ViewportChangedData) -> Unit)
|
||||||
@JsName("onEvent")
|
@JsName("onEvent")
|
||||||
internal fun onEventWithInvoiceClosedInfo(type: String, callback: (InvoiceClosedInfo) -> Unit)
|
internal fun onEventWithInvoiceClosedInfo(type: String, callback: (InvoiceClosedInfo) -> Unit)
|
||||||
|
@JsName("onEvent")
|
||||||
|
internal fun onEventWithPopupClosedInfo(type: String, callback: (String?) -> Unit)
|
||||||
|
|
||||||
fun offEvent(type: String, callback: () -> Unit)
|
fun offEvent(type: String, callback: () -> Unit)
|
||||||
@JsName("offEvent")
|
@JsName("offEvent")
|
||||||
@ -100,6 +112,18 @@ fun WebApp.onEvent(type: EventType.InvoiceClosed, eventHandler: InvoiceClosedEve
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The callback which should be used in case you want to turn off events handling
|
||||||
|
*/
|
||||||
|
fun WebApp.onEvent(type: EventType.PopupClosed, eventHandler: PopupClosedEventHandler) = { it: String? ->
|
||||||
|
eventHandler(js("this").unsafeCast<WebApp>(), it)
|
||||||
|
}.also {
|
||||||
|
onEventWithPopupClosedInfo(
|
||||||
|
type.typeName,
|
||||||
|
callback = it
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The callback which should be used in case you want to turn off events handling
|
* @return The callback which should be used in case you want to turn off events handling
|
||||||
*/
|
*/
|
||||||
@ -124,8 +148,55 @@ fun WebApp.onSettingsButtonClicked(eventHandler: EventHandler) = onEvent(EventTy
|
|||||||
* @return The callback which should be used in case you want to turn off events handling
|
* @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.onInvoiceClosed(eventHandler: InvoiceClosedEventHandler) = onEvent(EventType.InvoiceClosed, eventHandler)
|
||||||
|
/**
|
||||||
|
* @return The callback which should be used in case you want to turn off events handling
|
||||||
|
*/
|
||||||
|
fun WebApp.onPopupClosed(eventHandler: PopupClosedEventHandler) = onEvent(EventType.PopupClosed, eventHandler)
|
||||||
|
|
||||||
fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).checkWebAppData(
|
fun WebApp.isInitDataSafe(botToken: String) = TelegramAPIUrlsKeeper(botToken).checkWebAppData(
|
||||||
initData,
|
initData,
|
||||||
initDataUnsafe.hash
|
initDataUnsafe.hash
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun WebApp.showPopup(
|
||||||
|
message: String,
|
||||||
|
title: String?,
|
||||||
|
buttons: Array<PopupButton>,
|
||||||
|
callback: ClosePopupCallback? = null
|
||||||
|
) = showPopup(
|
||||||
|
PopupParams(
|
||||||
|
message,
|
||||||
|
title,
|
||||||
|
buttons
|
||||||
|
),
|
||||||
|
callback
|
||||||
|
)
|
||||||
|
|
||||||
|
fun WebApp.showPopup(
|
||||||
|
message: String,
|
||||||
|
title: String?,
|
||||||
|
firstButton: PopupButton,
|
||||||
|
vararg otherButtons: PopupButton,
|
||||||
|
callback: ClosePopupCallback? = null
|
||||||
|
) = showPopup(
|
||||||
|
PopupParams(
|
||||||
|
message,
|
||||||
|
title,
|
||||||
|
arrayOf(firstButton, *otherButtons)
|
||||||
|
),
|
||||||
|
callback
|
||||||
|
)
|
||||||
|
|
||||||
|
var WebApp.requireClosingConfirmation
|
||||||
|
get() = isClosingConfirmationEnabled
|
||||||
|
set(value) {
|
||||||
|
if (value) {
|
||||||
|
enableClosingConfirmation()
|
||||||
|
} else {
|
||||||
|
disableClosingConfirmation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun WebApp.toggleClosingConfirmation() {
|
||||||
|
requireClosingConfirmation = !requireClosingConfirmation
|
||||||
|
}
|
||||||
|
@ -17,10 +17,14 @@ external interface WebAppUser {
|
|||||||
val username: String?
|
val username: String?
|
||||||
@JsName(languageCodeField)
|
@JsName(languageCodeField)
|
||||||
val languageCode: String?
|
val languageCode: String?
|
||||||
|
val is_premium: Boolean?
|
||||||
@JsName(photoUrlField)
|
@JsName(photoUrlField)
|
||||||
val photoUrl: String?
|
val photoUrl: String?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val WebAppUser.isPremium
|
||||||
|
get() = is_premium == true
|
||||||
|
|
||||||
fun WebAppUser.asUser() = if (isBot == true) {
|
fun WebAppUser.asUser() = if (isBot == true) {
|
||||||
CommonBot(
|
CommonBot(
|
||||||
UserId(id),
|
UserId(id),
|
||||||
@ -34,6 +38,7 @@ fun WebAppUser.asUser() = if (isBot == true) {
|
|||||||
firstName,
|
firstName,
|
||||||
lastName ?: "",
|
lastName ?: "",
|
||||||
username ?.let(::Username),
|
username ?.let(::Username),
|
||||||
languageCode ?.let(::IetfLanguageCode)
|
languageCode ?.let(::IetfLanguageCode),
|
||||||
|
isPremium = isPremium
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
package dev.inmo.tgbotapi.webapps.popup
|
||||||
|
|
||||||
|
typealias ClosePopupCallback = (id: String) -> Unit
|
@ -0,0 +1,55 @@
|
|||||||
|
package dev.inmo.tgbotapi.webapps.popup
|
||||||
|
|
||||||
|
import kotlin.js.json
|
||||||
|
|
||||||
|
external interface PopupButton {
|
||||||
|
val id: String
|
||||||
|
val type: PopupButtonType
|
||||||
|
val text: String?
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PopupButton(
|
||||||
|
id: String,
|
||||||
|
type: PopupButtonType,
|
||||||
|
text: String? = null
|
||||||
|
) = json(
|
||||||
|
*listOfNotNull(
|
||||||
|
"id" to id,
|
||||||
|
"type" to type.typeName,
|
||||||
|
("text" to text).takeIf { text != null }
|
||||||
|
).toTypedArray()
|
||||||
|
).unsafeCast<PopupButton>()
|
||||||
|
|
||||||
|
value class PopupButtonType(
|
||||||
|
val typeName: String
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
val Default = PopupButtonType("default")
|
||||||
|
val Ok = PopupButtonType("ok")
|
||||||
|
val Close = PopupButtonType("close")
|
||||||
|
val Cancel = PopupButtonType("cancel")
|
||||||
|
val Destructive = PopupButtonType("destructive")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun DefaultPopupButton(
|
||||||
|
id: String,
|
||||||
|
text: String
|
||||||
|
) = PopupButton(id, PopupButtonType.Default, text)
|
||||||
|
|
||||||
|
fun OkPopupButton(
|
||||||
|
id: String
|
||||||
|
) = PopupButton(id, PopupButtonType.Ok)
|
||||||
|
|
||||||
|
fun ClosePopupButton(
|
||||||
|
id: String
|
||||||
|
) = PopupButton(id, PopupButtonType.Close)
|
||||||
|
|
||||||
|
fun CancelPopupButton(
|
||||||
|
id: String
|
||||||
|
) = PopupButton(id, PopupButtonType.Cancel)
|
||||||
|
|
||||||
|
fun DestructivePopupButton(
|
||||||
|
id: String,
|
||||||
|
text: String
|
||||||
|
) = PopupButton(id, PopupButtonType.Destructive, text)
|
@ -0,0 +1,48 @@
|
|||||||
|
package dev.inmo.tgbotapi.webapps.popup
|
||||||
|
|
||||||
|
import kotlin.js.json
|
||||||
|
|
||||||
|
external interface PopupParams {
|
||||||
|
val message: String
|
||||||
|
val title: String?
|
||||||
|
val buttons: Array<PopupButton>
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PopupParams(
|
||||||
|
message: String,
|
||||||
|
title: String?,
|
||||||
|
buttons: Array<PopupButton>
|
||||||
|
) = json(
|
||||||
|
*listOfNotNull(
|
||||||
|
"message" to message,
|
||||||
|
"buttons" to buttons,
|
||||||
|
("title" to title).takeIf { title != null }
|
||||||
|
).toTypedArray()
|
||||||
|
).unsafeCast<PopupParams>()
|
||||||
|
|
||||||
|
fun PopupParams(
|
||||||
|
message: String,
|
||||||
|
firstButton: PopupButton,
|
||||||
|
vararg otherButtons: PopupButton
|
||||||
|
) = PopupParams(
|
||||||
|
message,
|
||||||
|
null,
|
||||||
|
arrayOf(
|
||||||
|
firstButton,
|
||||||
|
*otherButtons
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
fun PopupParams(
|
||||||
|
title: String,
|
||||||
|
message: String,
|
||||||
|
firstButton: PopupButton,
|
||||||
|
vararg otherButtons: PopupButton
|
||||||
|
) = PopupParams(
|
||||||
|
message,
|
||||||
|
title,
|
||||||
|
arrayOf(
|
||||||
|
firstButton,
|
||||||
|
*otherButtons
|
||||||
|
)
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user