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 <Body> verb. No other verbs can be nested under this verb

client(string \\ [], options \\ [])

Implements the <Client> verb. No other verbs can be nested under this verb

conference(string \\ [], options \\ [])

Implements the <Conference> verb. No other verbs can be nested under this verb

dial(options, list2)

Implements the <Dial> verb. Other verbs can be nested under this verb, as shown in the examples

enqueue(string \\ [], options \\ [])

Implements the <Enqueue> verb. No other verbs can be nested under this verb

gather(options, list2)

Implements the <Gather> verb. Other verbs can be nested under this verb, as shown in the examples

get_buffer(buff)

Get the current state of a buffer

hangup(string \\ [], options \\ [])

Implements the <Hangup> verb. No other verbs can be nested under this verb

leave(string \\ [], options \\ [])

Implements the <Leave> verb. No other verbs can be nested under this verb

media(string \\ [], options \\ [])

Implements the <Media> verb. No other verbs can be nested under this verb

message(options, list2)

Implements the <Message> verb. Other verbs can be nested under this verb, as shown in the examples

number(string \\ [], options \\ [])

Implements the <Number> verb. No other verbs can be nested under this verb

option(pattern, text, menu_options \\ [], verb_options \\ [])

Add an option to the output

pause(string \\ [], options \\ [])

Implements the <Pause> verb. No other verbs can be nested under this verb

play(string \\ [], options \\ [])

Implements the <Play> verb. No other verbs can be nested under this verb

put_buffer(buff, content)

Update the buffer by pushing a new tag onto the beginning

queue(string \\ [], options \\ [])

Implements the <Queue> verb. No other verbs can be nested under this verb

record(string \\ [], options \\ [])

Implements the <Record> verb. No other verbs can be nested under this verb

redirect(string \\ [], options \\ [])

Implements the <Redirect> verb. No other verbs can be nested under this verb

reject(string \\ [], options \\ [])

Implements the <Reject> verb. No other verbs can be nested under this verb

render(buff)

Render the contents of the buffer into a string

say(string \\ [], options \\ [])

Implements the <Say> verb. No other verbs can be nested under this verb

sip(string \\ [], options \\ [])

Implements the <Sip> verb. No other verbs can be nested under this verb

sms(string \\ [], options \\ [])

Implements the <Sms> verb. No other verbs can be nested under this verb

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 macro to include text within this tag

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

get_buffer(buff)

Specs:

  • get_buffer(pid) :: list

Get the current state of a buffer.

put_buffer(buff, content)

Specs:

  • put_buffer(pid, any) :: atom

Update the buffer by pushing a new tag onto the beginning.

render(buff)

Specs:

Render the contents of the buffer into a string.

start_buffer(state)

Specs:

  • start_buffer(list) :: {:ok, pid}

Start an Agent to store a given buffer state.

stop_buffer(buff)

Specs:

  • stop_buffer(pid) :: atom

Stop a buffer.

Macros

body(string \\ [], options \\ [])

Implements the <Body> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the

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
client(string \\ [], options \\ [])

Implements the <Client> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
conference(string \\ [], options \\ [])

Implements the <Conference> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
dial(options, list2)

Implements the <Dial> verb. Other verbs can be nested under this verb, as shown in the examples.

See Twilio's official docs for the verb here:

https://www.twilio.com/docs/api/twiml/dial

Examples

twiml do
  dial do
    number "1112223333"
  end
end
enqueue(string \\ [], options \\ [])

Implements the <Enqueue> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
gather(options, list2)

Implements the <Gather> verb. Other verbs can be nested under this verb, as shown in the examples.

See Twilio's official docs for the verb here:

https://www.twilio.com/docs/api/twiml/gather

Examples

twiml do
  gather do
    number "1112223333"
  end
end
hangup(string \\ [], options \\ [])

Implements the <Hangup> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
leave(string \\ [], options \\ [])

Implements the <Leave> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
media(string \\ [], options \\ [])

Implements the <Media> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
message(options, list2)

Implements the <Message> verb. Other verbs can be nested under this verb, as shown in the examples.

See Twilio's official docs for the verb here:

https://www.twilio.com/docs/api/twiml/message

Examples

twiml do
  message do
    number "1112223333"
  end
end
number(string \\ [], options \\ [])

Implements the <Number> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
option(pattern, text, menu_options \\ [], verb_options \\ [])

Add an option to the output.

pause(string \\ [], options \\ [])

Implements the <Pause> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
play(string \\ [], options \\ [])

Implements the <Play> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
queue(string \\ [], options \\ [])

Implements the <Queue> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
record(string \\ [], options \\ [])

Implements the <Record> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
redirect(string \\ [], options \\ [])

Implements the <Redirect> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
reject(string \\ [], options \\ [])

Implements the <Reject> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
say(string \\ [], options \\ [])

Implements the <Say> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
sip(string \\ [], options \\ [])

Implements the <Sip> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
sms(string \\ [], options \\ [])

Implements the <Sms> verb. No other verbs can be nested under this verb.

See Twilio's official docs for the verb here:

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
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 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>
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.