package messaging import ( "encoding/json" "fmt" "time" "github.com/twilio/twilio-go" twilioApi "github.com/twilio/twilio-go/rest/api/v2010" "git.kundeng.us/phoenix/sender/models" ) func SendMessages(config models.TwiloDetails, numbers [](models.Number), message models.Message, secondInterval int) { fmt.Println("Sending message") longSleepLimit := 5 count := 0 client := initClient(config) for _, number := range numbers { numberToSend := number if numberToSend.IsEmpty() { fmt.Println("Empty number") continue } fmt.Println(numberToSend) params := &twilioApi.CreateMessageParams{} params.SetTo(numberToSend.PhoneNumber) params.SetFrom(config.Number) params.SetBody(message.Text) fmt.Println("Sending to: " + numberToSend.PhoneNumber) resp, err := client.Api.CreateMessage(params) if err != nil { fmt.Println("Error sending SMS message: " + err.Error()) } else { response, _ := json.Marshal(*resp) fmt.Println("Response: " + string(response)) } if count%longSleepLimit == 0 { // sleep for X seconds tme := 5 * time.Second time.Sleep(tme) } else { time.Sleep(time.Second) } } } func initClient(config models.TwiloDetails) *twilio.RestClient { return twilio.NewRestClientWithParams(twilio.ClientParams{ Username: config.AccountSID, Password: config.AuthToken, }) }