sfreiberg / gotwilio Goto Github PK
View Code? Open in Web Editor NEWTwilio library for Go (golang).
License: BSD 2-Clause "Simplified" License
Twilio library for Go (golang).
License: BSD 2-Clause "Simplified" License
When calling the SendSMS method it returns the following error strconv.ParseFloat: parsing "": invailid syntax
. I am calling the SendSMS method like the readme has documented:
sms, exc, err := twilio.SendSMS(from, to, body, "", "")
even though it returns an error the message is still sent to Twilio.
This code:
package main
import (
"fmt"
"github.com/sfreiberg/gotwilio"
)
func main() {
accountSid := "123...123"
authToken := "123...123"
twilio := gotwilio.NewTwilioClient(accountSid, authToken)
from := "+11235551234"
to := "+11235551234"
message := "Welcome to gotwilio!"
response,exception,err := twilio.SendSMS(from, to, message, "", "")
fmt.Printf("response: %+v\n",response)
fmt.Printf("exception: %+v\n",exception)
fmt.Printf("err: %+v\n",err)
}
successfully sends the SMS but it also prints this as part of the output:
exception: <nil>
err: json: cannot unmarshal null into Go value of type string
I would have expected err to be nil.
Basic auth is hardcoded to use account SID and auth token. API keys can be set but they are ignored. You also can't pass in API keys as the account SID and auth token because the account SID is used to generate the URL for API requests.
Is it possible to receive a sms, by twilio using this wrapper.
If so, can you share, a sample code ?
Thanks in advance.
is it possible to verify the request?
I have added a url in the SMS body that includes a query parameter (?type=ab_cam). When the sms is sent on iPhone6, then the query parameter is sent as ?type=ab camp. The underscore is missing in the url. When I checked the same url on Android then it worked fine. Can someone please check this, if it is for a particular device or not ?
in using the api to create rooms now, we wanted to set group room type as group-small as we dont need more than 4 participants and these are cheaper rooms to provision.
const (
PeerToPeer VideoRoomType = "peer-to-peer"
Group VideoRoomType = "group"
)
will setting max to 4 and type group do same thing as supporting Group-Small ?
Would love to have Twilio verifiy api implemented in the package (if not already)
Is this package capable of responding the messages say commands like "!Hello" if so can you please post example code
Thank you
We're running into intermittent "EOF" errors using Twilio.CallWithUrlCallbacks()
. err
looks like this:
Post https://api.twilio.com/2010-04-01/Accounts/<an_account_id>/Calls.json: EOF
Not sure why this happens. Some posts suggest it could have to do with the Go http client wanting to reuse connections and for some reason the server has already closed the connection. Or, that the server is rate limited (too many concurrent connections).
Any ideas? Help greatly appreciated.
Used Gotwilio to generate an access token for Twilio Video API, kept receiving errors for invalid Access Token by Twilio which led to this page: https://www.twilio.com/docs/api/errors/20103
After investigating the jwt token generated by Gotwilio and that of a valid token generated by twilio quickstart.js repo, basically a friend figured out that needed withAPIKey method to work and that the timestamps for token expiry are negative which is also causing a problem so need to fix that too and now my access token is valid.
While not super important, I'd love to have a tagged version for this package. v0.1.0
would be a fine starting point if the interface is still changing.
Wanted to start a discussion about the possible integration of OpenTracing and context.Context
propagation in the gotwilio
project.
OpenTracing is an API specification/collection of libraries which allow for distributed tracing of an individual request as it propagates across a system. For instance, one could view a trace of a particular request and identify how long certain components of the request took (interaction with database, message queue, internal processing, external service calls, etc.), as well as view logs and tags associated with that particular sub-request (HTTP status codes, errors, etc.)
These recorded traces are viewed through a tool such as Jaeger. Example below:
For those of us who are developing Twilio-based applications, the HTTP requests to Twilio (& resulting attributes, such as SIDs and errors) are an important part of our request lifecycle, and it would be great to have first-class support integrated into the gotwilio
library.
The great part about this is that OpenTracing instrumentation code piggybacks off of the Golang context.Context
package, and the instrumentation code is a no-op if the application has not configured a remote tracing server to report to. This means that nobody is required to configure OpenTracing, but if they have configured it, the gotwilio
package would seamlessly integrate.
We would use the opentracing-go
package.
To maintain backwards compatibility, I propose keeping the current methods, but added Context
-suffixed methods to support context propagation. This is similar to the approach taken by the database/sql
package (e.g. Query
vs QueryContext
.
type Twilio interface {
func CallWithUrlCallbacks(string, string, *CallbackParameters) (*VoiceResponse, *Exception, error)
func CallWithUrlCallbacksContext(context.Context, string, string, *CallbackParameters) (*VoiceResponse, *Exception, error)
}
What do you think @sfreiberg?
Are there any plans to add provisioning numbers to this package? Happy to contribute this if that's ok?
I see GetSMS
as an option, but it requires I know about the SMS. Is there an option to get all existing SMS messages like:
curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/{accountID}/Messages.json?PageSize=20&From="+{phone}"' \ -u {accountID}:{authKey}
According to this code, only POST requests are supported. However, Twilio accesses fax media files using a GET request. As far as I can see and have roughly tested, simply allowing the function to continue even if its a GET request correctly validates the signature.
Lines 62 to 69 in 06f83df
Browsing the Twilio documentation, it says that appending the full raw query to the URL is sufficient. Likewise, r.URL.String() includes the entire raw query. Any POST parameters are appended to that. If we call ParseForm on a GET request, the request Body is not read, and r.PostForm is initialized to a non-nil, empty value. So GenerateSignature still functions as it should.
I just took a first look at this package but was immediately confused by the fact that methods like SendSMS return two different kinds of error info: *Exception and error. What are the semantics of a function that returns 2 different error types? It would be more idiomatic to return just (data, error) and include any exception data inside the error.
I'm using then the Twilio WhatsApp API to notify users with messages. I want to send images too. I noticed that the actual API does not support this.
Should I fork and implement this?
gog -u github.com/sfreiberg/gotwilio
# github.com/sfreiberg/gotwilio
../../go/pkg/mod/github.com/sfreiberg/[email protected]/sms.go:218:24: not enough arguments in call to twilio.get
have (string)
want (context.Context, string)
../../go/pkg/mod/github.com/sfreiberg/[email protected]/sms.go:261:24: not enough arguments in call to twilio.get
have (string)
want (context.Context, string)
../../go/pkg/mod/github.com/sfreiberg/[email protected]/sms.go:303:24: not enough arguments in call to twilio.get
have (string)
want (context.Context, string)
Hi Twilio - on our first v1 implementation we had UI clients jsut connect to rooms and used room default settings from our accounts twilio console. In that console we had video codec support for H264 and VP8, which I think was default and should be.
As we updated to get event status calllbacks and needed to create a secure url for Twilio to callback we created rooms up front on backend with go api. Found android stopped working.
Was hard to find, had to dig into this library source code to see default was not supporting both.
videoRoomOptions := gotwilio.DefaultVideoRoomOptions
videoRoomOptions.VideoCodecs = []gotwilio.VideoCodecs{gotwilio.H264, gotwilio.VP8}
fixed. Would highly suggest updating to support both as default.
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!
I've looked in the code, but I have not found anything useful to send TWiML messages https://www.twilio.com/docs/sms/twiml/message .
Just asking before I create a PR to add the functionality.
package main
import (
"github.com/sfreiberg/gotwilio"
)
func main() {
accountSid := "xxx"
authToken := "xxx"
twilio := gotwilio.NewTwilioClient(accountSid, authToken)
from := "+xxxxxxxxxx"
to := "+xxxxxxxxx"
message := "Welcome to gotwilio!"
twilio.SendSMS(from, to, message, "", "")
}
I get an error while running go get github.com/sfreiberg/gotwilio
.
The error is:
# github.com/sfreiberg/gotwilio ../github.com/sfreiberg/gotwilio/access_token.go:91:7: undefined: jwt.StandardClaims ../github.com/sfreiberg/gotwilio/access_token.go:104:53: cannot use claims (variable of type *twilioClaims) as jwt.Claims value in argument to jwt.NewWithClaims: *twilioClaims does not implement jwt.Claims (missing method GetAudience) ../github.com/sfreiberg/gotwilio/access_token.go:119:6: undefined: jwt.StandardClaims
I see that in Twilio's doc (https://www.twilio.com/docs/lookup/tutorials/carrier-and-caller-name#identify-a-phone-numbers-carrier-and-type) there's a new object called caller_name
in the lookup method.
Are there any updates to include it?
Pull request created: #80
Hey,
It works great locally but when I deploy to my Kubernetes cluster I get the following error.
Post https://api.twilio.com/2010-04-01/Accounts/AC6ce4211566726873dad7c9924ba2ff1c/Messages.json: x509: certificate signed by unknown authority
I'm pretty sure my cert is valid. We're a decent sized company and we've been using these certs and renewing them for 4 years. This is the first time I've seen this kind of error with twilio. The only difference is we've been moving our API service from NodeJS to Go. Thanks!
According to the docs at https://www.twilio.com/docs/sms/send-messages#conditional-parameters, only one of From
or MessagingServiceSid
is required.
Currently there is no way to specify a MessagingServiceSid
instead of From
when calling twilio.SendSMS()
in this library, so it is not possible to use a roster of different numbers for outgoing SMS messages.
In order for others to implement other grant types (voice), the grantName method should be exported.
thanks,
Hello, I'd like to use gomock to mock the Twilio requests and responses in tests. This requires an interface corresponding to type Twilio struct
and all its methods func (twilio *Twilio) ...
. What do you think of adding this interface to the gotwilio
package?
I find that GetSMS()
method filters out Twilio specific error code in SmsResponse, and only return when
HTTP Status Code is not 200.
I think it would be more appropriate to return the Twilio exception code field in the result, since the user can determine the reason for the failed SMS.
Do you Are going to put whatts API here???
Hello!
I see that there was a previous PR #44 that added functionality for MMS with Copilot, along with a LookupPhone
function, but was ultimately closed. I am in need of MMS usage over Copilot, and would like to add just the SendMMSWithCopilot
function that was proposed as part of the PR above. Please let me know if there's any more context here about that decision; otherwise, look out for a PR from me coming soon!
Thank you, Andrew
The client doesn't currently allow usage to be queried. The Usage API is documented here:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.