twirest

package
v0.0.0-...-030a493 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package twirest provides a interface to Twilio REST API allowing the user to query meta-data from their account and, to initiate calls and send SMS.

Index

Constants

View Source
const (
	TwiInit       = "init"
	TwiQueued     = "queued"
	TwiSending    = "sending"
	TwiSent       = "sent"
	TwiReceiving  = "receiving"
	TwiReceived   = "received"
	TwiFailed     = "failed"
	TwiRinging    = "ringing"
	TwiInProgress = "in-progress"
	TwiCanceled   = "canceled"
	TwiCompleted  = "completed"
	TwiBusy       = "busy"
	TwiNoAnswer   = "no-answer"
)

Call, Message & Conference status strings

View Source
const (
	TwiCalls                   = "calls"
	TwiCallsInbound            = "calls-inbound"
	TwiCallsInboundLocal       = "calls-inbound-local"
	TwiCallsInboundTollfree    = "calls-inbound-tollfree"
	TwiCallsOutbound           = "calls-outbound"
	TwiCallsClient             = "calls-client"
	TwiCallsSip                = "calls-sip"
	TwiSms                     = "sms"
	TwiSmsInbound              = "sms-inbound"
	TwiSmsInboundShortcode     = "sms-inbound-shortcode"
	TwiSmsInboundLongcode      = "sms-inbound-longcode"
	TwiPhoneNumbers            = "phonenumbers"
	TwiPhoneNumbersTollFree    = "phonenumbers-tollfree"
	TwiPhoneNumbersLocal       = "phonenumbers-local"
	TwiShortcodes              = "shortcodes"
	TwiShortcodesVanity        = "shortcodes-vanity"
	TwiShortcodesRandom        = "shortcodes-random"
	TwiShortcodesCustomerOwned = "shortcodes-customerowned"
	TwiCallerIdLookups         = "calleridlookups"
	TwiRecordings              = "recordings"
	TwiTranscriptions          = "transcriptions"
	TwiRecordingStorage        = "recordingstorage"
	TwiTotalPrice              = "totalprice"
)

UsageRecords categories

View Source
const (
	TwiDaily     = "Daily"
	TwiMonthly   = "Monthly"
	TwiYearly    = "Yearly"
	TwiAllTime   = "AllTime"
	TwiToday     = "Today"
	TwiYesterday = "Yesterday"
	TwiThisMonth = "ThisMonth"
	TwiLastMonth = "LastMonth"
)

UsageRecords subresources

View Source
const (
	TwiClosed    = "closed"
	TwiSuspended = "suspended"
	TwiActive    = "active"
)

Account status strings

View Source
const ApiVer string = "2010-04-01"

Variables

View Source
var ErrSignature = errors.New("Invalid X-Twilio-Signature")

ErrSignature is used to signify that ValidateRequest was not able to confirm the received signature as being correct.

Functions

This section is empty.

Types

type Account

type Account struct {
	Sid string
}

Account resource information for a single account

type AccountResponse

type AccountResponse struct {
	Sid             string
	DateCreated     string
	DateUpdated     string
	FriendlyName    string
	Type            string
	Status          string
	AuthToken       string
	Uri             string
	OwnerAccountSid string
	SubResourceUris *AccountSubUris
}

type AccountSubUris

type AccountSubUris struct {
	AvailablePhoneNumbers string
	Calls                 string
	Conferences           string
	IncomingPhoneNumbers  string
	Notifications         string
	OutgoingCallerIds     string
	Recordings            string
	Transcriptions        string
	SMSMessages           string
}

type Accounts

type Accounts struct {
	FriendlyName string `FriendlyName=`
	Status       string `Status=`
}

Request a list of the account resources

type AccountsResponse

type AccountsResponse struct {
	Page
	Account []AccountResponse
}

type AddOutgoingCallerId

type AddOutgoingCallerId struct {
	PhoneNumber          string `PhoneNumber=`
	FriendlyName         string `FriendlyName=`
	CallDelay            string `CallDelay=`
	Extension            string `Extension=`
	StatusCallback       string `StatusCallback=`
	StatusCallbackMethod string `StatusCallbackMethod=`
	// contains filtered or unexported fields
}

