Skip to main content
Version: Next (unreleased)

Twilio

go get github.com/KARTIKrocks/gosms/twilio

Configuration

provider, err := twilio.NewProvider(twilio.Config{
AccountSID: "account_sid",
AuthToken: "auth_token",
From: "+15551234567",
})
if err != nil {
log.Fatal(err)
}

client := gosms.NewClient(provider)
result, err := client.Send(ctx, "+15559876543", "Hello from gosms!")
FieldPurpose
AccountSID, AuthTokenTwilio API credentials
FromDefault sender number, used when a Message doesn't set From
MessagingServiceSIDOptional — route through a Messaging Service instead of a single From number
StatusCallbackOptional — URL Twilio posts delivery status updates to
HTTPClientOptional — override the default *http.Client
BaseURLOptional — override the Twilio API base URL (testing)

Scheduled messages

Twilio is the only provider that supports WithSchedule:

msg := gosms.NewMessage("+15559876543", "Reminder: your appointment is tomorrow").
WithSchedule(time.Now().Add(24 * time.Hour))

result, err := client.SendMessage(ctx, msg)

Webhook

twilio.ParseWebhook matches the gosms.WebhookParser signature — see Webhooks for the shared pattern:

http.HandleFunc("/webhook/twilio", func(w http.ResponseWriter, r *http.Request) {
status, err := twilio.ParseWebhook(r)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

log.Printf("Message %s status: %s", status.MessageID, status.Status)
w.WriteHeader(http.StatusOK)
})