Documentation
¶
Overview ¶
Package twiml implements tooling to create, parse, and validate Twilio Twiml requests and responses
Index ¶
- func FormatNumber(number string) (string, error)
- type BeepType
- type Conference
- func (c *Conference) SetBeep(beep BeepType) *Conference
- func (c *Conference) SetCoach(coach string) *Conference
- func (c *Conference) SetEndConferenceOnExit(endConferenceOnExit bool) *Conference
- func (c *Conference) SetEventCallbackURL(eventCallbackURL string) *Conference
- func (c *Conference) SetMaxParticipants(maxParticipants int) *Conference
- func (c *Conference) SetMuted(muted bool) *Conference
- func (c *Conference) SetRecord(record string) *Conference
- func (c *Conference) SetRecordingStatusCallback(recordingStatusCallback string) *Conference
- func (c *Conference) SetRecordingStatusCallbackEvent(recordingStatusCallbackEvent string) *Conference
- func (c *Conference) SetRecordingStatusCallbackMethod(recordingStatusCallbackMethod MethodType) *Conference
- func (c *Conference) SetRegion(region string) *Conference
- func (c *Conference) SetStartConferenceOnEnter(startConferenceOnEnter bool) *Conference
- func (c *Conference) SetStatusCallback(statusCallback string) *Conference
- func (c *Conference) SetStatusCallbackEvent(statusCallbackEvent ConferenceCallbackEvent) *Conference
- func (c *Conference) SetStatusCallbackMethod(statusCallbackMethod MethodType) *Conference
- func (c *Conference) SetTrim(trim string) *Conference
- func (c *Conference) SetWaitMethod(waitMethod MethodType) *Conference
- func (c *Conference) SetWaitURL(waitURL string) *Conference
- type ConferenceCallbackEvent
- func (c ConferenceCallbackEvent) End() ConferenceCallbackEvent
- func (c ConferenceCallbackEvent) Hold() ConferenceCallbackEvent
- func (c ConferenceCallbackEvent) Join() ConferenceCallbackEvent
- func (c ConferenceCallbackEvent) Leave() ConferenceCallbackEvent
- func (c ConferenceCallbackEvent) Mute() ConferenceCallbackEvent
- func (c ConferenceCallbackEvent) Speaker() ConferenceCallbackEvent
- func (c ConferenceCallbackEvent) Start() ConferenceCallbackEvent
- type Connect
- type Dial
- type Gather
- func (g *Gather) Pause(length uint) *Gather
- func (g *Gather) Say(say *Say) *Gather
- func (g *Gather) SetAction(action string) *Gather
- func (g *Gather) SetInput(input string) *Gather
- func (g *Gather) SetMethod(method MethodType) *Gather
- func (g *Gather) SetNumDigits(numDigits uint) *Gather
- func (g *Gather) SetTimeout(timeout uint) *Gather
- type Hangup
- type MethodType
- type Number
- type Parameter
- type ParsedNumber
- type Pause
- type Play
- type Redirect
- type Request
- type RequestValues
- type Response
- func (r *Response) Connect(connect *Connect) *Response
- func (r *Response) Dial(dial *Dial) *Response
- func (r *Response) Gather(gather *Gather) *Response
- func (r *Response) Hangup() *Response
- func (r *Response) Pause(length uint) *Response
- func (r *Response) Play(play *Play) *Response
- func (r *Response) Redirect(redirect *Redirect) *Response
- func (r *Response) Render(ctx context.Context) ([]byte, error)
- func (r *Response) RenderTo(ctx context.Context, w io.Writer) error
- func (r *Response) Say(say *Say) *Response
- func (r *Response) Start(start *Start) *Response
- type Say
- type Start
- type Stream
- func (s *Stream) Parameter(stream *Parameter) *Stream
- func (s *Stream) SetName(name string) *Stream
- func (s *Stream) SetStatusCallback(statusCallback string) *Stream
- func (s *Stream) SetStatusCallbackMethod(statusCallbackMethod MethodType) *Stream
- func (s *Stream) SetTrack(track TrackType) *Stream
- func (s *Stream) SetURL(url string) *Stream
- type TrackType
- type VoiceType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatNumber ¶
FormatNumber formates a number to E164 format
Types ¶
type Conference ¶
type Conference struct {
XMLName xml.Name `xml:"Conference"`
Muted bool `xml:"muted,attr,omitempty"`
Beep BeepType `xml:"beep,attr,omitempty"`
StartConferenceOnEnter *bool `xml:"startConferenceOnEnter,attr"`
EndConferenceOnExit bool `xml:"endConferenceOnExit,attr,omitempty"`
WaitURL *string `xml:"waitUrl,attr"`
WaitMethod MethodType `xml:"waitMethod,attr,omitempty"`
MaxParticipants int `xml:"maxParticipants,attr,omitempty"`
Record string `xml:"record,attr,omitempty"`
Region string `xml:"region,attr,omitempty"`
Trim string `xml:"trim,attr,omitempty"`
Coach string `xml:"coach,attr,omitempty"`
StatusCallbackEvent string `xml:"statusCallbackEvent,attr,omitempty"`
StatusCallback string `xml:"statusCallback,attr,omitempty"`
StatusCallbackMethod MethodType `xml:"statusCallbackMethod,attr,omitempty"`
RecordingStatusCallback string `xml:"recordingStatusCallback,attr,omitempty"`
RecordingStatusCallbackMethod MethodType `xml:"recordingStatusCallbackMethod,attr,omitempty"`
RecordingStatusCallbackEvent string `xml:"recordingStatusCallbackEvent,attr,omitempty"`
EventCallbackURL string `xml:"eventCallbackUrl,attr,omitempty"`
Value string `xml:",chardata"`
}
Conference represents the twiml Conference verb
func NewConference ¶
func NewConference(conferenceName string) *Conference
NewConference returns a Conference verb
func (*Conference) SetBeep ¶
func (c *Conference) SetBeep(beep BeepType) *Conference
SetBeep sets the beep attribute
func (*Conference) SetCoach ¶
func (c *Conference) SetCoach(coach string) *Conference
SetCoach sets the coach attribute
func (*Conference) SetEndConferenceOnExit ¶
func (c *Conference) SetEndConferenceOnExit(endConferenceOnExit bool) *Conference
SetEndConferenceOnExit sets the endConferenceOnExit attribute
func (*Conference) SetEventCallbackURL ¶
func (c *Conference) SetEventCallbackURL(eventCallbackURL string) *Conference
SetEventCallbackURL sets the eventCallbackURL attribute
func (*Conference) SetMaxParticipants ¶
func (c *Conference) SetMaxParticipants(maxParticipants int) *Conference
SetMaxParticipants sets the maxParticipants attribute
func (*Conference) SetMuted ¶
func (c *Conference) SetMuted(muted bool) *Conference
SetMuted sets the muted attribute
func (*Conference) SetRecord ¶
func (c *Conference) SetRecord(record string) *Conference
SetRecord sets the record attribute
func (*Conference) SetRecordingStatusCallback ¶
func (c *Conference) SetRecordingStatusCallback(recordingStatusCallback string) *Conference
SetRecordingStatusCallback sets the recordingStatusCallback attribute
func (*Conference) SetRecordingStatusCallbackEvent ¶
func (c *Conference) SetRecordingStatusCallbackEvent(recordingStatusCallbackEvent string) *Conference
SetRecordingStatusCallbackEvent sets the recordingStatusCallbackEvent attribute
func (*Conference) SetRecordingStatusCallbackMethod ¶
func (c *Conference) SetRecordingStatusCallbackMethod(recordingStatusCallbackMethod MethodType) *Conference
SetRecordingStatusCallbackMethod sets the recordingStatusCallbackMethod attribute
func (*Conference) SetRegion ¶
func (c *Conference) SetRegion(region string) *Conference
SetRegion sets the region attribute
func (*Conference) SetStartConferenceOnEnter ¶
func (c *Conference) SetStartConferenceOnEnter(startConferenceOnEnter bool) *Conference
SetStartConferenceOnEnter sets the startConferenceOnEnter attribute
func (*Conference) SetStatusCallback ¶
func (c *Conference) SetStatusCallback(statusCallback string) *Conference
SetStatusCallback sets the statusCallback attribute
func (*Conference) SetStatusCallbackEvent ¶
func (c *Conference) SetStatusCallbackEvent(statusCallbackEvent ConferenceCallbackEvent) *Conference
SetStatusCallbackEvent sets the statusCallbackEvent attribute
func (*Conference) SetStatusCallbackMethod ¶
func (c *Conference) SetStatusCallbackMethod(statusCallbackMethod MethodType) *Conference
SetStatusCallbackMethod sets the statusCallbackMethod attribute
func (*Conference) SetTrim ¶
func (c *Conference) SetTrim(trim string) *Conference
SetTrim sets the trim attribute
func (*Conference) SetWaitMethod ¶
func (c *Conference) SetWaitMethod(waitMethod MethodType) *Conference
SetWaitMethod sets the waitMethod attribute
func (*Conference) SetWaitURL ¶
func (c *Conference) SetWaitURL(waitURL string) *Conference
SetWaitURL sets the waitURL attribute
type ConferenceCallbackEvent ¶ added in v0.0.2
type ConferenceCallbackEvent string
ConferenceCallbackEvent can be one of start, end, join, leave, mute, hold, and speaker
func ConferenceCallbackEvents ¶
func ConferenceCallbackEvents() ConferenceCallbackEvent
ConferenceCallbackEvents enables specific Callback Events
func (ConferenceCallbackEvent) End ¶ added in v0.0.2
func (c ConferenceCallbackEvent) End() ConferenceCallbackEvent
End enables the Callback Event to indicate Conference has Ended
func (ConferenceCallbackEvent) Hold ¶ added in v0.0.2
func (c ConferenceCallbackEvent) Hold() ConferenceCallbackEvent
Hold enables the Callback Event to indicate Participant has been held
func (ConferenceCallbackEvent) Join ¶ added in v0.0.2
func (c ConferenceCallbackEvent) Join() ConferenceCallbackEvent
Join enables the Callback Event to indicate Participant has joined
func (ConferenceCallbackEvent) Leave ¶ added in v0.0.2
func (c ConferenceCallbackEvent) Leave() ConferenceCallbackEvent
Leave enables the Callback Event to indicate Participant has left
func (ConferenceCallbackEvent) Mute ¶ added in v0.0.2
func (c ConferenceCallbackEvent) Mute() ConferenceCallbackEvent
Mute enables the Callback Event to indicate Participant has been muted/unmuted
func (ConferenceCallbackEvent) Speaker ¶ added in v0.0.2
func (c ConferenceCallbackEvent) Speaker() ConferenceCallbackEvent
Speaker enables the Callback Event to indicate Participant has started/stoped speaking
func (ConferenceCallbackEvent) Start ¶ added in v0.0.2
func (c ConferenceCallbackEvent) Start() ConferenceCallbackEvent
Start enables the Callback Event to indicate Conference has Started
type Connect ¶ added in v0.0.4
type Connect struct {
XMLName xml.Name `xml:"Connect"`
Action string `xml:"action,attr,omitempty"`
Method MethodType `xml:"method,attr,omitempty"`
Verbs []interface{}
}
Connect represents the TwiML Connect verb
func (*Connect) SetMethod ¶ added in v0.0.4
func (c *Connect) SetMethod(method MethodType) *Connect
SetMethod sets the method attribute
type Dial ¶
type Dial struct {
XMLName xml.Name `xml:"Dial"`
Action string `xml:"action,attr,omitempty"`
Method MethodType `xml:"method,attr,omitempty"`
Timeout uint `xml:"timeout,attr,omitempty"`
Verbs []interface{}
}
Dial represents the TwiML Dial Verb
func (*Dial) Conference ¶
func (d *Dial) Conference(conference *Conference) *Dial
Conference appends a Conference verb to Dial
type Gather ¶
type Gather struct {
XMLName xml.Name `xml:"Gather"`
Input string `xml:"input,attr,omitempty"`
Action string `xml:"action,attr,omitempty"`
Method MethodType `xml:"method,attr,omitempty"`
Timeout uint `xml:"timeout,attr,omitempty"`
FinishOnKey *string `xml:"finishOnKey,attr"`
NumDigits uint `xml:"numDigits,attr,omitempty"`
PartialResultCallback string `xml:"partialResultCallback,attr,omitempty"`
PartialResultCallbackMethod MethodType `xml:"partialResultCallbackMethod,attr,omitempty"`
Language string `xml:"language,attr,omitempty"`
Hints string `xml:"hints,attr,omitempty"`
ProfanityFilter bool `xml:"profanityFilter,attr,omitempty"`
SpeechTimeout uint `xml:"speechTimeout,attr,omitempty"`
Verbs []interface{}
}
Gather represents the TwiML Gather verb
func (*Gather) SetMethod ¶
func (g *Gather) SetMethod(method MethodType) *Gather
SetMethod sets the method attribute
func (*Gather) SetNumDigits ¶
SetNumDigits sets the numDigits attribute
func (*Gather) SetTimeout ¶
SetTimeout sets the timeout attribute
type MethodType ¶
type MethodType string
MethodType is an enum for the http method
const ( // Post represents an HTTP POST method Post MethodType = "POST" // Get represents an HTTP GETmethod Get MethodType = "GET" )
type Parameter ¶
type Parameter struct {
XMLName xml.Name `xml:"Parameter"`
Name string `xml:"name,attr,omitempty"`
Value string `xml:"value,attr,omitempty"`
}
Parameter represents the TwiML Parameter verb
type ParsedNumber ¶
type ParsedNumber struct {
Valid bool
Number string
SIP bool
SIPDomain string
Region string
Raw string
App bool
AppID string
Client bool
ClientID string
}
ParsedNumber represents a parsed phone number or SIP URI.
func ParseNumber ¶
func ParseNumber(v string) *ParsedNumber
ParseNumber parses ether a E164 number or a SIP URI returning a ParsedNumber
type Play ¶
type Play struct {
XMLName xml.Name `xml:"Play"`
Digits string `xml:"digits,attr,omitempty"`
Loop uint `xml:"loop,attr,omitempty"`
Value string `xml:",chardata"`
}
Play represents the TwiML Play verb
type Redirect ¶
type Redirect struct {
XMLName xml.Name `xml:"Redirect"`
Method MethodType `xml:"method,attr,omitempty"`
Value string `xml:",chardata"`
}
Redirect represents the TwiML Redirect verb
func (*Redirect) SetMethod ¶
func (r *Redirect) SetMethod(method MethodType) *Redirect
SetMethod sets the method attribute
type Request ¶
type Request struct {
Values RequestValues
// contains filtered or unexported fields
}
Request is a twillio request expecting a TwiML response
type RequestValues ¶
RequestValues hold form values from a validated Request
func (RequestValues) CallDuration ¶
func (r RequestValues) CallDuration() (time.Duration, error)
CallDuration Parses the duration from the string value
func (RequestValues) From ¶
func (r RequestValues) From() *ParsedNumber
From returns a Number parsed from the raw From value
func (RequestValues) SequenceNumber ¶
func (r RequestValues) SequenceNumber() (int, error)
SequenceNumber Parses the sequence number from the string value
func (RequestValues) TimestampOrNow ¶
func (r RequestValues) TimestampOrNow() time.Time
TimestampOrNow parses the Timestamp from string. If Timestamp does not exist in the current request, time.Now() is returned instead.
func (RequestValues) To ¶
func (r RequestValues) To() *ParsedNumber
To returns a Number parsed from the raw To value
type Response ¶
type Response struct {
Verbs []interface{}
}
Response represents the TwiML Response Verb
type Say ¶
type Say struct {
XMLName xml.Name `xml:"Say"`
Voice VoiceType `xml:"voice,attr,omitempty"`
Loop uint `xml:"loop,attr,omitempty"`
Value string `xml:",chardata"`
}
Say represents the TwiML Say verb
type Stream ¶
type Stream struct {
XMLName xml.Name `xml:"Stream"`
Track TrackType `xml:"track,attr,omitempty"`
Name string `xml:"name,attr,omitempty"`
URL string `xml:"url,attr,omitempty"`
StatusCallback string `xml:"statusCallback,attr,omitempty"`
StatusCallbackMethod MethodType `xml:"statusCallbackMethod,attr,omitempty"`
Verbs []interface{}
}
Stream represents the TwiML Stream verb
func (*Stream) SetStatusCallback ¶
SetStatusCallback sets the statusCallback attribute
func (*Stream) SetStatusCallbackMethod ¶
func (s *Stream) SetStatusCallbackMethod(statusCallbackMethod MethodType) *Stream
SetStatusCallbackMethod sets the statusCallbackMethod attribute
type VoiceType ¶
type VoiceType string
VoiceType is enum type for voice
const ( // ManVoice is used in Say to select man voice ManVoice VoiceType = "man" // WomenVoice is used in Say to select woman voice WomenVoice VoiceType = "women" // AliceVoice is used in Say to select alice voice AliceVoice VoiceType = "alice" // PollyMatthew is used in Say to select Amazon Poly voice Matthew PollyMatthew VoiceType = "Polly.Matthew" )