-
Notifications
You must be signed in to change notification settings - Fork 14
/
viber_service.go
181 lines (158 loc) · 6.12 KB
/
viber_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
package sendpulse_sdk_go
import (
"context"
"fmt"
"net/http"
)
type ViberService struct {
client *Client
}
func newViberService(cl *Client) *ViberService {
return &ViberService{client: cl}
}
type CreateViberCampaignParams struct {
TaskName string `json:"task_name"`
MessageType int `json:"message_type,omitempty"`
SenderID int `json:"sender_id"`
MessageLiveTime int `json:"message_live_time"`
SendDate DateTimeType `json:"send_date"`
MailingListID int `json:"address_book"`
Recipients []int `json:"recipients"`
Message string `json:"message"`
Additional *struct {
Button *struct {
Text string `json:"text"`
Link string `json:"link"`
} `json:"button,omitempty"`
Image *struct {
Link string `json:"link"`
} `json:"image,omitempty"`
ResendSms *struct {
Status bool `json:"status"`
SmsText string `json:"sms_text"`
SmsSenderName string `json:"sms_sender_name"`
} `json:"resend_sms,omitempty"`
} `json:"additional,omitempty"`
}
func (service *ViberService) CreateCampaign(ctx context.Context, params CreateViberCampaignParams) (int, error) {
path := "/viber"
var respData struct {
Result bool `json:"result"`
Data struct {
TaskID int `json:"task_id"`
} `json:"data"`
}
_, err := service.client.newRequest(ctx, http.MethodPost, path, params, &respData, true)
return respData.Data.TaskID, err
}
type UpdateViberCampaignParams struct {
TaskID int `json:"main_task_id"`
TaskName string `json:"task_name"`
Message string `json:"message"`
MessageType int `json:"message_type"`
ButtonText string `json:"button_text,omitempty"`
ButtonLink string `json:"button_link,omitempty"`
ImageLink string `json:"image_link,omitempty"`
AddressBookID int `json:"address_book,omitempty"`
SenderID int `json:"sender_id"`
MessageLiveTime int `json:"message_live_time"`
SendDate DateTimeType `json:"send_date"`
}
func (service *ViberService) UpdateCampaign(ctx context.Context, params UpdateViberCampaignParams) error {
path := "/viber/update"
var respData struct {
Result bool `json:"result"`
}
_, err := service.client.newRequest(ctx, http.MethodPost, path, params, &respData, true)
return err
}
type ViberCampaign struct {
ID int `json:"id"`
Name string `json:"name"`
Message string `json:"message"`
ButtonText string `json:"button_text"`
ButtonLink string `json:"button_link"`
ImageLink string `json:"image_link"`
AddressBookID int `json:"address_book"`
SenderName string `json:"sender_name"`
SenderID int `json:"sender_id"`
MessageLiveTime int `json:"message_live_time"`
SendDate DateTimeType `json:"send_date"`
Status string `json:"status"`
Created DateTimeType `json:"created"`
}
func (service *ViberService) GetCampaigns(ctx context.Context, limit, offset int) ([]*ViberCampaign, error) {
path := fmt.Sprintf("/viber/task?limit=%d&offset=%d", limit, offset)
var respData []*ViberCampaign
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData, err
}
type ViberCampaignStatistics struct {
ID int `json:"id"`
Name string `json:"name"`
Message string `json:"message"`
ButtonText string `json:"button_text"`
ButtonLink string `json:"button_link"`
ImageLink string `json:"image_link"`
AddressBookID int `json:"address_book"`
SenderName string `json:"sender_name"`
SendDate DateTimeType `json:"send_date"`
Status string `json:"status"`
Statistics struct {
Sent int `json:"sent"`
Delivered int `json:"delivered"`
Read int `json:"read"`
Redirected int `json:"redirected"`
Undelivered int `json:"undelivered"`
Errors int `json:"errors"`
} `json:"statistic"`
Created DateTimeType `json:"created"`
}
func (service *ViberService) GetStatistics(ctx context.Context, campaignID int) (*ViberCampaignStatistics, error) {
path := fmt.Sprintf("/viber/task/%d", campaignID)
var respData *ViberCampaignStatistics
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData, err
}
type ViberSender struct {
ID int `json:"id"`
Status string `json:"status"`
Name string `json:"name"`
ServiceType string `json:"service_type"`
WebSite string `json:"web_site"`
Description string `json:"description"`
Countries []string `json:"countries"`
TrafficType string `json:"traffic_type"`
AdminComment string `json:"admin_comment"`
Owner string `json:"owner"`
}
func (service *ViberService) GetSenders(ctx context.Context) ([]*ViberSender, error) {
path := "/viber/senders"
var respData []*ViberSender
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData, err
}
func (service *ViberService) GetSender(ctx context.Context, senderID int) (*ViberSender, error) {
path := fmt.Sprintf("/viber/senders/%d", senderID)
var respData *ViberSender
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData, err
}
type ViberRecipient struct {
Phone int `json:"phone"`
AddressBookID int `json:"address_book_id"`
Status string `json:"status"`
SendDate DateTimeType `json:"send_date"`
Price float32 `json:"price"`
Currency string `json:"currency"`
LastUpdate DateTimeType `json:"last_update"`
}
func (service *ViberService) GetRecipients(ctx context.Context, taskID int) ([]*ViberRecipient, error) {
path := fmt.Sprintf("/viber/task/%d/recipients", taskID)
var respData struct {
TaskID int `json:"task_id"`
Recipients []*ViberRecipient `json:"recipients"`
}
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return respData.Recipients, err
}