twiml

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: MIT Imports: 18 Imported by: 0

README

twiml

GoDoc

twiml is a libruary for formating TwiML (the Twilio Markup Language). TwiML is a set of instructions you can use to tell Twilio what to do when you receive an incoming call or SMS.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConferenceCallbackEvents

func ConferenceCallbackEvents() conferenceCallbackEvents

ConferenceCallbackEvents enables specific Callback Events

func FormatNumber

func FormatNumber(number string) (string, error)

FormatNumber formates a number to E164 format

Types

type BeepType

type BeepType string

BeepType is an enum type for Beep

const (
	// BeepsOn beeps on enter and exit
	BeepsOn BeepType = "true"

	// BeepsOff disables beeps
	BeepsOff BeepType = "false"

	// BeepOnEnter beeps on enter only
	BeepOnEnter BeepType = "onEnter"

	// BeepOnExit beeps on exit only
	BeepOnExit BeepType = "onExit"
)

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 conferenceCallbackEvents) *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 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 NewDial

func NewDial() *Dial

NewDial returns a Dial verb

func (*Dial) Conference

func (d *Dial) Conference(conference *Conference) *Dial

Conference appends a Conference verb to Dial

func (*Dial) Number

func (d *Dial) Number(number *Number) *Dial

Number appends a Number 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 NewGather

func NewGather() *Gather

NewGather returns a Gather verb

func (*Gather) Pause

func (g *Gather) Pause(length uint) *Gather

Pause appends a Pause verb to Gather

func (*Gather) Say

func (g *Gather) Say(say *Say) *Gather

Say appends a Say verb to Gather

func (*Gather) SetAction

func (g *Gather) SetAction(action string) *Gather

SetAction sets the action attribute

func (*Gather) SetInput

func (g *Gather) SetInput(input string) *Gather

SetInput sets the input attribute

func (*Gather) SetMethod

func (g *Gather) SetMethod(method MethodType) *Gather

SetMethod sets the method attribute

func (*Gather) SetNumDigits

func (g *Gather) SetNumDigits(numDigits uint) *Gather

SetNumDigits sets the numDigits attribute

func (*Gather) SetTimeout

func (g *Gather) SetTimeout(timeout uint) *Gather

SetTimeout sets the timeout attribute

type Hangup

type Hangup struct {
	XMLName xml.Name `xml:"Hangup"`
}

Hangup represents the TwiML Hangup verb

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 Number

type Number struct {
	XMLName xml.Name `xml:"Number"`
	Value   string   `xml:",chardata"`
}

Number represents a phone number to call

func NewNumber

func NewNumber(number string) *Number

NewNumber returns a Number verb

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

func NewParameter

func NewParameter() *Parameter

NewParameter returns a Parameter verb

func (*Parameter) SetName

func (s *Parameter) SetName(name string) *Parameter

SetName sets the Name attribute

func (*Parameter) SetValue

func (s *Parameter) SetValue(value string) *Parameter

SetValue sets the value attribute

type ParsedNumber

type ParsedNumber struct {
	Valid     bool
	Number    string
	Sip       bool
	SipDomain string
	Region    string
	Raw       string
}

func ParseNumber

func ParseNumber(v string) *ParsedNumber

ParseNumber parses ether a E164 number or a SIP URI returning a ParsedNumber

type Pause

type Pause struct {
	XMLName xml.Name `xml:"Pause"`
	Length  uint     `xml:"length,attr,omitempty"`
}

Pause represents the TwiML Pause verb

func NewPause

func NewPause(length uint) *Pause

NewPause returns a Pause verb

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

func NewPlay

func NewPlay(msg string) *Play

NewPlay returns a Play verb

func (*Play) SetDigits

func (p *Play) SetDigits(digits string) *Play

SetDigits sets the digits value

func (*Play) SetLoop

func (p *Play) SetLoop(loop uint) *Play

SetLoop sets the Loop value

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 NewRedirect

