This repository has been archived by the owner on Sep 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builders.go
89 lines (81 loc) · 2.52 KB
/
builders.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
package airship
// MakePushTemplatePayload creates a new push template payload
func MakePushTemplatePayload(templateID string, channels []string, substitutions map[string]string) PushTemplatePayload {
return PushTemplatePayload{
Audience: AudienceSelector{Channels: channels},
DeviceTypes: []string{"ios", "android"},
MergeData: MergeData{
Substitutions: substitutions,
TemplateID: templateID,
},
}
}
// MakeSendPushPayload creates a new push template payload
func MakeSendPushPayload(templateID string, channels []string, substitutions map[string]string, options ...PushNotificationOption) PushObject {
notification := NotificationObject{
Android: &AndroidOverrideWithTemplate{
Template: &TemplateRef{TemplateID: templateID},
},
IOS: &IOSOverrideWithTemplate{
Template: &TemplateRef{TemplateID: templateID},
},
}
for _, fn := range options {
fn(¬ification)
}
return PushObject{
Audience: AudienceSelector{Channels: channels},
DeviceTypes: []string{"ios", "android"},
GlobalAttributes: substitutions,
Notification: notification,
}
}
//
// Mutator Config -- Experimental
//
// PushNotificationOption is a mutator-function based option for sending a push notification.
type PushNotificationOption = func(notif *NotificationObject)
// WithDeepLinkAction adds an Open Deep Link action to the notification.
func WithDeepLinkAction(deepURL, fallbackURL string) PushNotificationOption {
return func(notif *NotificationObject) {
if notif.Actions == nil {
notif.Actions = &Actions{}
}
notif.Actions.Open = &uaOpenAction{
Type: ActionTypeDeepLink,
Content: deepURL,
FallbackURL: fallbackURL,
}
}
}
// WithOpenURLAction adds an Open URL action to the notification.
func WithOpenURLAction(url string) PushNotificationOption {
return func(notif *NotificationObject) {
if notif.Actions == nil {
notif.Actions = &Actions{}
}
notif.Actions.Open = &uaOpenAction{
Type: ActionTypeOpenURL,
Content: url,
}
}
}
// WithExtra adds "extra" data to IOS & Android notification overrides.
func WithExtra(extra map[string]string) PushNotificationOption {
return func(notif *NotificationObject) {
if notif.Android != nil {
notif.Android.Extra = extra
}
if notif.IOS != nil {
notif.IOS.Extra = extra
}
}
}
// WithShortenLinks sets the ShortenLinks value on the SMS notification overrides.
func WithShortenLinks(value bool) PushNotificationOption {
return func(notif *NotificationObject) {
if notif.Sms != nil {
notif.Sms.ShortenLinks = value
}
}
}