-
Notifications
You must be signed in to change notification settings - Fork 0
/
mymobileapi.go
190 lines (181 loc) · 9.98 KB
/
mymobileapi.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
package mymobileapi
// The SMS message that should be sent. Must contain at least one message and at most 100 messages.
type Message struct {
// The textual content of the SMS message
Content string `json:"content"`
// The MSISDN (mobile number) to whom the messages is intended
Destination string `json:"destination"`
// A user defined ID which can be used to correlate messages sent to the API and receipts or replies
// received for that message. Maximum length 100 characters
CustomerId string `json:"customerId,omitempty"`
// Variables related to the generation of a mobile document associated with a specific SMS message, and document template.
Document struct {
// The API template name related to the document template.
Template string `json:"template,omitempty"`
// The version of the document template to use. If not provided then the configured default (active) version is used.
Version int `json:"version,omitempty"`
// The authentication password for the document.
// If not provided (Empty or Null) then the document will not require authentication.
Password string `json:"password,omitempty"`
// The values of the variables defined in the document template.
Variables interface{} `json:"variables,omitempty"`
} `json:"document,omitempty"`
}
// BulkMessageRequest is a request to send a batch of SMS messages
type BulkMessageRequest struct {
// A number of optional settings for a send
SendOptions struct {
// The sender ID (source address) to use when sending the messages specified. Maximum length is 11 characters.
// Please note that a best effort is made to use the value specified but availability is ultimately
// determined by the mobile network operator
SenderId string `json:"senderId,omitempty"`
// The type of duplication check to use (Defaults to 'None')
DuplicateCheck string `json:"duplicateCheck,omitempty"`
// The date and time in UTC when the messages should be sent.
// Maximum date and time allowed is 3 months from the current date and time.
// Value should be formatted according to ISO 8601 UTC format (yyyy-mm-ddThh:mm[:ss][Z])
StartDeliveryUtc string `json:"startDeliveryUtc,omitempty"`
// This value should be set in UTC if delivery should be staggered over a period of time.
// Leave null if all messages should be sent as soon as possible.
// Value, if set, must be greater than StartDeliveryUtc
// and should be formatted according to ISO 8601 UTC format (yyyy-mm-ddThh:mm[:ss][Z])
EndDeliveryUtc string `json:"endDeliveryUtc,omitempty"`
// The name of the reply rule set that should be used for the send. Replies that are received as a result of
// the send are then subject to rules configured in the reply rule set governing auto forwards and auto
// responses
ReplyRuleSetName string `json:"replyRuleSetName,omitempty"`
// A user defined value for the name of the campaign associated with this send. Only used by the system for
// reporting purposes. Maximum value is 100 characters
CampaignName string `json:"campaignName,omitempty"`
// A user defined value for the name of the cost center associated with this send. Only used by the system for
// reporting purposes. Maximum value is 100 characters
CostCentre string `json:"costCentre,omitempty"`
// True if SMS messages should not be sent to mobile subscribers that have opted-out as a result of a previous
// send; otherwise false
CheckOptOuts bool `json:"checkOptOuts,omitempty"`
// True if this send should try shorten and track urls otherwise false.
ShortenUrls bool `json:"shortenUrls,omitempty"`
// The amount of time in hours an SMS should remain valid.
// The network will continue to try to deliver the SMS over the validity period.
ValidityPeriod int `json:"validityPeriod,omitempty"`
// Should the messages be sent or is this a test of the API?
// If TestMode = true then it will return the result but won’t send the data, and won’t appear in any sent report.
TestMode bool `json:"testMode,omitempty"`
// The api name of the reply rule to use for this send
RuleName string `json:"ruleName,omitempty"`
// The specific reply rule version to use for this send (if null, the active version will be used).
ReplyRuleVersion int `json:"replyRuleVersion,omitempty"`
// Any Extra reply forward emails for this send.
ExtraForwardEmails string `json:"extraForwardEmails,omitempty"`
} `json:"sendOptions,omitempty"`
Messages []Message
}
// BulkMessageRequest is a request to send a batch of SMS messages
type GroupMessageRequest struct {
// A number of optional settings for a send
SendOptions struct {
// The sender ID (source address) to use when sending the messages specified. Maximum length is 11 characters.
// Please note that a best effort is made to use the value specified but availability is ultimately
// determined by the mobile network operator
SenderId string `json:"senderId,omitempty"`
// The type of duplication check to use (Defaults to 'None')
DuplicateCheck string `json:"duplicateCheck,omitempty"`
// The date and time in UTC when the messages should be sent.
// Maximum date and time allowed is 3 months from the current date and time.
// Value should be formatted according to ISO 8601 UTC format (yyyy-mm-ddThh:mm[:ss][Z])
StartDeliveryUtc string `json:"startDeliveryUtc,omitempty"`
// This value should be set in UTC if delivery should be staggered over a period of time.
// Leave null if all messages should be sent as soon as possible.
// Value, if set, must be greater than StartDeliveryUtc
// and should be formatted according to ISO 8601 UTC format (yyyy-mm-ddThh:mm[:ss][Z])
EndDeliveryUtc string `json:"endDeliveryUtc,omitempty"`
// The name of the reply rule set that should be used for the send. Replies that are received as a result of
// the send are then subject to rules configured in the reply rule set governing auto forwards and auto
// responses
ReplyRuleSetName string `json:"replyRuleSetName,omitempty"`
// A user defined value for the name of the campaign associated with this send. Only used by the system for
// reporting purposes. Maximum value is 100 characters
CampaignName string `json:"campaignName,omitempty"`
// A user defined value for the name of the cost center associated with this send. Only used by the system for
// reporting purposes. Maximum value is 100 characters
CostCentre string `json:"costCentre,omitempty"`
// True if SMS messages should not be sent to mobile subscribers that have opted-out as a result of a previous
// send; otherwise false
CheckOptOuts bool `json:"checkOptOuts,omitempty"`
// True if this send should try shorten and track urls otherwise false.
ShortenUrls bool `json:"shortenUrls,omitempty"`
// The amount of time in hours an SMS should remain valid.
// The network will continue to try to deliver the SMS over the validity period.
ValidityPeriod int `json:"validityPeriod,omitempty"`
// Should the messages be sent or is this a test of the API?
// If TestMode = true then it will return the result but won’t send the data, and won’t appear in any sent report.
TestMode bool `json:"testMode,omitempty"`
// The api name of the reply rule to use for this send
RuleName string `json:"ruleName,omitempty"`
// The specific reply rule version to use for this send (if null, the active version will be used).
ReplyRuleVersion int `json:"replyRuleVersion,omitempty"`
// Any Extra reply forward emails for this send.
ExtraForwardEmails string `json:"extraForwardEmails,omitempty"`
} `json:"sendOptions,omitempty"`
Message Message
// The names of the groups that contacts should belong to. These contacts will be the recipients of
// the SMS message. Should contain at least one group name.
Groups []string
}
// BulkMessageResponse is returned by the API in response to a BulkMessageRequest
type BulkMessageResponse struct {
// The total cost of the send excluding any VAT, GST or tax.
Cost int `json:"cost"`
// The remaining balance after the Cost has been deducted for the send.
RemainingBalance int `json:"remainingBalance"`
// The system generated ID for the send or batch of messages
EventID int `json:"eventId"`
// A sample message that was generated for the send. Purely informational.
Sample string `json:"sample"`
// The break down of the costs for the send grouped by mobile network and feature.
CostBreakdown struct {
Quantity int `json:"quantity"`
Cost int `json:"cost"`
Network string `json:"network"`
} `json:"costBreakdown"`
// The total number of messages that were successfully enqueued for delivery. Long messages may require
// multiple SMS messages or parts to send a message and this is reflected in the Parts value.
Messages int `json:"messages"`
// The total number of SMS messages that were successfully enqueued for delivery.
Parts int `json:"parts"`
ErrorReport struct {
NoNetwork int `json:"noNetwork"`
Duplicates int `json:"duplicates"`
OptedOuts int `json:"optedOuts"`
Faults struct {
RawDestination string `json:"rawDestination"`
ScrubbedDestination string `json:"scrubbedDestination"`
CustomerID string `json:"customerId"`
ErrorMessage string `json:"errorMessage"`
Status string `json:"status"`
} `json:"faults"`
} `json:"errorReport"`
}
// GetBalance returns the current balance of the account.
// Post Paid customers will always receive a balance of 1000000,
// as no credit deduction occurs on this account type.
func (c *Client) GetBalance() (int, error) {
resp := struct {
Balance int `json:"balance"`
}{}
_, err := c.get("Balance", nil, &resp)
if err != nil {
return 0, err
}
return resp.Balance, nil
}
// SendBulkMessages sends SMS message(s) to a multiple recipients.
func (c *Client) SendBulkMessages(data BulkMessageRequest) (resp BulkMessageResponse, err error) {
_, err = c.post("BulkMessages", data, &resp)
return
}
// SendGroupMessages send SMS message(s) to one or more specified groups.
func (c *Client) SendGroupMessages(data GroupMessageRequest) (resp BulkMessageResponse, err error) {
_, err = c.post("GroupMessages", data, &resp)
return
}