From 1157f8b301813dfdc61495f9a12867baf0dd62ad Mon Sep 17 00:00:00 2001 From: Demian Date: Tue, 5 May 2020 20:41:30 +0300 Subject: [PATCH] webhook: implement getWebhookInfo method --- webhook.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/webhook.go b/webhook.go index 8d430a52..63f1fa17 100644 --- a/webhook.go +++ b/webhook.go @@ -36,9 +36,15 @@ type WebhookEndpoint struct { // You can also leave the Listen field empty. In this case it is up to the caller to // add the Webhook to a http-mux. type Webhook struct { - Listen string - MaxConnections int - AllowedUpdates []string + Listen string `json:"url"` + MaxConnections int `json:"max_conecctions"` + AllowedUpdates []string `json:"allowed_updates"` + + // (WebhookInfo) + HasCustomCert bool `json:"has_custom_certificate"` + PendingUpdates int `json:"pending_update_count"` + ErrorUnixtime int64 `json:"last_error_date"` + ErrorMessage string `json:"last_error_message"` TLS *WebhookTLS Endpoint *WebhookEndpoint @@ -145,6 +151,22 @@ func (h *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.dest <- update } +// GetWebhook returns current webhook status. +func (b *Bot) GetWebhook() (*Webhook, error) { + data, err := b.Raw("getWebhookInfo", nil) + if err != nil { + return nil, err + } + + var resp struct { + Webhook Webhook + } + if err := json.Unmarshal(data, &resp); err != nil { + return nil, err + } + return &resp.Webhook, nil +} + // SetWebhook configures a bot to receive incoming // updates via an outgoing webhook. func (b *Bot) SetWebhook(w *Webhook) error {