forked from PagerDuty/go-pagerduty
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webhook.go
37 lines (33 loc) · 1.31 KB
/
webhook.go
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
package pagerduty
import (
"encoding/json"
"io"
)
// IncidentDetail contains a representation of the incident associated with the action that caused this webhook message.
type IncidentDetail struct {
ID string `json:"id"`
IncidentNumber uint `json:"incident_number"`
CreatedOn string `json:"created_on"`
Status string `json:"status"`
HTMLUrl string `json:"html_url"`
Service string `json:"service"`
AssignedToUser *json.RawMessage `json:"assigned_to_user"`
AssignedTo []string `json:"assigned_to"`
TriggerSummaryData *json.RawMessage `json:"trigger_summary_data"`
TriggerDetailsHTMLUrl string `json:"trigger_details_html_url"`
}
// WebhookPayload is a single message array for a webhook.
type WebhookPayload struct {
ID string `json:"id"`
Type string `json:"type"`
CreatedOn string `json:"created_on"`
Data *json.RawMessage `json:"data"`
}
// DecodeWebhook decodes a webhook from a response object.
func DecodeWebhook(r io.Reader) (*WebhookPayload, error) {
var payload WebhookPayload
if err := json.NewDecoder(r).Decode(&payload); err != nil {
return nil, err
}
return &payload, nil
}