Skip to content

Commit

Permalink
Merge pull request #40 from mailersend/send-sms
Browse files Browse the repository at this point in the history
feat: fix for sms personalisation
  • Loading branch information
robgordon89 authored Aug 1, 2022
2 parents 59ae10d + b272958 commit 8c040e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
13 changes: 12 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2129,7 +2129,18 @@ func main() {
message := ms.Sms.NewMessage()
message.SetFrom("your-number")
message.SetTo([]string{"client-number"})
message.SetText("This is the message content")
message.SetText("This is the message content {{ var }}")

personalization := []mailersend.SmsPersonalization{
{
PhoneNumber: "client-number",
Data: map[string]interface{}{
"var": "foo",
},
},
}

message.SetPersonalization(personalization)

res, _ := ms.Sms.Send(context.TODO(), message)
fmt.Printf(res.Header.Get("X-SMS-Message-Id"))
Expand Down
18 changes: 15 additions & 3 deletions sms.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ const smsBasePath = "/sms"
type SmsService service

type Sms struct {
From string `json:"from"`
To []string `json:"to"`
Text string `json:"text"`
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 {
Expand Down Expand Up @@ -62,6 +69,11 @@ 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)
Expand Down

0 comments on commit 8c040e2

Please sign in to comment.