Categorygithub.com/meterup/twilio-go
modulepackage
0.0.0-20210603011909-f94fae471660
Repository: https://github.com/meterup/twilio-go.git
Documentation: pkg.go.dev

# README

twilio-go

A client for accessing the Twilio API with several nice features:

  • Easy-to-use helpers for purchasing phone numbers and sending MMS messages

  • E.164 support, times that are parsed into a time.Time, and other smart types.

  • Finer grained control over timeouts with a Context, and the library uses wall-clock HTTP timeouts, not socket timeouts.

  • Easy debugging network traffic by setting DEBUG_HTTP_TRAFFIC=true in your environment.

  • Easily find calls and messages that occurred between a particular set of time.Times, down to the nanosecond, with GetCallsInRange / GetMessagesInRange.

  • It's clear when the library will make a network request, there are no unexpected latency spikes when paging from one resource to the next.

  • Uses threads to fetch resources concurrently; for example, has methods to fetch all Media for a Message concurrently.

  • Usable, one sentence descriptions of Alerts.

Here are some example use cases:

const sid = "AC123"
const token = "456bef"

client := twilio.NewClient(sid, token, nil)

// Send a message
msg, err := client.Messages.SendMessage("+14105551234", "+14105556789", "Sent via go :) ✓", nil)

// Start a phone call
var callURL, _ = url.Parse("https://kev.inburke.com/zombo/zombocom.mp3")
call, err := client.Calls.MakeCall("+14105551234", "+14105556789", callURL)

// Buy a number
number, err := client.IncomingNumbers.BuyNumber("+14105551234")

// Get all calls from a number
data := url.Values{}
data.Set("From", "+14105551234")
callPage, err := client.Calls.GetPage(context.TODO(), data)

// Iterate over calls
iterator := client.Calls.GetPageIterator(url.Values{})
for {
    page, err := iterator.Next(context.TODO())
    if err == twilio.NoMoreResults {
        break
    }
    fmt.Println("start", page.Start)
}

A complete documentation reference can be found at godoc.org.

In Production

twilio-go is being used by the following applications:

  • Logrole, an open source Twilio log viewer that's faster than the API.

Using twilio-go in production? Let me know!

Supported API's

The API is unlikely to change, and currently covers these resources:

  • Alerts
  • Applications
  • Calls
  • Conferences
  • Faxes
  • Incoming Phone Numbers
  • Available Phone Numbers
  • Keys
  • Messages
  • Media
  • Monitor
  • Outgoing Caller ID's
  • Pricing
  • Queues
  • Recordings
  • Task Router
    • Activities
    • TaskQueues
    • Workers
    • Workflows
  • Transcriptions
  • Wireless
  • Voice Insights
  • Access Tokens for IPMessaging, Video and Programmable Voice SDK

Error Parsing

If the twilio-go client gets an error from the Twilio API, we attempt to convert it to a rest.Error before returning. Here's an example 404.

&rest.Error{
    Title: "The requested resource ... was not found",
    ID: "20404",
    Detail: "",
    Instance: "",
    Type: "https://www.twilio.com/docs/errors/20404",
    StatusCode: 404
}

Not all errors will be a rest.Error however - HTTP timeouts, canceled context.Contexts, and JSON parse errors (HTML error pages, bad gateway responses from proxies) may also be returned as plain Go errors.

Twiml Generation

There are no plans to support Twiml generation in this library. It may be more readable and maintainable to manually write the XML involved in a Twiml response.

Errata

  • Media URL's used to be returned over HTTP. twilio-go rewrites these URL's to be HTTPS before returning them to you.

  • A subset of Notifications returned code 4107, which doesn't exist. These notifications should have error code 14107. We rewrite the error code internally before returning it to you.

  • The only provided API for filtering calls or messages by date grabs all messages for an entire day, and the day ranges are only available for UTC. Use GetCallsInRange or GetMessagesInRange to do timezone-aware, finer-grained date filtering.

  • You can get Alerts for a given Call or MMS by passing ResourceSid=CA123 as a filter to Alerts.GetPage. This functionality is not documented in the API.

Consulting

I'm available for hire, for Twilio work or general-purpose engineering. For more on what I can do for your company, see here: https://burke.services/twilio.html. Contact me: [email protected]

Donating

Donations free up time to review pull requests, respond to bug reports, and add new features. In the absence of donations there are no guarantees about timeliness for reviewing or responding to proposed changes; I don't get paid by anyone else to work on this. You can send donations via Github's "Sponsor" mechanism or Paypal's "Send Money" feature to [email protected]. Donations are not tax deductible in the USA.

# Packages

No description provided by the author
Package datausage has utilities for retrieving data usage from a SIM card.
Create them on your server and pass them to a client to help verify a client's identity, and to grant access to features in client API's.
No description provided by the author

