mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-06-01 23:45:25 +00:00
55 lines
1.6 KiB
Kotlin
55 lines
1.6 KiB
Kotlin
|
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||
|
|
||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.*
|
||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||
|
import kotlinx.serialization.*
|
||
|
import kotlinx.serialization.internal.BooleanSerializer
|
||
|
|
||
|
fun SetWebhook(
|
||
|
url: String,
|
||
|
certificate: InputFile,
|
||
|
maxAllowedConnections: Int? = null,
|
||
|
allowedUpdates: List<String>? = null
|
||
|
) : Request<Boolean> {
|
||
|
val data = SetWebhook(
|
||
|
url,
|
||
|
certificate.fileId,
|
||
|
maxAllowedConnections,
|
||
|
allowedUpdates
|
||
|
)
|
||
|
return when (certificate) {
|
||
|
is FileId -> data
|
||
|
is MultipartFile -> MultipartRequestImpl(
|
||
|
data,
|
||
|
mapOf(certificateField to certificate)
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Serializable
|
||
|
data class SetWebhook internal constructor(
|
||
|
@SerialName(urlField)
|
||
|
val url: String,
|
||
|
@SerialName(certificateField)
|
||
|
@Optional
|
||
|
val certificateFile: String? = null,
|
||
|
@SerialName(maxAllowedConnectionsField)
|
||
|
@Optional
|
||
|
val maxAllowedConnections: Int? = null,
|
||
|
@SerialName(allowedUpdatesField)
|
||
|
@Optional
|
||
|
val allowedUpdates: List<String>? = null
|
||
|
) : DataRequest<Boolean> {
|
||
|
override fun method(): String = "setWebhook"
|
||
|
override fun resultSerializer(): KSerializer<Boolean> = BooleanSerializer
|
||
|
|
||
|
init {
|
||
|
maxAllowedConnections ?.let {
|
||
|
if (it !in allowedConnectionsLength) {
|
||
|
throw IllegalArgumentException("Allowed connection for webhook must be in $allowedConnectionsLength range (but passed $it)")
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|