Call the twilio rest api in go.
func sendTwilioMessage() {
t := vtwilio.NewVTwilio(sid, token, vtwilio.TwilioNumber(twilioNumber))
message, err := t.SendMessage("Hello world", "12345678910")
if err != nil {
panic(err)
}
fmt.Println(message)
}
func GetATwilioMessage() {
t := vtwilio.NewVTwilio(sid, token, vtwilio.TwilioNumber(twilioNumber))
message, err := t.GetMessage(messageSID)
if err != nil {
panic(err)
}
fmt.Println(message)
}
PageSize(int)
- current page, defaults to 10Page(int)
- size of the page, defaults to 0OnDate(time.Time)
- Get messages on a dateOnAndBeforeDate(time.Time)
- Get message on and before a given dateOnAndAfterDate(time.Time)
- Get messages on and after given date
func ListTwilioMessages() {
t := vtwilio.NewVTwilio(accountSID, authToken, vtwilio.TwilioNumber(twilioNumber))
messages, err := t.ListMessages(vtwilio.PageSize(1), vtwilio.Page(0))
if err != nil {
panic(err)
}
fmt.Println(messages)
}
NearNumber
NearLatLong
Distance
InPostalCode
InLocality
InRegion
InRateCenter
InLATA
func GetAvailableNumbers() {
t := vtwilio.NewVTwilio(sid, token)
numbers, err := t.AvailablePhoneNumbers("US", vtwilio.InRegion("CA"))
if err != nil {
panic(err)
}
fmt.Println(numbers)
}
After using the AvailablePhoneNumbers
method, a number can be chosen and purchased from Twilio using the IncomingPhoneNumber
method.
Note: This will not work with a Twilio trial account.
AreaCode
APIVersion
FriendlyName
VoiceURL
VoiceMethod
VoiceFallBackURL
VoiceFallBackMethod
StatusCallback
StatusCallbackMethod
VoiceCallerIDLookup
VoiceApplicationSID
TrunkSID
SMSURL
SMSMethod
SMSFallbackURL
SMSFallbackMethod
SMSApplicationSID
AccountSID
AddressSID
func PurchaseNumber(number string) (*vtwilio.IncomingPhoneNumber, error) {
t := vtwilio.NewVTwilio(sid, token)
num, err := t.IncomingPhoneNumber(number)
if err != nil {
return nil, err
}
return num, nil
}
Updating a number uses the same options as purchasing one.
func UpdateNumber() error {
t := vtwilio.NewVTwilio(sid, token)
_, err := t.UpdateIncomingPhoneNumber("+12345678910", "MESSAGE_SID",
vtwilio.FriendlyName("New Friendly Name"))
if err != nil {
return err
}
return nil
}
This will delete a Twilio number from your account, and allow someone else to potentially buy this number.
func ReleaseNumber() error {
t := vtwilio.NewVTwilio(sid, token)
err := t.ReleaseNumber("NUMBER_SID")
if err != nil {
return err
}
return nil
}
- Fix typo
- Add from number option for send method to override the client's default
- Add callback url option to send method
- TwiML support
- Incoming phone numbers
- Update phone number settings
- Release a phone number
- Refactoring code
- Add lookup for available phone numbers
- No longer required to pass a number to VTwilio in the case that you want to look up a number. This is now an option
- Currently still a work in progress