smsbb/smsbb.go
djsweet 2145ce1134 Make a thing worth running (#7)
This is, admittedly, mostly the [twilio-go](https://github.com/twilio/twilio-go) Quickstart, adapted with positional arguments and environment variables for secrets. But it's definitely a start!

Co-authored-by: Dani Sweet <djsweet@users.noreply.github.com>
Reviewed-on: #7
Reviewed-by: maren <git@stillgreenmoss.net>
2024-01-08 00:47:15 +00:00

49 lines
No EOL
1.1 KiB
Go

package main
import (
"encoding/json"
"fmt"
"os"
"github.com/twilio/twilio-go"
twilioApi "github.com/twilio/twilio-go/rest/api/v2010"
)
func main () {
accountSid := os.Getenv("SMSBB_ACCT_SID")
authToken := os.Getenv("SMSBB_AUTH_TOKEN")
if (len(accountSid) == 0) {
fmt.Fprintf(os.Stderr, "Please set the SMSBB_ACCT_SID environment variable to your Twilio account SID\n")
os.Exit(1)
}
if (len(authToken) == 0) {
fmt.Fprintf(os.Stderr, "Please set the SMSBB_AUTH_TOKEN environment variable to your Twilio authentication token\n")
os.Exit(1)
}
if (len(os.Args) < 4) {
fmt.Fprintf(os.Stderr, "%s FROM-NUMBER TO-NUMBER MESSAGE-BODY\n", os.Args[0])
os.Exit(1)
}
client := twilio.NewRestClientWithParams(twilio.ClientParams{
Username: accountSid,
Password: authToken,
})
params := &twilioApi.CreateMessageParams{}
params.SetFrom(os.Args[1])
params.SetTo(os.Args[2])
params.SetBody(os.Args[3])
resp, err := client.Api.CreateMessage(params)
if err != nil {
fmt.Fprintf(os.Stderr, "Error sending SMS message: %s", err.Error())
} else {
response, _ := json.Marshal(*resp)
fmt.Printf("Response from Twilio: %s", string(response))
}
}