mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-23 00:57:13 +00:00
add SetWebhook
This commit is contained in:
parent
de039c3909
commit
ff2b56b3a9
@ -2,6 +2,11 @@
|
||||
|
||||
## 0.12.0
|
||||
|
||||
* Added `DataRequest` interface which replace `Data` interface
|
||||
* `MultipartRequestImpl` now use `DataRequest`
|
||||
* All requests which implements `Data` now implement `DataRequest`
|
||||
* Added class `SetWebhook` and its factory
|
||||
|
||||
## 0.11.0
|
||||
|
||||
* Kotlin `1.3.11` -> `1.3.21`
|
||||
|
@ -0,0 +1,54 @@
|
||||
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)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -87,7 +87,7 @@ data class SendAnimationData internal constructor(
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : Data<RawMessage>,
|
||||
) : DataRequest<RawMessage>,
|
||||
SendMessageRequest<RawMessage>,
|
||||
ReplyingMarkupSendMessageRequest<RawMessage>,
|
||||
TextableSendMessageRequest<RawMessage>,
|
||||
|
@ -88,7 +88,7 @@ data class SendAudioData internal constructor(
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : Data<RawMessage>,
|
||||
) : DataRequest<RawMessage>,
|
||||
SendMessageRequest<RawMessage>,
|
||||
ReplyingMarkupSendMessageRequest<RawMessage>,
|
||||
TextableSendMessageRequest<RawMessage>,
|
||||
|
@ -72,7 +72,7 @@ data class SendDocumentData internal constructor(
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : Data<RawMessage>,
|
||||
) : DataRequest<RawMessage>,
|
||||
SendMessageRequest<RawMessage>,
|
||||
ReplyingMarkupSendMessageRequest<RawMessage>,
|
||||
TextableSendMessageRequest<RawMessage>,
|
||||
|
@ -66,7 +66,7 @@ data class SendMediaGroupData internal constructor(
|
||||
@SerialName(replyToMessageIdField)
|
||||
@Optional
|
||||
override val replyToMessageId: MessageIdentifier? = null
|
||||
) : Data<List<RawMessage>>,
|
||||
) : DataRequest<List<RawMessage>>,
|
||||
SendMessageRequest<List<RawMessage>>
|
||||
{
|
||||
@SerialName(mediaField)
|
||||
|
@ -58,7 +58,7 @@ data class SendPhotoData internal constructor(
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : Data<RawMessage>,
|
||||
) : DataRequest<RawMessage>,
|
||||
SendMessageRequest<RawMessage>,
|
||||
ReplyingMarkupSendMessageRequest<RawMessage>,
|
||||
TextableSendMessageRequest<RawMessage>
|
||||
|
@ -92,7 +92,7 @@ data class SendVideoData internal constructor(
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : Data<RawMessage>,
|
||||
) : DataRequest<RawMessage>,
|
||||
SendMessageRequest<RawMessage>,
|
||||
ReplyingMarkupSendMessageRequest<RawMessage>,
|
||||
TextableSendMessageRequest<RawMessage>,
|
||||
|
@ -82,7 +82,7 @@ data class SendVideoNoteData internal constructor(
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : Data<RawMessage>,
|
||||
) : DataRequest<RawMessage>,
|
||||
SendMessageRequest<RawMessage>,
|
||||
ReplyingMarkupSendMessageRequest<RawMessage>,
|
||||
TextableSendMessageRequest<RawMessage>,
|
||||
|
@ -77,7 +77,7 @@ data class SendVoiceData internal constructor(
|
||||
@SerialName(replyMarkupField)
|
||||
@Optional
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : Data<RawMessage>,
|
||||
) : DataRequest<RawMessage>,
|
||||
SendMessageRequest<RawMessage>,
|
||||
ReplyingMarkupSendMessageRequest<RawMessage>,
|
||||
TextableSendMessageRequest<RawMessage>,
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
|
||||
interface Data<T: Any> : SimpleRequest<T>
|
||||
@Deprecated(
|
||||
"Renamed to DataRequest",
|
||||
ReplaceWith(
|
||||
"DataRequest",
|
||||
"com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.DataRequest"
|
||||
)
|
||||
)
|
||||
typealias Data<T> = DataRequest<T>
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
|
||||
interface DataRequest<T: Any> : SimpleRequest<T>
|
@ -9,7 +9,7 @@ import kotlinx.serialization.json.JsonObject
|
||||
/**
|
||||
* Will be used as SimpleRequest if
|
||||
*/
|
||||
class MultipartRequestImpl<D: Data<R>, F: Files, R: Any>(
|
||||
class MultipartRequestImpl<D: DataRequest<R>, F: Files, R: Any>(
|
||||
val data: D,
|
||||
val files: F
|
||||
) : MultipartRequest<R> {
|
||||
|
@ -23,6 +23,7 @@ val userProfilePhotosRequestLimit = 0 .. 100
|
||||
val chatTitleLength = 1 until 255
|
||||
val chatDescriptionLength = 0 until 256
|
||||
val inlineResultQueryIdLingth = 1 until 64
|
||||
val allowedConnectionsLength = 1 .. 100
|
||||
|
||||
val invoiceTitleLimit = 1 until 32
|
||||
val invoiceDescriptionLimit = 1 until 256
|
||||
@ -68,6 +69,8 @@ const val isPersonalField = "is_personal"
|
||||
const val nextOffsetField = "next_offset"
|
||||
const val switchPmTextField = "switch_pm_text"
|
||||
const val switchPmParameterField = "switch_pm_parameter"
|
||||
const val maxAllowedConnectionsField = "max_connections"
|
||||
const val allowedUpdatesField = "allowed_updates"
|
||||
|
||||
|
||||
const val photoUrlField = "photo_url"
|
||||
@ -172,6 +175,7 @@ const val pricesField = "prices"
|
||||
const val payloadField = "payload"
|
||||
const val vcardField = "vcard"
|
||||
const val resultsField = "results"
|
||||
const val certificateField = "certificate"
|
||||
|
||||
const val pointField = "point"
|
||||
const val xShiftField = "x_shift"
|
||||
|
Loading…
Reference in New Issue
Block a user