-
Notifications
You must be signed in to change notification settings - Fork 2
/
messaging.go
208 lines (180 loc) · 9.26 KB
/
messaging.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package braze
import (
"context"
"net/http"
)
const (
messagingMessagesSendPath = "/messages/send"
messagingTransactionalSendPath = "/transactional/v1/campaigns/%s/send"
messagingCampaignsTriggerSendPath = "/campaigns/trigger/send"
)
var (
ApplePushMessageInterruptionLevelPassive ApplePushMessageInterruptionLevel = "passive"
ApplePushMessageInterruptionLevelActive ApplePushMessageInterruptionLevel = "active"
ApplePushMessageInterruptionLevelTimeSensitive ApplePushMessageInterruptionLevel = "time-sensitive"
ApplePushMessageInterruptionLevelCritical ApplePushMessageInterruptionLevel = "critical"
ApplePushMessageFileTypeAIF ApplePushMessageFileType = "aif"
ApplePushMessageFileTypeGIF ApplePushMessageFileType = "gif"
ApplePushMessageFileTypeJPG ApplePushMessageFileType = "jpg"
ApplePushMessageFileTypeM4A ApplePushMessageFileType = "m4a"
ApplePushMessageFileTypeMP3 ApplePushMessageFileType = "mp3"
ApplePushMessageFileTypeMP4 ApplePushMessageFileType = "mp4"
ApplePushMessageFileTypePNG ApplePushMessageFileType = "png"
ApplePushMessageFileTypeWAV ApplePushMessageFileType = "wav"
)
type MessagingEndpoint interface {
SendMessages(context.Context, *SendMessagesRequest) (*Response, error)
TriggerCampaign(context.Context, *TriggerCampaignRequest) (*Response, error)
}
var _ MessagingEndpoint = (*MessagingService)(nil)
type MessagingService struct {
client *Client
}
func (s *MessagingService) SendMessages(ctx context.Context, r *SendMessagesRequest) (*Response, error) {
req, err := s.client.http.newRequest(http.MethodPost, messagingMessagesSendPath, r)
if err != nil {
return nil, err
}
var res Response
if err := s.client.http.do(ctx, req, &res); err != nil {
return nil, err
}
return &res, nil
}
func (s *MessagingService) TriggerCampaign(ctx context.Context, r *TriggerCampaignRequest) (*Response, error) {
req, err := s.client.http.newRequest(http.MethodPost, messagingCampaignsTriggerSendPath, r)
if err != nil {
return nil, err
}
var res Response
if err := s.client.http.do(ctx, req, &res); err != nil {
return nil, err
}
return &res, nil
}
type SendMessagesRequest struct {
Messages *Messages
}
type Messages struct {
AndroidPush *AndroidPushMessage
ApplePush *ApplePushMessage
Email *EmailMessage
}
// https://www.braze.com/docs/api/objects_filters/messaging/android_object/
type AndroidPushMessage struct {
Alert string `json:"alert"`
Title string `json:"title"`
Extra *string `json:"extra,omitempty"`
MessageVariationID *string `json:"message_variation_id,omitempty"`
NotificationChannelID *string `json:"notification_channel_id,omitempty"`
Priority *int `json:"priority,omitempty"`
SendToSync *bool `json:"send_to_sync,omitempty"`
CollapseKey *string `json:"collapse_key,omitempty"`
Sound *string `json:"sound,omitempty"`
CustomURI *string `json:"custom_uri,omitempty"`
SummaryText *string `json:"summary_text,omitempty"`
TimeToLive *int `json:"time_to_live,omitempty"`
NotificationID *int `json:"notification_id,omitempty"`
PushIconImageURL *string `json:"push_icon_image_url,omitempty"`
AccentColor *int `json:"accent_color,omitempty"`
SendToMostRecentDeviceOnly *bool `json:"send_to_most_recent_device_only,omitempty"`
Buttons []*AndroidPushActionButton `json:"buttons,omitempty"`
ConversationData []*AndroidPushConversationData `json:"conversation_data,omitempty"`
}
type AndroidPushActionButton struct {
Text string `json:"text"`
Action *string `json:"action,omitempty"`
URI *string `json:"uri,omitempty"`
UseWebview *string `json:"use_webview,omitempty"`
}
type AndroidPushConversationData struct {
ShortcutID string `json:"shortcut_id"`
ReplyPersonID string `json:"reply_person_id"`
Messages []*AndroidPushConversationMessage `json:"messages"`
Persons []*AndroidPushConversationPerson `json:"persons"`
}
type AndroidPushConversationMessage struct {
Text string `json:"text"`
Timestamp int `json:"timestamp"`
PersonID string `json:"person_id"`
}
type AndroidPushConversationPerson struct {
ID string `json:"id"`
Name string `json:"name"`
}
// https://www.braze.com/docs/api/objects_filters/messaging/apple_object/
type ApplePushMessage struct {
Badge *int `json:"badge,omitempty"`
Alert *ApplePushAlert `json:"alert,omitempty"`
Sound *string `json:"sound,omitempty"`
Extra *string `json:"extra,omitempty"`
ContentAvailable *bool `json:"content-available,omitempty"`
InterruptionLevel *ApplePushMessageInterruptionLevel `json:"interruption_level,omitempty"`
RelevanceScore *float64 `json:"relevance_score,omitempty"`
Expiry *string `json:"expiry,omitempty"`
CustomURI *string `json:"custom_uri,omitempty"`
MessageVariationID *string `json:"message_variation_id,omitempty"`
NotificationGroupThreadID *string `json:"notification_group_thread_id,omitempty"`
AssetURL *string `json:"asset_url,omitempty"`
AssetFileType *ApplePushMessageFileType `json:"asset_file_type,omitempty"`
CollapseID *string `json:"collapse_id,omitempty"`
MutableContent *bool `json:"mutable_content,omitempty"`
SendToMostRecentDeviceOnly *bool `json:"send_to_most_recent_device_only,omitempty"`
Category *string `json:"category,omitempty"`
Buttons []*ApplePushActionButton `json:"buttons,omitempty"`
}
type ApplePushAlert struct {
Body string `json:"body"`
Title *string `json:"title,omitempty"`
TitleLocKey *string `json:"title_loc_key,omitempty"`
TitleLocArgs []string `json:"title_loc_args,omitempty"`
ActionLocKey *string `json:"action_loc_key,omitempty"`
LocKey *string `json:"loc_key,omitempty"`
LocArgs []*string `json:"loc_args,omitempty"`
}
type (
ApplePushMessageInterruptionLevel string
ApplePushMessageFileType string
)
type ApplePushActionButton struct {
ActionID string `json:"action_id"`
Action string `json:"action"`
URI string `json:"uri"`
UseWebview *bool `json:"use_webview,omitempty"`
}
// https://www.braze.com/docs/api/objects_filters/messaging/email_object/
type EmailMessage struct {
AppID string `json:"app_id"`
Subject *string `json:"subject,omitempty"`
From string `json:"from"`
ReplyTo *string `json:"reply_to,omitempty"`
BCC *string `json:"bcc,omitempty"`
Body *string `json:"body,omitempty"`
PlaintextBody *string `json:"plaintext_body,omitempty"`
PreHeader *string `json:"preheader,omitempty"`
EmailTemplateID *string `json:"email_template_id,omitempty"`
MessageVariationID *string `json:"message_variation_id,omitempty"`
Extras map[string]interface{} `json:"extras,omitempty"`
Headers map[string]interface{} `json:"headers,omitempty"`
ShouldInlineCSS *bool `json:"should_inline_css,omitempty"`
Attachments []*EmailMessageAttachment `json:"attachments,omitempty"`
}
type EmailMessageAttachment struct {
FileName string `json:"file_name"`
URL string `json:"url"`
}
type TriggerCampaignRequest struct {
CampaignID string `json:"campaign_id,omitempty"`
SendID *string `json:"send_id,omitempty"`
TriggerProperties map[string]interface{} `json:"trigger_properties,omitempty"`
Broadcast *bool `json:"broadcast,omitempty"`
Recipients []*Recipient `json:"recipients,omitempty"`
// Audience TODO
}
type Recipient struct {
UserAlias *UserAlias `json:"user_alias,omitempty"`
ExternalUserID *string `json:"external_user_id,omitempty"`
TriggerProperties map[string]interface{} `json:"trigger_properties,omitempty"`
CanvasEntryProperties map[string]interface{} `json:"canvas_entry_properties,omitempty"`
SendToExistingOnly *bool `json:"send_to_existing_only,omitempty"`
}