-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsubscriptions.go
More file actions
47 lines (41 loc) · 1.42 KB
/
subscriptions.go
File metadata and controls
47 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package maxigo
import (
"context"
"net/http"
"net/url"
)
// Subscribe sets up a WebHook subscription for the bot.
// Corresponds to POST /subscriptions.
func (c *Client) Subscribe(ctx context.Context, webhookURL string, updateTypes []string, secret string) (*SimpleQueryResult, error) {
body := SubscriptionRequestBody{
URL: webhookURL,
UpdateTypes: updateTypes,
Secret: secret,
}
var result SimpleQueryResult
if err := c.do(ctx, "Subscribe", http.MethodPost, "/subscriptions", nil, body, &result); err != nil {
return nil, err
}
return &result, nil
}
// Unsubscribe removes a WebHook subscription.
// After calling this method, long polling becomes available again.
// Corresponds to DELETE /subscriptions.
func (c *Client) Unsubscribe(ctx context.Context, webhookURL string) (*SimpleQueryResult, error) {
q := make(url.Values)
q.Set("url", webhookURL)
var result SimpleQueryResult
if err := c.do(ctx, "Unsubscribe", http.MethodDelete, "/subscriptions", q, nil, &result); err != nil {
return nil, err
}
return &result, nil
}
// GetSubscriptions returns all active WebHook subscriptions.
// Corresponds to GET /subscriptions.
func (c *Client) GetSubscriptions(ctx context.Context) ([]Subscription, error) {
var result getSubscriptionsResult
if err := c.do(ctx, "GetSubscriptions", http.MethodGet, "/subscriptions", nil, nil, &result); err != nil {
return nil, err
}
return result.Subscriptions, nil
}