type Call

type Call struct {
	Sid           string // CallSid
	Recordings    bool
	Notifications bool
	// contains filtered or unexported fields
}

Request call information about a single call

type CallResponse

type CallResponse struct {
	Sid             string
	ParentCallSid   string
	DateCreated     string
	DateUpdated     string
	AccountSid      string
	To              string
	From            string
	PhoneNumberSid  string
	Status          string
	StartTime       string
	EndTime         string
	Duration        string
	Price           string
	PriceUnit       string
	Direction       string
	AnsweredBy      string
	ForwardedFrom   string
	CallerName      string
	Uri             string
	SubResourceUris *CallSubUris
}

type CallSubUris

type CallSubUris struct {
	Notifications string
	Recordings    string
}

type Calls

type Calls struct {
	To              string `To=`
	From            string `From=`
	Status          string `Status=`
	StartTime       string `StartTime=`
	StartTimeBefore string `StartTime<=`
	StartTimeAfter  string `StartTime>=`
	ParentCallSid   string `ParentCallSid=`
	// contains filtered or unexported fields
}

Request list of calls made to and from account

type CallsResponse

type CallsResponse struct {
	Page
	Call []CallResponse
}

type ChangeQueue

type ChangeQueue struct {
	Sid          string
	FriendlyName string `FriendlyName=`
	MaxSize      string `MaxSize=`
	// contains filtered or unexported fields
}

Request to change queue properties

type Conference

type Conference struct {
	Sid string
	// contains filtered or unexported fields
}

Resource for individual conference instance

type ConferenceResponse

type ConferenceResponse struct {
	Sid             string
	AccountSid      string
	FriendlyName    string
	Status          string
	DateCreated     string
	DateUpdated     string
	Uri             string
	SubResourceUris *ConferenceSubUris
}

type ConferenceSubUris

type ConferenceSubUris struct {
	Participants string
}

type Conferences

type Conferences struct {
	Status            string `Status=`
	FriendlyName      string `FriendlyName=`
	DateCreated       string `DateCreated=`
	DateCreatedBefore string `DateCreated<=`
	DateCreatedAfter  string `DateCreated>=`
	DateUpdated       string `DateUpdated=`
	DateUpdatedBefore string `DateUpdated<=`
	DateUpdatedAfter  string `DateUpdated>=`
	// contains filtered or unexported fields
}

List conferences within an account

type ConferencesResponse

type ConferencesResponse struct {
	Page
	Conference []ConferenceResponse
}

type CreateQueue

type CreateQueue struct {
	FriendlyName string `FriendlyName=`
	MaxSize      string `MaxSize=`
	// contains filtered or unexported fields
}

Create a new queue

type DeQueue

type DeQueue struct {
	Sid     string // Queue Sid
	CallSid string // either this field or Front is required
	Front   bool
	Url     string `Url=`
	Method  string `Method=`
	// contains filtered or unexported fields
}

Remove a member from a queue and redirect the member's call to a TwiML site

type DeleteNotification

type DeleteNotification struct {
	Sid string
	// contains filtered or unexported fields
}

DeleteNotification struct for removal of a notification

type DeleteOutgoingCallerId

type DeleteOutgoingCallerId struct {
	Sid string
	// contains filtered or unexported fields
}

type DeleteParticipant

type DeleteParticipant struct {
	Sid     string // Conference Sid
	CallSid string // required field
	// contains filtered or unexported fields
}

Remove a participant from a conference

type DeleteQueue

type DeleteQueue struct {
	Sid string // QueueSid
	// contains filtered or unexported fields
}

Remove a queue

type DeleteRecording

type DeleteRecording struct {
	Sid string // RecordingSid
	// contains filtered or unexported fields
}

Delete a recording

type ExceptionResponse

type ExceptionResponse struct {
	Code     int
	Message  string
	MoreInfo string
	Status   string
}

