-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsms.go
85 lines (70 loc) · 2.26 KB
/
sms.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
package mailersend
import (
"context"
"net/http"
"time"
)
const smsBasePath = "/sms"
type SmsService service
type Sms struct {
From string `json:"from"`
To []string `json:"to"`
Text string `json:"text"`
Personalization []SmsPersonalization `json:"personalization,omitempty"`
}
// SmsPersonalization - you can set multiple SmsPersonalization for each Recipient
type SmsPersonalization struct {
PhoneNumber string `json:"phone_number"`
Data map[string]interface{} `json:"data"`
}
type SmsMessageRoot struct {
Data SmsMessageData `json:"data"`
}
type SmsMessageData struct {
Id string `json:"id"`
From string `json:"from"`
To []string `json:"to"`
Text string `json:"text"`
Paused bool `json:"paused"`
CreatedAt time.Time `json:"created_at"`
SmsMessage []SmsMessage `json:"sms"`
SmsActivityData []smsActivityData `json:"sms_activity"`
}
type SmsMessage struct {
Id string `json:"id"`
From string `json:"from"`
To string `json:"to"`
Text string `json:"text"`
Status string `json:"status"`
SegmentCount int `json:"segment_count"`
ErrorType interface{} `json:"error_type"`
ErrorDescription interface{} `json:"error_description"`
}
// NewMessage - Setup a new Sms message ready to be sent.
func (s *SmsService) NewMessage() *Sms {
return &Sms{}
}
// SetFrom - Set from.
func (m *Sms) SetFrom(from string) {
m.From = from
}
// SetTo - Set to.
func (m *Sms) SetTo(to []string) {
m.To = to
}
// SetText - Set the text content of the email, required if not using a template.
func (m *Sms) SetText(text string) {
m.Text = text
}
// SetPersonalization - Set the template personalization.
func (m *Sms) SetPersonalization(personalization []SmsPersonalization) {
m.Personalization = personalization
}
// Send - send the message
func (s *SmsService) Send(ctx context.Context, sms *Sms) (*Response, error) {
req, err := s.client.newRequest(http.MethodPost, smsBasePath, sms)
if err != nil {
return nil, err
}
return s.client.do(ctx, req, nil)
}