sfreiberg / gotwilio

Twilio library for Go (golang).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: address and content retention options for sms

jnu opened this issue · comments

Hi, thanks for maintaining a go client for twilio, it's super helpful! Would it be possible to support the AddressRetention and ContentRetention parameters in SendSMS? Documentation here: https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource

The code should be easy to add to sendMessage, seems like it's mostly a question of how you want to allow optional parameters. One method is using an ...Option spread, for example: https://github.com/nats-io/go-nats/blob/master/nats.go#L515

gotwilio.SendSMS(from, to, content, "https://..., "...", gotwilio.ContentRetentionDiscard, gotwilio.AddressRetentionObfuscate)

then these get applied to form values in SendSMS:

formValues.Set("ContentRetention", "discard")
formValues.Set("AddressRetention", "obfuscate")

the implementation might look like:

type Option struct {
    Key   string
    Value string
} 

var ContentRetentionDiscard = &Option{"ContentRetention", "discard"}
var AddressRetentionObfuscate = &Option{"AddressRetention", "obfuscate"}

func (twilio *Twilio) SendSMS(from, to, body, statusCallback, applicationSid string, opts ...Option) (smsResponse *SmsResponse, exception *Exception, err error) {
    formValues := initFormValues(to, body, nil, statusCallback, applicationSid)
    formValues.Set("From", from)

    for _, opt := range opts {
        if opt != nil {
            formValues.Set(opt.Key, opt.Value)
        }
    }

    smsResponse, exception, err = twilio.sendMessage(formValues)
    return
}

happy to submit a PR for this, or discuss other approaches!