type MakeCall

type MakeCall struct {
	From                 string `From=`
	To                   string `To=`
	Url                  string `Url=`
	ApplicationSid       string `ApplicationSid=`
	Method               string `Method=`
	FallbackUrl          string `FallbackUrl=`
	FallbackMethod       string `FallbackMethod=`
	StatusCallback       string `StatusCallback=`
	StatusCallbackMethod string `StatusCallbackMethod=`
	SendDigits           string `SendDigits=`
	IfMachine            string `IfMachine=`
	Timeout              string `Timeout=`
	Record               string `Record=`
	SipAuthUsername      string `SipAuthUsername=`
	SipAuthPassword      string `SipAuthPassword=`
	// contains filtered or unexported fields
}

Request to make a phone call

type Message

type Message struct {
	Sid      string // MessageSid
	Media    bool
	MediaSid string
	// contains filtered or unexported fields
}

Message struct for request of single message

type MessageResponse

type MessageResponse struct {
	Sid         string
	DateCreated string
	DateUpdated string
	DateSent    string
	AccountSid  string
	To          string
	From        string
	Body        string
	NumSegments string
	Status      string
	Direction   string
	Price       string
	PriceUnit   string
	ApiVersion  string
	Uri         string
}

type Messages

type Messages struct {
	To             string `To=`
	From           string `From=`
	DateSent       string `DateSent=`
	DateSentBefore string `DateSent<=`
	DateSentAfter  string `DateSent>=`
	// contains filtered or unexported fields
}

Messages struct for request of list of messages

type MessagesResponse

type MessagesResponse struct {
	Page
	Message []MessageResponse
}

type ModifyCall

type ModifyCall struct {
	Sid                  string
	Url                  string `Url=`
	Method               string `Method=`
	Status               string `Status=`
	FallbackUrl          string `FallbackUrl=`
	FallbackMethod       string `FallbackMethod=`
	StatusCallback       string `StatusCallback=`
	StatusCallbackMethod string `StatusCallbackMethod=`
	// contains filtered or unexported fields
}

Request to modify call in queue/progress

type Notification

type Notification struct {
	Sid string
	// contains filtered or unexported fields
}

Notification struct for request of a specific notification

type NotificationResponse

type NotificationResponse struct {
	Sid           string
	DateCreated   string
	DateUpdated   string
	AccountSid    string
	CallSid       string
	ApiVersion    string
	Log           string
	ErrorCode     string
	MoreInfo      string
	MessageText   string
	MessageDate   string
	RequestUrl    string
	RequestMethod string
	Uri           string
	// The fields below are only included in
	// resource from 'Notification' request
	RequestVariables string
	ResponseHeaders  string
	ResponseBody     string
}

type Notifications

type Notifications struct {
	Log           string `Log=`
	MsgDate       string `MessageDate=`
	MsgDateBefore string `MessageDate<=`
	MsgDateAfter  string `MessageDate>=`
	// contains filtered or unexported fields
}

Notifications struct for request of a possible list of notifications

type NotificationsResponse

type NotificationsResponse struct {
	Page
	Notification []NotificationResponse
}

type OutgoingCallerId

type OutgoingCallerId struct {
	Sid string
	// contains filtered or unexported fields
}

Get outgoing caller ID

type OutgoingCallerIdResponse

type OutgoingCallerIdResponse struct {
	Sid          string
	DateCreated  string
	DateUpdated  string
	FriendlyName string
	AccountSid   string
	PhoneNumber  string
	Uri          string
}

type OutgoingCallerIds

type OutgoingCallerIds struct {
	PhoneNumber  string `PhoneNumber=`
	FriendlyName string `FriendlyName=`
	// contains filtered or unexported fields
}

Get outgoing caller IDs

type OutgoingCallerIdsResponse

type OutgoingCallerIdsResponse struct {
	Page
	OutgoingCallerId []OutgoingCallerIdResponse
}

type Page

