Skip to content

Commit

Permalink
Merge pull request #43 from kunal-plivo/master
Browse files Browse the repository at this point in the history
adds support for getInput XML verb
  • Loading branch information
kunal-plivo committed Oct 18, 2019
2 parents 8156590 + 4c4d0a0 commit 6ca01ac
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 1 deletion.
124 changes: 124 additions & 0 deletions xml/plivoxml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package xml

import (
"encoding/xml"

"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -462,6 +463,129 @@ func (e GetDigitsElement) SetContents(value []interface{}) GetDigitsElement {
return e
}

type GetInputElement struct {
Contents []interface{} `xml:",innerxml"`

Action *string `xml:"action,attr"`

Method *string `xml:"method,attr"`

InputType *string `xml:"inputType,attr"`

ExecutionTimeout *int `xml:"executionTimeout,attr"`

DigitEndTimeout *int `xml:"digitEndTimeout,attr"`

SpeechEndTimeout *int `xml:"speechEndTimeout,attr"`

FinishOnKey *string `xml:"finishOnKey,attr"`

NumDigits *int `xml:"numDigits,attr"`

SpeechModel *string `xml:"speechModel,attr"`

Hints *string `xml:"hints,attr"`

Language *string `xml:"language,attr"`

InterimSpeechResultsCallback *string `xml:"interimSpeechResultsCallback,attr"`

InterimSpeechResultsCallbackMethod *string `xml:"interimSpeechResultsCallbackMethod,attr"`

Redirect *bool `xml:"redirect,attr"`

Log *bool `xml:"log,attr"`

ProfanityFilter *string `xml:"profanityFilter,attr"`

XMLName xml.Name `xml:"GetInput"`
}

func (e GetInputElement) SetAction(value string) GetInputElement {
e.Action = &value
return e
}

func (e GetInputElement) SetMethod(value string) GetInputElement {
e.Method = &value
return e
}

func (e GetInputElement) SetInputType(value string) GetInputElement {
e.InputType = &value
return e
}

func (e GetInputElement) SetExecutionTimeout(value int) GetInputElement {
e.ExecutionTimeout = &value
return e
}

func (e GetInputElement) SetDigitEndTimeout(value int) GetInputElement {
e.DigitEndTimeout = &value
return e
}

func (e GetInputElement) SetSpeechEndTimeout(value int) GetInputElement {
e.SpeechEndTimeout = &value
return e
}

func (e GetInputElement) SetFinishOnKey(value string) GetInputElement {
e.FinishOnKey = &value
return e
}

func (e GetInputElement) SetNumDigits(value int) GetInputElement {
e.NumDigits = &value
return e
}

func (e GetInputElement) SetSpeechModel(value string) GetInputElement {
e.SpeechModel = &value
return e
}

func (e GetInputElement) SetHints(value string) GetInputElement {
e.Hints = &value
return e
}

func (e GetInputElement) SetLanguage(value string) GetInputElement {
e.Language = &value
return e
}

func (e GetInputElement) SetInterimSpeechResultsCallback(value string) GetInputElement {
e.InterimSpeechResultsCallback = &value
return e
}

func (e GetInputElement) SetInterimSpeechResultsCallbackMethod(value string) GetInputElement {
e.InterimSpeechResultsCallbackMethod = &value
return e
}

func (e GetInputElement) SetRedirect(value bool) GetInputElement {
e.Redirect = &value
return e
}

func (e GetInputElement) SetLog(value bool) GetInputElement {
e.Log = &value
return e
}

func (e GetInputElement) SetProfanityFilter(value string) GetInputElement {
e.ProfanityFilter = &value
return e
}

func (e GetInputElement) SetContents(value []interface{}) GetInputElement {
e.Contents = value
return e
}

