twilio / twilio-go

A Go package for communicating with the Twilio API.
MIT License
272 stars 40 forks source link

Add ShortenUrls CreateMessageParam #194

Closed harveysanders closed 1 year ago

harveysanders commented 1 year ago

Issue Summary

Hi! I may have missed it but I believe the ShortenUrl param is missing from CreateMessageParams. This may be intentional as the API docs state that Link Shortening is in Public Beta. I would like to contribute a PR if you do want to add the param.

https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource-with-shortened-link

I propose the following addition to the CreateMessage parameters:

Name Type Description
ShortenUrls bool Indicates your intent to shorten links in a message. Set the value to true to enable Link Shortening. You will need to set up your domain and Messaging Services to use Link Shortening. Get started here. This parameter is false by default.

Example Usage

func main() {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    client := twilio.NewRestClient()

    params := &api.CreateMessageParams{}
    params.SetFrom("+15017122661")
    params.SetBody("Click me!\nhttps://my.domain.com/longurl?longparam=didyouknowaurlcanbetwothousandfortyeightcharacterslong%3f!!")
    params.SetTo("+15558675310")

    // Proposed method usage
        // Link Shortening only works with a configured Messaging Service
        params.SetMessagingServiceSid(os.Getenv("TWILIO_MESSAGING_SERVICE_SID"))
    params.SetShortenUrls(true)

    resp, err := client.Api.CreateMessage(params)
    if err != nil {
        fmt.Println(err.Error())
    } else {
        if resp.Sid != nil {
            fmt.Println(*resp.Sid)
        } else {
            fmt.Println(resp.Sid)
        }
    }
}

Thanks!

Sidenote

The API docs have a typo here. "ShortenUrl=true" should say "ShortenUrls=true" https://www.twilio.com/docs/sms/api/message-resource#create-a-message-resource-with-shortened-link

image

beebzz commented 1 year ago

Hi @harveysanders, thanks for posting an issue! The shortenUrls param should be included in the next release for twilio-go on this upcoming Wednesday (October 19th). As for the docs bug, feel free to file a customer support ticket (https://twilio.com/help/contact) in order to properly track the issue. I'll also try to escalate it internally since it'll be launching in the libraries soon.

beebzz commented 1 year ago

Update: no need to reach out to support for the docs typo, should've just been fixed!

harveysanders commented 1 year ago

@beebzz Perfect! Thanks for the update.