Вы находитесь на странице: 1из 18

Dialtone api

Twilio

Gordon Guthrie
Twiml - XMHell

<?xml version="1.0" encoding="UTF-8" ?>


<Response>
<Say>Hello World</Say>
</Response>
bits and bobs
Primary Verbs Secondary Verbs
<Say> <Hangup>
<Play> <Redirect>
<Gather> <Reject>
<Record> <Pause>
<Sms>
<Dial>
Nouns
<Number>
<Client>
<Conference>
…event cycle…

browser
here’s a capability
I wanna do
something

Twilio

app server
there are some pains
…shonktastic…
"AccountSid=yabollocks&ToZip=&FromState=&Called=%2B44131510
1875&FromCountry=GB&CallerCountry=GB&CalledZip=&Direction=i
nbound&FromCity=&CalledCountry=GB&CallerState=&CallSid=yaho
or&CalledState=Edinburgh&From=%2B447776251669&CallerZip=&Fr
omZip=&CallStatus=ringing&ToCity=&ToState=Edinburgh&To=%2B4
41315101875&ToCountry=GB&CallerCity=&ApiVersion=2010-04-
01&Caller=%2B447776251669&CalledCity="

<?xml version="1.0" encoding="UTF-8" ?>


<Response>
<Say>Hello World</Say>
</Response>
ra punter …interaction is a pain…

dial the website

yer hooter
press 1 for X 2 for Y

2
lets make it better
turn ‘em both into Erlang Records
-record(twilio,
{ -record(twilio_caller,
account_sid = [], {
application_sid = [],
number = [],
direction = [],
call_status = [], city = [],
call_sid = [], zip = [],
api_version = [], state = [],
custom_params = [], country = [],
called = null,
country_code = [],
caller = null,
from = null, prefix = []
to = null, }).
call_duration = null,
inprogress = null,
recording = null
}).
<say voice=‘woman’ language=‘de’
text=‘pogue ma hone and poke ma
hontas, ya fanny’>

-record(say, {
voice :: string(),
language :: string(),
loop :: integer(),
text = "" :: string()
}).
…design goals…
• make Twiml a proper executable run-time
language
– with validation
• implement a run-time
• make it super-simple to use
– don’t debug live systems
– don’t create unusable IVR trees
…a state machine in URLs…

browser

Twilio

app server
extended Twiml
#say{}
#play{}
#gather{}
Twilio
#record{}
#sms{}
#dial{body = [#nouns{}]}
extended Twiml
#gather{body = [#ext{}],
autoMenuEXT = true,
after_EXT = [TwiML]}
Nouns
#response_EXT{}
#default_EXT{}
Erlang
#function_EXT{}
ow Of Control

#goto_EXT{}
#repeat_EXT{}
…put it all together…
SAY =
#say{text = "burb"},
PLAY =
#play{url = "some file"},
REPEAT =
#repeat_EXT{},
RESPONSE =
#response_EXT{title =
"berk", response = "1",
body = [SAY, PLAY]},
GATHER = #gather{autoMenu_EXT =
true, body = [SAY, PLAY],
after_EXT = [RESPONSE,
REPEAT]},
twiml:compile([GATHER], ascii),
…compiles to…
1 - GATHER (request Keypad Input)
1.1 - SAY "burb"
1.2 - PLAY some file
1.3 - SAY "Press 1 for BERK. "
1.2 - end of Gather (wait for response)
1.3 - Response 1 : BERK
1.3.1 - SAY "burb"
1.3.2 - PLAY some file
1.3.3 - HANGUP
1.4 - GOTO 1
…or…
[{"1",{{xml,"<Gather>"},into}},
{"1.1",{{xml,"<Say>burb</Say>"},next}},
{"1.2",{{xml,"<Play>some file</Play>"},next}},
{"1.3",{{xml,"<Say>Press 1 for BERK. </Say>"},next}},
{"1.2",{{xml,"</Gather>"},gather}},
{"1.3",{{response_EXT,"1","berk",[]},into}},
{"1.3.1",{{xml,"<Say>burb</Say>"},next}},
{"1.3.2",{{xml,"<Play>some file</Play>"},next}},
{"1.3.3",{{xml,"<Hangup/>"},exit}},
{"1.4",{{goto_EXT,"1"},"1"}}]
Thanks to Ryan Huffman
who wrote the initial
implementation
https://github.com/huffman/twilio_erlang
http://www.twilio.com/docs/libraries

Вам также может понравиться