Skip to content

Commit

Permalink
webhook: implement getWebhookInfo method
Browse files Browse the repository at this point in the history
  • Loading branch information
demget committed May 5, 2020
1 parent 487fbc0 commit 1157f8b
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1157f8b

Please sign in to comment.