Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix for sms personalisation #40

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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