func NewRedirect(redirect string) *Redirect

NewRedirect returns a 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

func NewRequest

func NewRequest(host string, r *http.Request) *Request

NewRequest returns Request

func (*Request) ValidatePost

func (req *Request) ValidatePost(ctx context.Context, authToken string) error

ValidatePost validates the Twilio Signature, requiring that the request is a POST

type RequestValues

type RequestValues map[string]string

RequestValues hold form values from a validated Request

func (RequestValues) CallDuration

func (r RequestValues) CallDuration() (int, 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 duration rom 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

func NewResponse

func NewResponse() *Response

NewResponse returns a Response

func (*Response) Dial

func (r *Response) Dial(dial *Dial) *Response

Dial adds the dial verb to the response

func (*Response) Gather

func (r *Response) Gather(gather *Gather) *Response

Gather adds the Gather verb to the response

func (*Response) Hangup

func (r *Response) Hangup() *Response

Hangup adds the hangup verb to the Response

func (*Response) Pause

func (r *Response) Pause(length uint) *Response

Pause appends a Pause verb to Dial

func (*Response) Play

func (r *Response) Play(play *Play) *Response

Play adds the play verb to the Response

func (*Response) Redirect

func (r *Response) Redirect(redirect *Redirect) *Response

Redirect appends a Redirect verb to Response

func (*Response) Render

func (r *Response) Render(ctx context.Context) ([]byte, error)

Render returns the rendered twiml response

func (*Response) RenderTo

func (r *Response) RenderTo(ctx context.Context, w io.Writer) error

RenderTo writes the Rendered TwiML to the writer

func (*Response) Say

func (r *Response) Say(say *Say) *Response

Say adds the say verb to the Response

func (*Response) Start

func (r *Response) Start(start *Start) *Response

Start adds the start verb to the Response

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

func NewSay

func NewSay(msg string) *Say

NewSay returns a Say verb

func (*Say) SetLoop

func (s *Say) SetLoop(loop uint) *Say

SetLoop sets the Loop value

func (*Say) SetVoice

func (s *Say) SetVoice(voice VoiceType) *Say

SetVoice sets the voice value

type Start

type Start struct {
	XMLName xml.Name `xml:"Start"`
	Verbs   []interface{}
}

Start represents the TwiML Start verb

func NewStart

func NewStart() *Start

NewStart returns a Start verb

func (*Start) Stream

func (s *Start) Stream(stream *Stream) *Start

Stream adds the stream verb to the Start

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 NewStream

func NewStream() *Stream

NewStream returns a Stream verb

func (*Stream) Parameter

func (s *Stream) Parameter(stream *Parameter) *Stream

Parameter adds the stream verb to the Start

func (*Stream) SetName

func (s *Stream) SetName(name string) *Stream

SetName sets the Name attribute

func (*Stream) SetStatusCallback

func (s *Stream) SetStatusCallback(statusCallback string) *Stream

SetStatusCallback sets the statusCallback attribute

func (*Stream) SetStatusCallbackMethod

func (s *Stream) SetStatusCallbackMethod(statusCallbackMethod MethodType) *Stream

SetStatusCallbackMethod sets the statusCallbackMethod attribute

func (*Stream) SetTrack

func (s *Stream) SetTrack(track TrackType) *Stream

SetTrack sets the track value

func (*Stream) SetURL

func (s *Stream) SetURL(url string) *Stream

SetURL sets the URL attribute

type TrackType

type TrackType string

TrackType is an enum for the track type

const (
	// InboundTrack represents an inbound_track
	InboundTrack TrackType = "inbound_track"

	// OutboundTrack represents an outbound_track
	OutboundTrack TrackType = "outbound_track"

	// BothTracks represents an both_tracks
	BothTracks TrackType = "both_tracks"
)

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"
)

func (VoiceType) Say

func (v VoiceType) Say(msg string) *Say

Say returns a Say verb with voice set to current value

Jump to

Keyboard shortcuts

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