/go-bandwidth

Bandwidth Voice and Messaging APIs (AKA Catapult, Application Platform) in GO

Primary LanguageGoMIT LicenseMIT

Catapult API in Go GoDoc Build Status

Bandwidth Bandwidth's App Platform Go SDK

With go-bandwidth you have access to the entire set of API methods including:

  • Account - get user's account data and transactions,
  • Application - manage user's applications,
  • AvailableNumber - search free local or toll-free phone numbers,
  • Bridge - control bridges between calls,
  • Call - get access to user's calls,
  • Conference - manage user's conferences,
  • ConferenceMember - make actions with conference members,
  • Domain - get access to user's domains,
  • EntryPoint - control of endpoints of domains,
  • Error - list of errors,
  • Media - list, upload and download files to Bandwidth API server,
  • Message - send SMS/MMS, list messages,
  • NumberInfo - receive CNUM info by phone number,
  • PhoneNumber - get access to user's phone numbers,
  • Recording - mamange user's recordings.

Also you can work with Bandwidth XML using special types.

Install

     go get github.com/Bandwidth/go-bandwidth

Getting Started

  • Install go-bandwidth,
  • Get user id, api token and secret - to use the Catapult API you need these data. You can get them here on the tab "Account",
  • Set user id, api token and secret
	import "github.com/Bandwidth/go-bandwidth"
	
	api := bandwidth.New("userId", "apiToken", "apiSecret")

Read Catapult Api documentation for more details

Examples

All examples assume you have already setup your auth data!

List all calls from special number

  list, _ := api.GetCalls(&bandwidth.GetCallsQuery{From: "+19195551212"})

List all received messages

  list, _ := api.GetMessages(&bandwidth.GetMessagesQuery{State: "received"})

Send SMS

  messageId, _ := api.CreateMessage(&bandwidth.CreateMessageData{From: "+19195551212", To: "+191955512142", Text:"Test"})

Send SMS (via Messaging API v2)

  message, _ := api.CreateMessageV2(&CreateMessageDataV2{From: "fromNumber", To: "toNumber", Text: "text", ApplicationID: "YOUR_APPLICATION_ID"})

Send some SMSes

  statuses, error := api.CreateMessages(
	  &bandwidth.CreateMessageData{From: "+19195551212", To: "+191955512141", Text:"Test1"}, 
	  &bandwidth.CreateMessageData{From: "+19195551212", To: "+191955512142", Text:"Test2"})

Upload file

  api.UploadMediaFile("avatar.png", "/local/path/to/file.png", "image/png")

Make a call

  api.CreateCall(&bandwidth.CreateCallData{From: "+19195551212",  To: "+191955512142"})

Reject incoming call

  api.RejectIncomingCall(callId)

Create a gather

  api.CreateGather(callId, &bandwidth.CreateGatherData{MaxDigits: 3, InterDigitTimeout: 5, Prompt: &bandwidth.GatherPromptData{Sentence: "Please enter 3 digits"}})

Start a conference

  api.CreateConference(&bandwidth.CreateConferenceData{From: "+19195551212"})

Add a member to the conference

  api.CreateConferenceMember(conferenceId, &bandwidth.CreateConferenceMemberData{CallId: "id_of_call_to_add_to_this_conference", JoinTone: true, LeavingTone: true})

Connect 2 calls to a bridge

  api.CreateBridge(&bandwidth.BridgeData{CallIDs: []string{callId1, callId2}})

Search available local numbers to buy

  list, _ := api.GetAvailableNumbers(bandwidth.AvailableNumberTypeLocal, &bandwidth.GetAvailableNumberQuery{City: "Cary", State: "NC", Quantity: 3})

Get CNAM info for a number

  info, _ := api.GetNumberInfo("+19195551212")

Buy a phone number

  api.CreatePhoneNumber(&bandwidth.CreatePhoneNumberData{Number: "+19195551212"})

List recordings

  list, _ := api.GetRecordings()

Generate Bandwidth XML

   import (
	   "github.com/Bandwidth/go-bandwidth/xml"
	   "fmt"
   )
   
   response := &xml.Response{}
   speakSentence := xml.SpeakSentence{Sentence: "Transferring your call, please wait.", Voice: "paul", Gender: "male", Locale: "en_US"}
   transfer := xml.Transfer{
        TransferTo: "+13032218749",
        TransferCallerId: "private",
        SpeakSentence: &SpeakSentence{
            Sentence: "Inner speak sentence.",
            Voice: "paul",
            Gender: "male",
            Locale: "en_US"}}
    hangup := xml.Hangup{}

    append(response.Verbs, speakSentence)
	append(response.Verbs, transfer)
	append(response.Verbs, hangup)


    //as alternative we can pass list of verbs as
    //response = &xml.Response{Verbs = []interface{}{speakSentence, transfer, hangup}}

    fmt.Println(response.ToXML())

See directory examples for more demos.

Bugs/Issues

Please open an issue in this repository and we'll handle it directly. If you have any questions please contact us at openapi@bandwidth.com.