type HangupElement struct {
Reason *string `xml:"reason,attr"`

Expand Down
3 changes: 2 additions & 1 deletion xml/plivoxml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestSimpleXML(t *testing.T) {
}

func TestComplexXML(t *testing.T) {
assert.Equal(t, "<Response><Message src=\"123\" dst=\"321\" type=\"sms\" callbackUrl=\"url\" callbackMethod=\"POST\">Plivo®</Message><Record action=\"action\" method=\"POST\" fileFormat=\"fileformat\" redirect=\"true\" timeout=\"10\" maxLength=\"100\" playBeep=\"true\" finishOnKey=\"key\" recordSession=\"true\" callbackUrl=\"url\" callbackMethod=\"POST\"></Record><Dial action=\"action\" method=\"POST\" hangupOnStar=\"true\" timeLimit=\"10\" timeout=\"10\" callbackUrl=\"url\" callbackMethod=\"POST\" redirect=\"true\" digitsMatch=\"123\" sipHeaders=\"h=1\"><Number sendDigits=\"123\" sendOnPreanswer=\"true\">123</Number><User sendDigits=\"123\" sendOnPreanswer=\"true\" sipHeaders=\"header=1\">user</User></Dial><DTMF async=\"true\">123</DTMF><Wait length=\"10\" silence=\"true\" minSilence=\"10\" beep=\"true\"></Wait><PreAnswer><Speak voice=\"MAN\" language=\"en\" loop=\"10\">text</Speak></PreAnswer><GetDigits action=\"action\" timeout=\"10\" digitTimeout=\"10\" finishOnKey=\"#\" numDigits=\"10\" retries=\"10\" redirect=\"true\" playBeep=\"true\" validDigits=\"123\" invalidDigitsSound=\"sound\"></GetDigits><Conference muted=\"true\" enterSound=\"sound\" exitSound=\"sound\" startConferenceOnEnter=\"true\" endConferenceOnExit=\"true\" stayAlone=\"true\" waitSound=\"sound\" maxMembers=\"10\" record=\"true\" recordFileFormat=\"rff\" timeLimit=\"10\" hangupOnStar=\"true\" action=\"action\" method=\"method\" callbackUrl=\"url\" callbackMethod=\"method\" digitsMatch=\"123\" floorEvent=\"true\" redirect=\"true\" relayDTMF=\"true\">name</Conference><Redirect method=\"POST\">url</Redirect><Play loop=\"10\">url</Play><Hangup reason=\"test\" schedule=\"10\"></Hangup></Response>", ResponseElement{
assert.Equal(t, "<Response><Message src=\"123\" dst=\"321\" type=\"sms\" callbackUrl=\"url\" callbackMethod=\"POST\">Plivo®</Message><Record action=\"action\" method=\"POST\" fileFormat=\"fileformat\" redirect=\"true\" timeout=\"10\" maxLength=\"100\" playBeep=\"true\" finishOnKey=\"key\" recordSession=\"true\" callbackUrl=\"url\" callbackMethod=\"POST\"></Record><Dial action=\"action\" method=\"POST\" hangupOnStar=\"true\" timeLimit=\"10\" timeout=\"10\" callbackUrl=\"url\" callbackMethod=\"POST\" redirect=\"true\" digitsMatch=\"123\" sipHeaders=\"h=1\"><Number sendDigits=\"123\" sendOnPreanswer=\"true\">123</Number><User sendDigits=\"123\" sendOnPreanswer=\"true\" sipHeaders=\"header=1\">user</User></Dial><DTMF async=\"true\">123</DTMF><Wait length=\"10\" silence=\"true\" minSilence=\"10\" beep=\"true\"></Wait><PreAnswer><Speak voice=\"MAN\" language=\"en\" loop=\"10\">text</Speak></PreAnswer><GetDigits action=\"action\" timeout=\"10\" digitTimeout=\"10\" finishOnKey=\"#\" numDigits=\"10\" retries=\"10\" redirect=\"true\" playBeep=\"true\" validDigits=\"123\" invalidDigitsSound=\"sound\"></GetDigits><GetInput action=\"action\" method=\"GET\" inputType=\"Speech\" executionTimeout=\"10\" digitEndTimeout=\"20\" speechEndTimeout=\"30\" finishOnKey=\"#\" numDigits=\"10\" speechModel=\"default\" hints=\"1 2 3\" language=\"en-us\" interimSpeechResultsCallback=\"interimCallback\" interimSpeechResultsCallbackMethod=\"POST\" redirect=\"true\" log=\"false\"><Speak voice=\"WOMAN\" language=\"en-US\" loop=\"1\">Tell us more about your experience</Speak></GetInput><Conference muted=\"true\" enterSound=\"sound\" exitSound=\"sound\" startConferenceOnEnter=\"true\" endConferenceOnExit=\"true\" stayAlone=\"true\" waitSound=\"sound\" maxMembers=\"10\" record=\"true\" recordFileFormat=\"rff\" timeLimit=\"10\" hangupOnStar=\"true\" action=\"action\" method=\"method\" callbackUrl=\"url\" callbackMethod=\"method\" digitsMatch=\"123\" floorEvent=\"true\" redirect=\"true\" relayDTMF=\"true\">name</Conference><Redirect method=\"POST\">url</Redirect><Play loop=\"10\">url</Play><Hangup reason=\"test\" schedule=\"10\"></Hangup></Response>", ResponseElement{
Contents: []interface{}{
new(MessageElement).SetSrc("123").SetDst("321").SetType("sms").SetCallbackMethod("POST").SetCallbackUrl("url").SetContents("Plivo®"),
new(RecordElement).SetCallbackMethod("POST").SetCallbackUrl("url").SetAction("action").SetFileFormat("fileformat").SetFinishOnKey("key").SetRecordSession(true).SetRedirect(true).SetPlayBeep(true).SetTimeout(10).SetMaxLength(100).SetMethod("POST"),
Expand All @@ -28,6 +28,7 @@ func TestComplexXML(t *testing.T) {
new(SpeakElement).SetContents("text").SetLanguage("en").SetLoop(10).SetVoice("MAN"),
}),
new(GetDigitsElement).SetPlayBeep(true).SetRedirect(true).SetFinishOnKey("#").SetAction("action").SetDigitTimeout(10).SetNumDigits(10).SetRetries(10).SetTimeout(10).SetValidDigits("123").SetInvalidDigitsSound("sound").SetContents([]interface{}{}),
new(GetInputElement).SetAction("action").SetMethod("GET").SetInputType("Speech").SetExecutionTimeout(10).SetDigitEndTimeout(20).SetSpeechEndTimeout(30).SetFinishOnKey("#").SetNumDigits(10).SetSpeechModel("default").SetLanguage("en-us").SetHints("1 2 3").SetInterimSpeechResultsCallback("interimCallback").SetInterimSpeechResultsCallbackMethod("POST").SetRedirect(true).SetLog(false).SetContents([]interface{}{new(SpeakElement).SetContents("Tell us more about your experience").SetVoice("WOMAN").SetLanguage("en-US").SetLoop(1)}),
new(ConferenceElement).SetAction("action").SetRedirect(true).SetCallbackUrl("url").SetCallbackMethod("method").SetContents("name").SetDigitsMatch("123").SetEndConferenceOnExit(true).SetEnterSound("sound").SetExitSound("sound").SetFloorEvent(true).SetHangupOnStar(true).SetMaxMembers(10).SetMethod("method").SetMuted(true).SetRecord(true).SetRecordFileFormat("rff").SetRelayDTMF(true).SetStartConferenceOnEnter(true).SetStayAlone(true).SetTimeLimit(10).SetWaitSound("sound"),
new(RedirectElement).SetMethod("POST").SetContents("url"),
new(PlayElement).SetContents("url").SetLoop(10),
Expand Down

0 comments on commit 6ca01ac

Please sign in to comment.