Skip to content

Commit

Permalink
allow optional parameters in SendSMS (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnu authored Dec 11, 2020
1 parent bcd1a4b commit c426a37
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 17 additions & 1 deletion sms.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ type SmsResponse struct {
Url string `json:"uri"`
}

// Optional SMS parameters
var (
// Settings for what Twilio should do with addresses in message logs
SmsAddressRetentionObfuscate = &Option{"AddressRetention", "obfuscate"}
SmsAddressRetentionRetain = &Option{"AddressRetention", "retain"}
// Settings for what Twilio should do with message content in message logs
SmsContentRetentionDiscard = &Option{"ContentRetention", "discard"}
SmsContentRetentionRetain = &Option{"ContentRetention", "retain"}
)

// DateCreatedAsTime returns SmsResponse.DateCreated as a time.Time object
// instead of a string.
func (sms *SmsResponse) DateCreatedAsTime() (time.Time, error) {
Expand Down Expand Up @@ -65,10 +75,16 @@ func (twilio *Twilio) SendWhatsAppMedia(from, to, body string, mediaURL []string

// SendSMS uses Twilio to send a text message.
// See http://www.twilio.com/docs/api/rest/sending-sms for more information.
func (twilio *Twilio) SendSMS(from, to, body, statusCallback, applicationSid string) (smsResponse *SmsResponse, exception *Exception, err error) {
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
}
Expand Down
6 changes: 6 additions & 0 deletions type.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ package gotwilio
func NewBoolean(value bool) *bool {
return &value
}

// Option contains a key/value pair to define optional request parameters.
type Option struct {
Key string
Value string
}

0 comments on commit c426a37

Please sign in to comment.