mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
SetWebhook updates
This commit is contained in:
parent
6d6c544aaf
commit
86a472e814
@ -5,6 +5,14 @@
|
||||
* `Core`:
|
||||
* Support of `logOut` method (`LogOut` object as a `Request`)
|
||||
* Support of `close` method (`Close` object as a `Request`)
|
||||
* `SetWebhook` updates:
|
||||
* Function `SetWebhook` with `inputFile` has changed this param nullability - `inputFile` now is nullable
|
||||
* Function `SetWebhook` without `certificate` param now is unavailable. You can use `SetWebhook` with nullable
|
||||
`inputFile`
|
||||
* New field `ipAddress`. It works the same as `ip_address` in [setWebhook](https://core.telegram.org/bots/api#setwebhook)
|
||||
section
|
||||
* New field `dropPendingUpdates`. It works the same as `drop_pending_updates` in [setWebhook](https://core.telegram.org/bots/api#setwebhook)
|
||||
section
|
||||
|
||||
## 0.29.4
|
||||
|
||||
|
@ -16,14 +16,18 @@ private fun correctWebhookUrl(sourceUrl: String) = if (sourceUrl.contains("://")
|
||||
fun SetWebhook(
|
||||
url: String,
|
||||
certificate: MultipartFile,
|
||||
ipAddress: String? = null,
|
||||
maxAllowedConnections: Int? = null,
|
||||
allowedUpdates: List<String>? = null
|
||||
allowedUpdates: List<String>? = null,
|
||||
dropPendingUpdates: Boolean? = null
|
||||
): MultipartRequestImpl<SetWebhook, Map<String, MultipartFile>, Boolean> = MultipartRequestImpl(
|
||||
SetWebhook(
|
||||
correctWebhookUrl(url),
|
||||
null,
|
||||
null as String?,
|
||||
ipAddress,
|
||||
maxAllowedConnections,
|
||||
allowedUpdates
|
||||
allowedUpdates,
|
||||
dropPendingUpdates
|
||||
),
|
||||
mapOf(certificateField to certificate)
|
||||
)
|
||||
@ -31,47 +35,61 @@ fun SetWebhook(
|
||||
fun SetWebhook(
|
||||
url: String,
|
||||
certificate: FileId,
|
||||
ipAddress: String? = null,
|
||||
maxAllowedConnections: Int? = null,
|
||||
allowedUpdates: List<String>? = null
|
||||
allowedUpdates: List<String>? = null,
|
||||
dropPendingUpdates: Boolean? = null
|
||||
): SetWebhook = SetWebhook(
|
||||
correctWebhookUrl(url),
|
||||
certificate.fileId,
|
||||
ipAddress,
|
||||
maxAllowedConnections,
|
||||
allowedUpdates
|
||||
allowedUpdates,
|
||||
dropPendingUpdates
|
||||
)
|
||||
|
||||
/**
|
||||
* Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update
|
||||
* for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update.
|
||||
*
|
||||
* If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url],
|
||||
* e.g. https://www.example.com/<token>. Since nobody else knows your bot's token, you can be pretty sure it's us.
|
||||
*/
|
||||
@Suppress("USELESS_CAST")
|
||||
fun SetWebhook(
|
||||
url: String,
|
||||
certificate: InputFile,
|
||||
certificate: InputFile? = null,
|
||||
ipAddress: String? = null,
|
||||
maxAllowedConnections: Int? = null,
|
||||
allowedUpdates: List<String>? = null
|
||||
allowedUpdates: List<String>? = null,
|
||||
dropPendingUpdates: Boolean? = null
|
||||
): Request<Boolean> = when (certificate) {
|
||||
is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, maxAllowedConnections, allowedUpdates)
|
||||
is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, maxAllowedConnections, allowedUpdates)
|
||||
is MultipartFile -> SetWebhook(correctWebhookUrl(url), certificate as MultipartFile, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates)
|
||||
is FileId -> SetWebhook(correctWebhookUrl(url), certificate as FileId, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates)
|
||||
null -> SetWebhook(correctWebhookUrl(url), null as String?, ipAddress, maxAllowedConnections, allowedUpdates, dropPendingUpdates)
|
||||
}
|
||||
|
||||
fun SetWebhook(
|
||||
url: String,
|
||||
maxAllowedConnections: Int? = null,
|
||||
allowedUpdates: List<String>? = null
|
||||
) = SetWebhook(
|
||||
correctWebhookUrl(url),
|
||||
null,
|
||||
maxAllowedConnections,
|
||||
allowedUpdates
|
||||
)
|
||||
|
||||
/**
|
||||
* Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update
|
||||
* for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update.
|
||||
*
|
||||
* If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the [url],
|
||||
* e.g. https://www.example.com/<token>. Since nobody else knows your bot's token, you can be pretty sure it's us.
|
||||
*/
|
||||
@Serializable
|
||||
data class SetWebhook internal constructor(
|
||||
@SerialName(urlField)
|
||||
val url: String,
|
||||
@SerialName(certificateField)
|
||||
val certificateFile: String? = null,
|
||||
@SerialName(ipAddressField)
|
||||
val ipAddress: String? = null,
|
||||
@SerialName(maxAllowedConnectionsField)
|
||||
val maxAllowedConnections: Int? = null,
|
||||
@SerialName(allowedUpdatesField)
|
||||
val allowedUpdates: List<String>? = null
|
||||
val allowedUpdates: List<String>? = null,
|
||||
@SerialName(dropPendingUpdatesField)
|
||||
val dropPendingUpdates: Boolean? = null
|
||||
) : DataRequest<Boolean> {
|
||||
override fun method(): String = "setWebhook"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
|
@ -123,6 +123,7 @@ const val switchPmTextField = "switch_pm_text"
|
||||
const val switchPmParameterField = "switch_pm_parameter"
|
||||
const val maxAllowedConnectionsField = "max_connections"
|
||||
const val allowedUpdatesField = "allowed_updates"
|
||||
const val dropPendingUpdatesField = "drop_pending_updates"
|
||||
const val hasCustomCertificateField = "has_custom_certificate"
|
||||
const val pendingUpdateCountField = "pending_update_count"
|
||||
const val lastErrorDateField = "last_error_date"
|
||||
@ -143,6 +144,7 @@ const val inviteLinkField = "invite_link"
|
||||
const val pinnedMessageField = "pinned_message"
|
||||
const val customTitleField = "custom_title"
|
||||
const val optionIdsField = "option_ids"
|
||||
const val ipAddressField = "ip_address"
|
||||
|
||||
const val requestContactField = "request_contact"
|
||||
const val requestLocationField = "request_location"
|
||||
|
Loading…
Reference in New Issue
Block a user