-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathautomation360_service.go
307 lines (266 loc) · 10.7 KB
/
automation360_service.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
package sendpulse_sdk_go
import (
"context"
"fmt"
"net/http"
)
// Automation360Service is a service to interact with conversions
type Automation360Service struct {
client *Client
}
// newAutomation360Service creates Automation360Service
func newAutomation360Service(cl *Client) *Automation360Service {
return &Automation360Service{client: cl}
}
// Autoresponder represents statistics about an automation flow
type Autoresponder struct {
Autoresponder struct {
ID int `json:"id"`
Name string `json:"name"`
Status int `json:"status"`
Created DateTime `json:"created"`
Changed DateTime `json:"changed"`
} `json:"autoresponder"`
Flows []*struct {
ID int `json:"id"`
MainID int `json:"main_id"`
AfType string `json:"af_type"`
Created DateTime `json:"created"`
LastSend DateTime `json:"last_send"`
Task map[string]any `json:"task"`
} `json:"flows"`
Starts int `json:"starts"`
InQueue int `json:"in_queue"`
EndCount int `json:"end_count"`
SendMessages int `json:"send_messages"`
Conversions int `json:"conversions"`
}
// GetAutoresponderStatistics returns statistics about an automation flow
func (service *Automation360Service) GetAutoresponderStatistics(ctx context.Context, id int) (*Autoresponder, error) {
path := fmt.Sprintf("/a360/autoresponders/%d", id)
var respData *Autoresponder
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData, err
}
// StartEvent sends event to SendPulse
func (service *Automation360Service) StartEvent(ctx context.Context, eventName string, variables map[string]any) error {
path := fmt.Sprintf("/events/name/%s", eventName)
var respData struct {
Result bool `json:"result"`
}
_, err := service.client.newRequest(ctx, http.MethodPost, path, variables, &respData, true)
return err
}
// MainTriggerBlockStat represents statistics about the "Start" element
type MainTriggerBlockStat struct {
FlowID int `json:"flow_id"`
Executed int `json:"executed"`
Deleted int `json:"deleted"`
}
// GetStartBlockStatistics returns statistics about the "Start" element
func (service *Automation360Service) GetStartBlockStatistics(ctx context.Context, id int) (*MainTriggerBlockStat, error) {
path := fmt.Sprintf("/a360/stats/main-trigger/%d/group-stat", id)
var respData struct {
Data *MainTriggerBlockStat `json:"data"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}
// EmailBlockStat represents statistics about the "Email" element
type EmailBlockStat struct {
FlowID int `json:"flow_id"`
Task struct {
ID int `json:"id"`
MailingListID int `json:"address_book_id"`
MessageTitle string `json:"message_title"`
SenderMailAddress string `json:"sender_mail_address"`
SenderMailName string `json:"sender_mail_name"`
Created DateTime `json:"created"`
} `json:"task"`
Sent int `json:"sent"`
Delivered int `json:"delivered"`
Opened int `json:"opened"`
Clicked int `json:"clicked"`
Errors int `json:"errors"`
Unsubscribed int `json:"unsubscribed"`
MarkedAsSpam int `json:"marked_as_spam"`
LastSend DateTime `json:"last_send"`
}
// GetEmailBlockStatistics returns statistics about the "Email" element
func (service *Automation360Service) GetEmailBlockStatistics(ctx context.Context, id int) (*EmailBlockStat, error) {
path := fmt.Sprintf("/a360/stats/email/%d/group-stat", id)
var respData struct {
Data *EmailBlockStat `json:"data"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}
// PushBlockStat represents statistics about the "Push" element
type PushBlockStat struct {
FlowID int `json:"flow_id"`
Sent int `json:"sent"`
Delivered int `json:"delivered"`
Clicked int `json:"clicked"`
Errors int `json:"errors"`
LastSend DateTime `json:"last_send"`
}
// GetPushBlockStatistics returns statistics about the "Push" element
func (service *Automation360Service) GetPushBlockStatistics(ctx context.Context, id int) (*PushBlockStat, error) {
path := fmt.Sprintf("/a360/stats/push/%d/group-stat", id)
var respData struct {
Data *PushBlockStat `json:"data"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}
// SmsBlockStat represents statistics about the "SMS" element
type SmsBlockStat struct {
FlowID int `json:"flow_id"`
Executed int `json:"executed"`
Sent int `json:"sent"`
Delivered int `json:"delivered"`
Opened int `json:"opened"`
Clicked int `json:"clicked"`
Errors int `json:"errors"`
LastSend DateTime `json:"last_send"`
}
// GetSmsBlockStatistics returns statistics about the "SMS" element
func (service *Automation360Service) GetSmsBlockStatistics(ctx context.Context, id int) (*SmsBlockStat, error) {
path := fmt.Sprintf("/a360/stats/sms/%d/group-stat", id)
var respData struct {
Data *SmsBlockStat `json:"data"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}
// MessengerBlockStat represents statistics about the "Messenger" element
type MessengerBlockStat struct {
FlowID int `json:"flow_id"`
Executed int `json:"executed"`
Sent int `json:"sent"`
LastSend DateTime `json:"last_send"`
}
// GetMessengerBlockStatistics returns statistics about the "Messenger" element
func (service *Automation360Service) GetMessengerBlockStatistics(ctx context.Context, id int) (*MessengerBlockStat, error) {
path := fmt.Sprintf("/a360/stats/messenger/%d/group-stat", id)
var respData struct {
Data *MessengerBlockStat `json:"data"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}
// FilterBlockStat represents statistics about the "Filter" element
type FilterBlockStat struct {
FlowID int `json:"flow_id"`
Executed int `json:"executed"`
LastSend DateTime `json:"last_send"`
}
// GetFilterBlockStatistics returns statistics about the "Filter" element
func (service *Automation360Service) GetFilterBlockStatistics(ctx context.Context, id int) (*FilterBlockStat, error) {
path := fmt.Sprintf("/a360/stats/filter/%d/group-stat", id)
var respData struct {
Data *FilterBlockStat `json:"data"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}
// TriggerBlockStat represents statistics about the "Condition" element
type TriggerBlockStat struct {
FlowID int `json:"flow_id"`
Executed int `json:"executed"`
LastSend DateTime `json:"last_send"`
}
// GetTriggerBlockStatistics returns statistics about the "Condition" element
func (service *Automation360Service) GetTriggerBlockStatistics(ctx context.Context, id int) (*TriggerBlockStat, error) {
path := fmt.Sprintf("/a360/stats/trigger/%d/group-stat", id)
var respData struct {
Data *TriggerBlockStat `json:"data"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}
// GoalBlockStat represents statistics about the "Goal" element
type GoalBlockStat struct {
FlowID int `json:"flow_id"`
Executed int `json:"executed"`
Sent int `json:"sent"`
Delivered int `json:"delivered"`
Opened int `json:"opened"`
Clicked int `json:"clicked"`
Errors int `json:"errors"`
LastSend DateTime `json:"last_send"`
}
// GetGoalBlockStatistics returns statistics about the "Goal" element
func (service *Automation360Service) GetGoalBlockStatistics(ctx context.Context, id int) (*GoalBlockStat, error) {
path := fmt.Sprintf("/a360/stats/goal/%d/group-stat", id)
var respData struct {
Data *GoalBlockStat `json:"data"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}
// ActionBlockStat represents statistics about the "Action" element
type ActionBlockStat struct {
FlowID int `json:"flow_id"`
Executed int `json:"executed"`
LastSend DateTime `json:"last_send"`
}
// GetActionBlockStatistics returns statistics about the "Action" element
func (service *Automation360Service) GetActionBlockStatistics(ctx context.Context, id int) (*ActionBlockStat, error) {
path := fmt.Sprintf("/a360/stats/action/%d/group-stat", id)
var respData struct {
Data *ActionBlockStat `json:"data"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}
// AutoresponderConversion represents the flow conversion
type AutoresponderConversion struct {
TotalConversions int `json:"total_conversions"`
MaintriggerConversions int `json:"maintrigger_conversions"`
GoalConversions int `json:"goal_conversions"`
Maintrigger struct {
ID int `json:"id"`
MainID int `json:"main_id"`
AfType string `json:"af_type"`
Created DateTime `json:"created"`
LastSend DateTime `json:"last_send"`
Conversions int `json:"conversions"`
} `json:"maintrigger"`
Goals []struct {
ID int `json:"id"`
Name string `json:"name"`
MainID int `json:"main_id"`
AfType string `json:"af_type"`
Created DateTime `json:"created"`
Conversions int `json:"conversions"`
} `json:"goals"`
}
// GetAutoresponderConversions returns the flow conversions list
func (service *Automation360Service) GetAutoresponderConversions(ctx context.Context, id int) (*AutoresponderConversion, error) {
path := fmt.Sprintf("/a360/autoresponders/%d/conversions", id)
var respData struct {
Data *AutoresponderConversion `json:"data"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData.Data, err
}
// AutoresponderContact represents the contact that converted
type AutoresponderContact struct {
ID int `json:"id"`
ConversionType string `json:"conversion_type"`
FlowID int `json:"flow_id"`
Email string `json:"email"`
Phone string `json:"phone"`
ConversionDate DateTime `json:"conversion_date"`
StartDate DateTime `json:"start_date"`
}
// GetAutoresponderContacts returns a list of the contacts that converted
func (service *Automation360Service) GetAutoresponderContacts(ctx context.Context, id int) ([]*AutoresponderContact, error) {
path := fmt.Sprintf("/a360/autoresponders/%d/conversions/list/all", id)
var respData struct {
Items []*AutoresponderContact `json:"items"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData.Items, err
}