Giter VIP home page Giter VIP logo

gotwilio's Introduction

Overview

This is the start of a library for Twilio. Gotwilio supports making voice calls and sending text messages.

License

Gotwilio is licensed under a BSD license.

Installation

To install gotwilio, simply run go get github.com/sfreiberg/gotwilio.

SMS Example

package main

import (
	"github.com/sfreiberg/gotwilio"
)

func main() {
	accountSid := "ABC123..........ABC123"
	authToken := "ABC123..........ABC123"
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+15555555555"
	to := "+15555555555"
	message := "Welcome to gotwilio!"
	twilio.SendSMS(from, to, message, "", "")
}

MMS Example

package main

import (
	"github.com/sfreiberg/gotwilio"
)

func main() {
	accountSid := "ABC123..........ABC123"
	authToken := "ABC123..........ABC123"
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+15555555555"
	to := "+15555555555"
	message := "Welcome to gotwilio!"
	mediaUrl := []string{"http://host/myimage.gif"}
	twilio.SendMMS(from, to, message, mediaUrl, "", "")
}

Voice Example

package main

import (
	"github.com/sfreiberg/gotwilio"
)

func main() {
	accountSid := "ABC123..........ABC123"
	authToken := "ABC123..........ABC123"
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+15555555555"
	to := "+15555555555"
	callbackParams := gotwilio.NewCallbackParameters("http://example.com")
	twilio.CallWithUrlCallbacks(from, to, callbackParams)
}

Video example

package main

import (
	"github.com/sfreiberg/gotwilio"
)

func main() {
	accountSid := "ABC123..........ABC123"
	authToken := "ABC123..........ABC123"
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	twilio.CreateVideoRoom(gotwilio.DefaultVideoRoomOptions)
}

gotwilio's People

Contributors

0syntrax0 avatar andrew-stripe avatar andrewpage avatar ashtonian avatar asms avatar bencolon avatar carbocation avatar codelingobot avatar crunk1 avatar fent avatar jenan-stripe avatar jheth avatar jniedrauer avatar jnu avatar krisatplaid avatar nbarbey avatar neilgarb avatar neilluno avatar oli-g avatar pisarukv avatar rogaha avatar romanyx avatar sfreiberg avatar sheeley avatar sshapir avatar tarasyarema avatar tekkamanendless avatar tylerb avatar wilkesybear avatar zikani03 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gotwilio's Issues

MMS with Copilot?

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

Unable to install package

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

EOF

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.

not enough arguments in call to twilio.get when running go get -u

 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)

Support Whatsapp message with Media

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?

SendSMS returns error "cannot unmarshal null"

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.

Receive SMS

Is it possible to receive a sms, by twilio using this wrapper.
If so, can you share, a sample code ?

Thanks in advance.

respond to messages?

Is this package capable of responding the messages say commands like "!Hello" if so can you please post example code

Thank you

non-idiomatic Go returning 2 error types

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.

`type Twilio interface` for mocking package?

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?

Invalid Access Token using Gotwilio withAPIKey, Error 20103

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.

Feature request: address and content retention options for sms

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!

certificate signed by unknown authority

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!

Selection_238
unnamed (1)

default room options not supporting VP8 codec for android

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.

Underscore missing in http url query string in sms

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 ?

Couldn't send sms

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, "", "")

}

Supporting GET request signature validation

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.

gotwilio/util.go

Lines 62 to 69 in 06f83df

func (twilio *Twilio) CheckRequestSignature(r *http.Request, baseURL string) (bool, error) {
if r.Method != "POST" {
return false, errors.New("Checking signatures on non-POST requests is not implemented")
}
if err := r.ParseForm(); err != nil {
return false, err
}

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.

Number Provisioning

Are there any plans to add provisioning numbers to this package? Happy to contribute this if that's ok?

room types do not have "group-small" like Twilio console does

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 ?

Feature Request

Would love to have Twilio verifiy api implemented in the package (if not already)

Whatts

Do you Are going to put whatts API here???

Get All SMS?

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}

SendSMS returns error but still works

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.

API keys are not used

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.

GetSMS not return `error_message` field

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.

OpenTracing / Context Propagation

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:
image

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.

Proposed API

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.