twilio / twilio-go

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

Sending SMS fails after upgrading to `1.22.0` #251

Closed wung-s closed 1 week ago

wung-s commented 2 weeks ago

Issue Summary

Without any other code change, upgrading twilio-go to v1.22.0 from v1.21.1 errors out

Steps to Reproduce

  1. Use twilio-go version v1.21.1
  2. Call the function sendSMS (will succeed)
  3. change github.com/twilio/twilio-go v1.21.1 to github.com/twilio/twilio-go v1.22.2 in go.mod and do go mod tidy to install the upgraded version
  4. Call the function sendSMS (returns an error)

Code Snippet

import (
       "fmt"
       "github.com/twilio/twilio-go"
    twilioapi "github.com/twilio/twilio-go/rest/api/v2010"
)

func sendSMS(to, msg, callerID string) error {
    client := twilio.NewRestClientWithParams(twilio.ClientParams{
        Username: "<account-sid>",
        Password: "<auth-token>",
    })

    params := twilioapi.CreateMessageParams{}
    params.SetTo(to)
    params.SetFrom(callerID)
    params.SetBody(msg)

    if _, err := client.Api.CreateMessage(&params); err != nil {
        return fmt.Errorf("failed to send SMS to number %v : %w", number, err)
    }

    return nil

}

Exception/Log

<*errors.withStack | 0xc0000128b8>: 
error decoding the response for an HTTP error code: 400: invalid character '<' looking for beginning of value
            {
                error: <*errors.withMessage | 0xc00007af00>{
                    cause: <*json.SyntaxError | 0xc000012888>{
                        msg: "invalid character '<' looking for beginning of value",
                        Offset: 1,
                    },
                    msg: "error decoding the response for an HTTP error code: 400",
                },
                stack: [0xfedf5c8, 0xfee0145, 0xfee04f6, 0xfee22b1, 0xfee0b6a, 0xfee8015, 0xfefb0f9, 0xfd2615b, 0xfcaa3e1],
            }

Technical details:

C0dyGary commented 2 weeks ago
error decoding the response for an HTTP error code: 400: invalid character '<' looking for beginning of value

It happens the same to me too

th0th commented 1 week ago

Outgoing calls are also failing with error No 'To' number is specified (null). I downgraded to 1.21.0 as a workaround.

tiwarishubham635 commented 1 week ago

Oh let me check once and get back

tiwarishubham635 commented 1 week ago

Okay, so I got it. The fix for this has already been pushed in the repo actually. See #249. But somehow it is not reflecting in the release. Possibly we need to make another release after deleting this tag. Let me see what I can do