-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.go
55 lines (49 loc) · 1.48 KB
/
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
package rchooks
import (
"fmt"
"strings"
)
const (
EventFilterExtension = "/restapi/v1.0/account/~/extension/~"
EventFilterMessagePosts = "/restapi/v1.0/glip/posts"
EventFilterMessageGroups = "/restapi/v1.0/glip/groups"
EventFilterSmsInbound = "/restapi/v1.0/account/~/a2p-sms/messages?direction=Inbound"
EventFilterSmsBatch = "/restapi/v1.0/account/~/a2p-sms/batch"
EventFilterSmsOptOuts = "/restapi/v1.0/account/~/a2p-sms/opt-outs"
SlugExtension = "extension"
SlugMessageGroups = "msggroups"
SlugMessagePosts = "msgposts"
SlugSmsBatch = "a2psmsbatch"
SlugSmsInbound = "a2psmsinbound"
SlugSmsOptOuts = "a2psmsoptouts"
)
func SlugToFilterMap() map[string]string {
return map[string]string{
SlugMessageGroups: EventFilterMessageGroups,
SlugMessagePosts: EventFilterMessagePosts,
SlugSmsBatch: EventFilterSmsBatch,
SlugSmsInbound: EventFilterSmsInbound,
SlugSmsOptOuts: EventFilterSmsOptOuts}
}
func ConvertEvent(slug string) (string, error) {
slug = strings.ToLower(strings.TrimSpace(slug))
if strings.Index(slug, "/") == 0 {
return slug, nil
}
s2f := SlugToFilterMap()
if filter, ok := s2f[slug]; ok {
return filter, nil
}
return "", fmt.Errorf("slug not found [%s]", slug)
}
func ConvertEvents(slugs ...string) ([]string, error) {
filters := []string{}
for _, slug := range slugs {
filter, err := ConvertEvent(slug)
if err != nil {
return filters, err
}
filters = append(filters, filter)
}
return filters, nil
}