-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwebhook_service.go
More file actions
38 lines (31 loc) · 971 Bytes
/
webhook_service.go
File metadata and controls
38 lines (31 loc) · 971 Bytes
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
package httpsms
import (
"context"
"encoding/json"
"net/http"
)
// WebhookService is the API client for the webhook endpoints
type WebhookService service
// WebhookStoreParams is the request payload for creating a webhook
type WebhookStoreParams struct {
SigningKey string `json:"signing_key"`
URL string `json:"url"`
PhoneNumbers []string `json:"phone_numbers"`
Events []string `json:"events"`
}
// Store adds a new webhook
func (service *WebhookService) Store(ctx context.Context, params *WebhookStoreParams) (*WebhookResponse, *Response, error) {
request, err := service.client.newRequest(ctx, http.MethodPost, "/v1/webhooks", params)
if err != nil {
return nil, nil, err
}
response, err := service.client.do(request)
if err != nil {
return nil, response, err
}
webhook := new(WebhookResponse)
if err = json.Unmarshal(*response.Body, webhook); err != nil {
return nil, response, err
}
return webhook, response, nil
}