Skip to content

Commit

Permalink
Merge pull request #108 from dsmoljanovic/infobip-multiple-recipients
Browse files Browse the repository at this point in the history
Support multiple SMS recipients for Infobip provider
  • Loading branch information
marcel corso gonzalez committed Nov 23, 2021
2 parents 6575a24 + 48f50e2 commit 646e7a2
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions provider/infobip/infobip.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ type Infobip struct {
Config
}

type InfobipDestination struct {
To string `json:"to"`
}

type InfobipMessage struct {
From string `json:"from"`
Destinations []InfobipDestination `json:"destinations"`
Text string `json:"text"`
}

type InfobipPayload struct {
Messages []InfobipMessage `json:"messages"`
}

//NewInfobip creates a new
func NewInfobip(config Config) *Infobip {
Infobip := &Infobip{config}
Expand All @@ -32,13 +46,30 @@ func NewInfobip(config Config) *Infobip {

//Send send sms to n number of people using bulk sms api
func (c *Infobip) Send(message sachet.Message) (err error) {
smsURL := "https://api.infobip.com/sms/1/text/single"
smsURL := "https://api.infobip.com/sms/2/text/advanced"
//smsURL = "http://requestb.in/pwf2ufpw"
var request *http.Request
var resp *http.Response

dataMap := map[string]string{"from": message.From, "to": message.To[0], "text": message.Text}
data, _ := json.Marshal(dataMap)
payload := InfobipPayload{}
payload.Messages = append(payload.Messages, InfobipMessage{})
payload.Messages[0].From = message.From
payload.Messages[0].Text = message.Text

for _, destination := range message.To {
payload.Messages[0].Destinations = append(
payload.Messages[0].Destinations,
InfobipDestination{
To: destination,
},
)
}

data, err := json.Marshal(payload)
if err != nil {
return err
}

//preparing the request
request, err = http.NewRequest("POST", smsURL, bytes.NewBuffer(data))
if err != nil {
Expand Down

0 comments on commit 646e7a2

Please sign in to comment.