webhooks: add ip_address and drop_pending_updates fields

This commit is contained in:
Nikita 2021-05-23 15:17:03 +03:00
parent cfe18bbec5
commit b7575fce70

View File

@ -49,6 +49,9 @@ type Webhook struct {
ErrorUnixtime int64 `json:"last_error_date"`
ErrorMessage string `json:"last_error_message"`
IpAddress string `json:"ip_address"`
DropPendingUpdates bool `json:"drop_pending_updates"`
TLS *WebhookTLS
Endpoint *WebhookEndpoint
@ -88,6 +91,12 @@ func (h *Webhook) getParams() map[string]string {
data, _ := json.Marshal(h.AllowedUpdates)
params["allowed_updates"] = string(data)
}
if h.IpAddress != "" {
params["ip_address"] = h.IpAddress
}
if h.DropPendingUpdates {
params["drop_pending_updates"] = strconv.FormatBool(h.DropPendingUpdates)
}
if h.TLS != nil {
params["url"] = "https://" + h.Listen
@ -178,7 +187,13 @@ func (b *Bot) SetWebhook(w *Webhook) error {
}
// RemoveWebhook removes webhook integration.
func (b *Bot) RemoveWebhook() error {
_, err := b.Raw("deleteWebhook", nil)
func (b *Bot) RemoveWebhook(dropPending ...bool) error {
drop := false
if len(dropPending) > 0 {
drop = dropPending[0]
}
_, err := b.Raw("deleteWebhook", map[string]bool{
"drop_pending_updates": drop,
})
return err
}