ExTwiml
Contains macros to make generating TwiML from Elixir far easier and more efficient. Just import
the module and go!
Examples
import Twiml
twiml do
play "/assets/welcome.mp3"
gather digits: 1 do
say "For more menus, please press 1.", voice: "woman"
say "To speak with a real person, please press 2.", voice: "woman"
end
end
Produces the following string
:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Play>/assets/welcome.mp3</Play>
<Gather digits="3">
<Say voice="woman">For more menus, please press 1.</Say>
<Say voice="woman">To speak with a real person, please press 2.</Say>
</Gather>
</Response>
You'd then need to render this string to the browser.
Summary↑
body(string \\ [], options \\ []) | Implements the |
client(string \\ [], options \\ []) | Implements the |
conference(string \\ [], options \\ []) | Implements the |
dial(options \\ [], list2) | Implements the |
enqueue(string \\ [], options \\ []) | Implements the |
gather(options \\ [], list2) | Implements the |
get_buffer(buff) | Get the current state of a buffer |
hangup(string \\ [], options \\ []) | Implements the |
leave(string \\ [], options \\ []) | Implements the |
media(string \\ [], options \\ []) | Implements the |
message(options \\ [], list2) | Implements the |
number(string \\ [], options \\ []) | Implements the |
option(pattern, text, menu_options \\ [], verb_options \\ []) | Add an option to the output |
pause(string \\ [], options \\ []) | Implements the |
play(string \\ [], options \\ []) | Implements the |
put_buffer(buff, content) | Update the buffer by pushing a new tag onto the beginning |
queue(string \\ [], options \\ []) | Implements the |
record(string \\ [], options \\ []) | Implements the |
redirect(string \\ [], options \\ []) | Implements the |
reject(string \\ [], options \\ []) | Implements the |
render(buff) | Render the contents of the buffer into a string |
say(string \\ [], options \\ []) | Implements the |
sip(string \\ [], options \\ []) | Implements the |
sms(string \\ [], options \\ []) | Implements the |
start_buffer(state) | Start an Agent to store a given buffer state |
stop_buffer(buff) | Stop a buffer |
tag(name, options \\ [], list3) | Use this macro to generate a tag not yet supported by this Twiml library. Note that you'll also need to use the |
text(string) | Adds whatever text is given to the current Twiml buffer, unmodified. As a result, this macro is really only useful when nested inside one of the other macros provided by this module |
twiml(list1) | Start creating a TwiML document |
Functions
Specs:
- get_buffer(pid) :: list
Get the current state of a buffer.
Specs:
- put_buffer(pid, any) :: atom
Update the buffer by pushing a new tag onto the beginning.
Specs:
- render(pid) :: String.t
Render the contents of the buffer into a string.
Specs:
- start_buffer(list) :: {:ok, pid}
Start an Agent to store a given buffer state.
Specs:
- stop_buffer(pid) :: atom
Stop a buffer.
Macros
Implements the <Body>
verb. No other verbs can be nested under this verb.
verb here:
https://www.twilio.com/docs/api/twiml/body
Examples
twiml do
body "Some text here", option1: "val", option2: "val"
end
twiml do
body option1: "val", option2: "val"
end
Implements the <Client>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/client
Examples
twiml do
client "Some text here", option1: "val", option2: "val"
end
twiml do
client option1: "val", option2: "val"
end
Implements the <Conference>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/conference
Examples
twiml do
conference "Some text here", option1: "val", option2: "val"
end
twiml do
conference option1: "val", option2: "val"
end
Implements the <Dial>
verb. Other verbs can be nested under this verb, as shown in the examples.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/dial
Examples
twiml do
dial do
number "1112223333"
end
end
Implements the <Enqueue>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/enqueue
Examples
twiml do
enqueue "Some text here", option1: "val", option2: "val"
end
twiml do
enqueue option1: "val", option2: "val"
end
Implements the <Gather>
verb. Other verbs can be nested under this verb, as shown in the examples.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/gather
Examples
twiml do
gather do
number "1112223333"
end
end
Implements the <Hangup>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/hangup
Examples
twiml do
hangup "Some text here", option1: "val", option2: "val"
end
twiml do
hangup option1: "val", option2: "val"
end
Implements the <Leave>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/leave
Examples
twiml do
leave "Some text here", option1: "val", option2: "val"
end
twiml do
leave option1: "val", option2: "val"
end
Implements the <Media>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/media
Examples
twiml do
media "Some text here", option1: "val", option2: "val"
end
twiml do
media option1: "val", option2: "val"
end
Implements the <Message>
verb. Other verbs can be nested under this verb, as shown in the examples.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/message
Examples
twiml do
message do
number "1112223333"
end
end
Implements the <Number>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/number
Examples
twiml do
number "Some text here", option1: "val", option2: "val"
end
twiml do
number option1: "val", option2: "val"
end
Add an option to the output.
Implements the <Pause>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/pause
Examples
twiml do
pause "Some text here", option1: "val", option2: "val"
end
twiml do
pause option1: "val", option2: "val"
end
Implements the <Play>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/play
Examples
twiml do
play "Some text here", option1: "val", option2: "val"
end
twiml do
play option1: "val", option2: "val"
end
Implements the <Queue>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/queue
Examples
twiml do
queue "Some text here", option1: "val", option2: "val"
end
twiml do
queue option1: "val", option2: "val"
end
Implements the <Record>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/record
Examples
twiml do
record "Some text here", option1: "val", option2: "val"
end
twiml do
record option1: "val", option2: "val"
end
Implements the <Redirect>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/redirect
Examples
twiml do
redirect "Some text here", option1: "val", option2: "val"
end
twiml do
redirect option1: "val", option2: "val"
end
Implements the <Reject>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/reject
Examples
twiml do
reject "Some text here", option1: "val", option2: "val"
end
twiml do
reject option1: "val", option2: "val"
end
Implements the <Say>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/say
Examples
twiml do
say "Some text here", option1: "val", option2: "val"
end
twiml do
say option1: "val", option2: "val"
end
Implements the <Sip>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/sip
Examples
twiml do
sip "Some text here", option1: "val", option2: "val"
end
twiml do
sip option1: "val", option2: "val"
end
Implements the <Sms>
verb. No other verbs can be nested under this verb.
See Twilio's official docs for the
https://www.twilio.com/docs/api/twiml/sms
Examples
twiml do
sms "Some text here", option1: "val", option2: "val"
end
twiml do
sms option1: "val", option2: "val"
end
Use this macro to generate a tag not yet supported by this Twiml library. Note that you'll also need to use the text
macro to include text within this tag.
Examples
tag :mms, to: "1112223333", from: "2223334444" do
text "How are you doing?"
end
Will produce the following Twiml:
<Mms to="1112223333" from="2223334444">How are you doing?</Mms>
Adds whatever text is given to the current Twiml buffer, unmodified. As a result, this macro is really only useful when nested inside one of the other macros provided by this module.
Start creating a TwiML document.