type Page struct {
	Page            uint   `xml:"page,attr"`
	NumPages        uint   `xml:"numpages,attr"`
	PageSize        uint   `xml:"pagesize,attr"`
	Total           uint   `xml:"total,attr"`
	Start           uint   `xml:"start,attr"`
	End             uint   `xml:"end,attr"`
	Uri             string `xml:"uri,attr"`
	FirstPageUri    string `xml:"firstpageuri,attr"`
	PreviousPageUri string `xml:"previouspageuri,attr"`
	NextPageUri     string `xml:"nextpageuri,attr"`
	LastPageUri     string `xml:"lastpageuri,attr"`
}

type Participant

type Participant struct {
	Sid     string // Conference Sid
	CallSid string // required field
	// contains filtered or unexported fields
}

Resource about single conference participant

type ParticipantResponse

type ParticipantResponse struct {
	ConferenceSid          string
	AccountSid             string
	CallSid                string
	Muted                  string
	EndConferenceOnExit    string
	StartConferenceOnEnter string
	DateCreated            string
	DateUpdated            string
	Uri                    string
}

type Participants

type Participants struct {
	Sid   string // Conference Sid
	Muted string `Muted=`
	// contains filtered or unexported fields
}

Request list of participants in a conference

type ParticipantsResponse

type ParticipantsResponse struct {
	Page
	Participant []ParticipantResponse
}

type Queue

type Queue struct {
	Sid string // QueueSid
	// contains filtered or unexported fields
}

Get resource for an individual Queue instance

type QueueMember

type QueueMember struct {
	Sid     string // QueueSid
	CallSid string // either this field or Front is required
	Front   bool
	// contains filtered or unexported fields
}

Request resource for a queue member

type QueueMemberResponse

type QueueMemberResponse struct {
	CallSid      string
	DateEnqueued string
	WaitTime     string
	Position     string
}

type QueueMembers

type QueueMembers struct {
	Sid string // QueueSid
	// contains filtered or unexported fields
}

List members of a queue

type QueueMembersResponse

type QueueMembersResponse struct {
	Page
	QueueMember []QueueMemberResponse
}

type QueueResponse

type QueueResponse struct {
	Sid             string
	FriendlyName    string
	CurrentSize     string
	MaxSize         string
	AverageWaitTime string
	DateCreated     string
	DateUpdated     string
	Uri             string
}

type Queues

type Queues struct {
	// contains filtered or unexported fields
}

List queues within an account

type QueuesResponse

type QueuesResponse struct {
	Page
	Queue []QueueResponse
}

type Recording

type Recording struct {
	Sid string // RecordingSid
	// contains filtered or unexported fields
}

Request resource for an individual recording

type RecordingResponse

type RecordingResponse struct {
	Sid         string
	DateCreated string
	DateUpdated string
	AccountSid  string
	CallSid     string
	ApiVersion  string
	Uri         string
	Duration    string
}

type Recordings

type Recordings struct {
	CallSid           string `CallSid=`
	DateCreated       string `DateCreated=`
	DateCreatedBefore string `DateCreated<=`
	DateCreatedAfter  string `DateCreated>=`
	// contains filtered or unexported fields
}

List recordings resource

type RecordingsResponse

type RecordingsResponse struct {
	Page
	Recording []RecordingResponse
}

type ResponseStatus

type ResponseStatus struct {
	Http   int
	Twilio int
}

type SendMessage

type SendMessage struct {
	Text                string `Body=`
	MediaUrl            string `MediaUrl=`
	From                string `From=`
	To                  string `To=`
	MessagingServiceSid string `MessagingServiceSid=`
	ApplicationSid      string `ApplicationSid=`
	StatusCallback      string `StatusCallback=`
	// contains filtered or unexported fields
}

Message struct for request to send a message

type TwilioClient

type TwilioClient struct {
	// contains filtered or unexported fields
}

TwilioClient struct for holding a http client and user credentials

func NewClient

func NewClient(accountSid, authToken string) *TwilioClient

Create a new client

func (*TwilioClient) Request

func (twiClient *TwilioClient) Request(reqStruct interface{}) (
	TwilioResponse, error)