# Functions

No description provided by the author
NewClient creates a Client for interacting with the Twilio API.
NewFaxClient returns a Client for use with the Twilio Fax API.
No description provided by the author
NewLookupClient returns a new Client to use the lookups API.
NewMonitorClient returns a Client for use with the Twilio Monitor API.
NewNextPageIterator returns a PageIterator based on the provided nextPageURI, and is designed for iterating if you have a nextPageURI and not a list of query values.
No description provided by the author
NewPageIterator returns a PageIterator that can be used to iterate through values.
NewPhoneNumber parses the given value as a phone number or returns an error if it cannot be parsed as one.
NewPricingClient returns a new Client to use the pricing API.
NewSuperSimClient returns a Client for use with the Twilio SuperSim API.
NewTaskRouterClient returns a Client for use with the Twilio TaskRouter API.
NewTwilioTime returns a TwilioTime instance.
NewVerifyClient returns a new Client to use the verify API.
NewVideoClient returns a new Client to use the video API.
NewWirelessClient returns a Client for use with the Twilio Wireless API.
ValidateIncomingRequest returns an error if the incoming req could not be validated as coming from Twilio.

# Constants

No description provided by the author
No description provided by the author
Format expected by Twilio for searching date ranges.
The APIVersion to use.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Lookup service.
No description provided by the author
No description provided by the author
Version of the Twilio Monitor API.
No description provided by the author
No description provided by the author
Version of the Twilio Pricing API.
types of video room.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
The reference time, as it appears in the Twilio API.
Credential type.
Credential type.
Credential type.
Verify service.
No description provided by the author
The twilio-go version.
No description provided by the author
Version of the Twilio Wireless API.
No description provided by the author
No description provided by the author

# Variables

The base URL serving the API.
DefaultRegion is the region used to parse phone numbers without a leading international prefix.
Epoch is a time that predates the formation of the company (January 1, 2005).
No description provided by the author
No description provided by the author
HeatDeath is a sentinel time that should outdate the extinction of the company.
Voice Insights service.
MediaClient is used for fetching images and does not follow redirects.
The base URL for Twilio Monitor.
NoMoreResults is returned if you reach the end of the result set while paging through resources.lint:ignore ST1012 preserve backwards compatibility.
The base URL for Twilio Pricing.
Super sim service.
No description provided by the author
No description provided by the author
Video service.
The base URL for Twilio Wireless.

# Structs

No description provided by the author
No description provided by the author
AccountPageIterator lets you retrieve consecutive AccountPages.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Alert represents a single Twilio Alert.
AlertPage represents a page of Alerts.
No description provided by the author
No description provided by the author
A Twilio Application.
No description provided by the author
ApplicationPageIterator lets you retrieve consecutive pages of resources.
No description provided by the author
The subresources of the AvailableNumbers resource let you search for local, toll-free and mobile phone numbers that are available for you to purchase.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
A CallPage contains a Page of calls.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Command represents a Command resource.
CommandPage represents a page of Commands.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
FaxPage represents a page of Faxes.
No description provided by the author
No description provided by the author
FleetPage represents a page of Fleets.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
A Twilio Key.
No description provided by the author
KeyPageIterator lets you retrieve consecutive pages of resources.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
A MediaService lets you retrieve a message's associated Media.
No description provided by the author
A MessagePage contains a Page of messages.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NAPNetworkPage represents a page of NAPNetworks.
No description provided by the author
NAPPage represents a page of Network Access Profiles.
No description provided by the author
No description provided by the author
No description provided by the author
NetworkPage represents a page of Networks.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
OutgoingCallerIDPageIterator lets you retrieve consecutive pages of resources.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Sim represents a Sim resource.
SimPage represents a page of Sims.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SuperSimPage represents a page of SuperSims.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
TwilioTime can parse a timestamp returned in the Twilio API and turn it into a valid Go Time struct.
No description provided by the author
No description provided by the author
UsageRecordPage represents a page of UsageRecords.
No description provided by the author
Values has the methods of url.Values, but can decode JSON from the response_headers field of an Alert.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
WorkspaceService lets you interact with a TaskRouter Workspace.

# Interfaces

AlertPageIterator lets you retrieve consecutive pages of resources.
CallPageIterator lets you retrieve consecutive pages of resources.
No description provided by the author
No description provided by the author
FaxPageIterator lets you retrieve consecutive pages of resources.
MessagePageIterator lets you retrieve consecutive pages of resources.
SimPageIterator lets you retrieve consecutive pages of resources.
No description provided by the author

# Type aliases

No description provided by the author
A Twilio error code.
No description provided by the author
The direction of the message.
A log level returned for an Alert.
No description provided by the author
No description provided by the author
No description provided by the author
The status of a resource ("accepted", "queued", etc).
No description provided by the author