github.com/simpleiot/simpleiot@v0.18.3/cmd/send-sms/main.go (about) 1 // example of sending SMS message 2 package main 3 4 import ( 5 "flag" 6 "fmt" 7 "log" 8 "os" 9 10 "github.com/simpleiot/simpleiot/msg" 11 ) 12 13 func main() { 14 flagTo := flag.String("to", "", "destination phone number") 15 flagMsg := flag.String("msg", "", "message to send") 16 17 flag.Parse() 18 19 sid := os.Getenv("TWILIO_SID") 20 auth := os.Getenv("TWILIO_AUTH_TOKEN") 21 from := os.Getenv("TWILIO_FROM") 22 23 if *flagTo == "" || sid == "" || 24 auth == "" || *flagMsg == "" || from == "" { 25 log.Println("Don't have needed information") 26 flag.Usage() 27 os.Exit(-1) 28 } 29 30 twilio := msg.NewTwilio(sid, auth, from) 31 32 err := twilio.SendSMS(*flagTo, *flagMsg) 33 34 if err != nil { 35 log.Println("Error sending message:", err) 36 os.Exit(-1) 37 } 38 39 fmt.Println("Message sent") 40 }