This SDK is designed to allow you to interact with Twilio API's using Golang.
This project is compatible with the following versions of Golang:
Version | Supported |
---|---|
1.15.x | Yes |
1.16.x | Yes |
⚠️ Disclaimer: This project is not an official Twilio project and is not supported or endorsed by Twilio in any way. It is maintained in my free time.
NOTE: The default branch for this project is called main
The code uses go doc
style documentation with links to the relevant Twilio API documentation/ guides where appropriate.
Example code snippets for all of the supported services & resources can be found here
There are many ways to initialise and configure the Twilio Client. See below for examples:
creds, err := credentials.New(credentials.Account{
Sid: os.Getenv("TWILIO_ACCOUNT_SID"),
AuthToken: os.Getenv("TWILIO_AUTH_TOKEN"),
})
if err != nil {
log.Panicf("%s", err.Error())
}
twilioClient := twilio.NewWithCredentials(creds)
creds, err := credentials.New(credentials.Account{
Sid: os.Getenv("TWILIO_ACCOUNT_SID"),
AuthToken: os.Getenv("TWILIO_AUTH_TOKEN"),
})
if err != nil {
log.Panicf("%s", err.Error())
}
twilioClient := twilio.New(session.New(creds))
The Twilio Client allows the user to supply configuration to alter the default behaviour of the SDK.
The SDK supports the following configuration:
- BackoffInterval - The time taken in milliseconds between retries
- DebugEnabled - This logs out the request and response details for each call to the Twilio API
- Edge - Specify a public edge or private interconnect to connect to Twilio via. See Global Infrastructure - Edge Locations for more information
- Region - Specify a public region or private interconnect region to connect to Twilio via. See Global Infrastructure - Legacy Regions for more information
- RetryAttempts - The number of retry attempts before an error is returned
creds, err := credentials.New(credentials.Account{
Sid: os.Getenv("TWILIO_ACCOUNT_SID"),
AuthToken: os.Getenv("TWILIO_AUTH_TOKEN"),
})
if err != nil {
log.Panicf("%s", err.Error())
}
twilioClient := twilio.New(session.New(creds), &client.Config{
DebugEnabled: true,
})
creds, err := credentials.New(credentials.Account{
Sid: os.Getenv("TWILIO_ACCOUNT_SID"),
AuthToken: os.Getenv("TWILIO_AUTH_TOKEN"),
})
if err != nil {
log.Panicf("%s", err.Error())
}
twilioClient := twilio.New(session.New(creds), &client.Config{
Edge: utils.String("dublin"),
Region: utils.String("ie1"),
})
This project is very heavily inspired and influenced by other open-source projects including: