-
Notifications
You must be signed in to change notification settings - Fork 10
/
example_events.go
117 lines (106 loc) · 3.45 KB
/
example_events.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package util
import (
"encoding/json"
"fmt"
"os"
"path"
"github.com/grokify/chathooks/pkg/config"
)
const (
DefaultExtension = "json"
)
type ExampleData struct {
Data map[string]ExampleSource `json:"data,omitempty"`
}
type ExampleSource struct {
FileExtension string `json:"file_extension,omitempty"`
EventSlugs []string `json:"event_slugs,omitempty"`
}
func NewExampleData() (ExampleData, error) {
data := ExampleData{}
err := json.Unmarshal(ExampleDataRaw(), &data)
return data, err
}
func ExampleDataRaw() []byte {
return []byte(`{
"data": {
"appsignal": {
"file_extension": "json",
"event_slugs": ["marker","exception","performance"]
},
"apteligent":{
"event_slugs": ["alert","alert-open","alert-close"]
},
"bugsnag":{
"event_slugs": ["exception-stack-trace-single","exception-stack-trace-multi","exception-error-message-long"]
},
"confluence":{
"event_slugs": ["page-created","comment-created"]
},
"deskdotcom":{
"event_slugs": ["formatted1","formatted2"]
},
"gosquared":{
"event_slugs": ["site-traffic","smart-group","live-chat"]
},
"heroku":{
"file_extension": "txt",
"event_slugs":["build"]
},
"librato":{
"event_slugs":["2","alert-triggered","alert-cleared"]
},
"marketo":{
"event_slugs":["formatted1","formatted2","demo1"]
},
"opsgenie":{
"event_slugs_":["create","close","delete",
"acknowledge","unacknowledge"],
"event_slugs__": [
"add-note","add-recipient","add-tags","add-team"],
"event_slugs":["remove-tags","assign-ownership","take-ownership", "escalate",
"custom-action-test-action"]
},
"papertrail":{
"event_slugs":["notifications-array-len-1","notifications-array"]
},
"pingdom":{
"event_slugs":["http-check"],
"event_slugs_":["dns-check","http-check","http-custom-check","imap-check","ping-check","pop3-check","smtp-check","tcp-check","transaction-check","udp-check"]
},
"semaphore":{
"event_slugs":["build","deploy"]
},
"slack":{
"event_slugs":["attachment","link-emoji"]
},
"statuspage":{
"event_slugs":["incident-updates","incident-updates-create","component-updates"]
},
"userlike":{
"event_slugs_":["chat-meta_feedback","chat-meta_forward","chat-meta_rating","chat-meta_receive","chat-meta_start","chat-meta_survey"],
"event_slugs":["chat-widget_config","offline-message_receive","operator_away","operator_back","operator_offline","operator_online"]
},
"wootric":{
"file_extension": "txt",
"event_slugs":["decline-created","response-created"]
}
}
}`)
}
func (data *ExampleData) ExampleMessageBytes(handlerKey string, eventSlug string) ([]byte, error) {
filepath := path.Join(
config.DocsHandlersDir(),
handlerKey,
data.BuildFilename(handlerKey, eventSlug))
return os.ReadFile(filepath)
}
func (data *ExampleData) BuildFilename(handlerKey string, eventSlug string) string {
ext := DefaultExtension
if src, ok := data.Data[handlerKey]; ok {
if len(src.FileExtension) > 0 {
ext = src.FileExtension
}
}
return fmt.Sprintf("event-example_%s.%s", eventSlug, ext)
}