Request makes a REST resource or action request from twilio servers and returns the response. The type of request is determined by the request struct supplied.

func (*TwilioClient) ValidateRequest

func (twiClient *TwilioClient) ValidateRequest(fullUrl string, req *http.Request) error

ValidateRequest will take the incoming http.Request on a Twilio callback URL and verify that the X-Twilio-Signature is correct. fullUrl must be in the format of https://www.exampe.com/twilio/callback?param1=exists

This can be used to create custom middleware to make it easy to verify the request is sent from Twilio. Documentation about this method is available at https://www.twilio.com/docs/api/security#validating-requests

type TwilioResponse

type TwilioResponse struct {
	Accounts          *AccountsResponse          `xml:"Accounts"`
	Account           *AccountResponse           `xml:"Account"`
	Calls             *CallsResponse             `xml:"Calls"`
	Call              *CallResponse              `xml:"Call"`
	Conferences       *ConferencesResponse       `xml:"Conferences"`
	Conference        *ConferenceResponse        `xml:"Conference"`
	Exception         *ExceptionResponse         `xml:"RestException"`
	Messages          *MessagesResponse          `xml:"Messages"`
	Message           *MessageResponse           `xml:"Message"`
	Notifications     *NotificationsResponse     `xml:"Notifications"`
	Notification      *NotificationResponse      `xml:"Notification"`
	OutgoingCallerIds *OutgoingCallerIdsResponse `xml:"OutgoingCallerIds"`
	OutgoingCallerId  *OutgoingCallerIdResponse  `xml:"OutgoingCallerId"`
	Participants      *ParticipantsResponse      `xml:"Participants"`
	Participant       *ParticipantResponse       `xml:"Participant"`
	Recordings        *RecordingsResponse        `xml:"Recordings"`
	Recording         *RecordingResponse         `xml:"Recording"`
	Queues            *QueuesResponse            `xml:"Queues"`
	Queue             *QueueResponse             `xml:"Queue"`
	QueueMembers      *QueueMembersResponse      `xml:"QueueMembers"`
	QueueMember       *QueueMemberResponse       `xml:"QueueMember"`
	UsageRecords      *UsageRecordsResponse      `xml:"UsageRecords"`
	ValidationRequest *ValidationRequestResponse `xml:"ValidationRequest"`
	Status            ResponseStatus
}

TwilioResponse holds one possible resource/response depending on type of request plus a Status struct.

type UpdateOutgoingCallerId

type UpdateOutgoingCallerId struct {
	Sid          string
	FriendlyName string `FriendlyName=`
	// contains filtered or unexported fields
}

type UpdateParticipant

type UpdateParticipant struct {
	Sid     string // Conference Sid
	CallSid string // required field
	Muted   string `Muted=`
	// contains filtered or unexported fields
}

Request to change the status of a participant

type UsageRecordResponse

type UsageRecordResponse struct {
	Category        string
	Description     string
	AccountSid      string
	StartDate       string
	EndDate         string
	Usage           string
	UsageUnit       string
	Count           string
	CountUnit       string
	Price           string
	PriceUnit       string
	Uri             string
	SubresourceUris *UsageRecordSubUris
}

type UsageRecordSubUris

type UsageRecordSubUris struct {
	Daily     string
	Monthly   string
	Yearly    string
	AllTime   string
	Today     string
	Yesterday string
	ThisMonth string
	LastMonth string
}

type UsageRecords

type UsageRecords struct {
	SubResource string
	Category    string `Category=`
	StartDate   string `StartDate=`
	EndDate     string `EndDate=`
	// contains filtered or unexported fields
}

Request usage by the account

type UsageRecordsResponse

type UsageRecordsResponse struct {
	Page
	UsageRecord []UsageRecordResponse
}

type ValidationRequestResponse

type ValidationRequestResponse struct {
	AccountSid     string
	PhoneNumber    string
	FriendlyName   string
	ValidationCode string
	CallSid        string
}

Response from AddOutgoingCallerId

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL