ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - danielberkompas/ex_twiml: Generate TwiML with Elixir
Generate TwiML with Elixir. Contribute to danielberkompas/ex_twiml development by creating an account on GitHub.
Visit Site

GitHub - danielberkompas/ex_twiml: Generate TwiML with Elixir

GitHub - danielberkompas/ex_twiml: Generate TwiML with Elixir

ExTwiml

Build Status Hex Version Inline docs

Generate TwiML for your Twilio integration, right inside Elixir! Built to be used with Telephonist, but it can be used entirely on its own.

Installation

ExTwiml can be installed through mix as a hex package. First, update your dependencies in mix.exs.

defp deps do
  [{:ex_twiml, "~> 2.1.3"}]
end

If you prefer, you can depend on the latest version from Github:

defp deps do
  [{:ex_twiml, github: "danielberkompas/ex_twiml"}]
end

Add it to your application list in mix.exs:

def application do
  [mod: {YourApp, []},
+   applications: [:ex_twiml]]
end

Then run mix deps.get, and ExTwiml will be installed.

Usage

Import the ExTwiml module into your module, and then use the twiml macro to generate your TwiML, like so:

defmodule YourModule do
  import ExTwiml

  def render do
    twiml do
      play "/assets/welcome.mp3"
      gather digits: 4, finish_on_key: "#" do
        say """
        Please enter the last four digits of your credit card number, followed
        by the pound sign.
        """, voice: "woman"
      end
    end
  end
end

You can then render the TwiML by calling YourModule.render/0. The output will be a binary in this format:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Play>/assets/welcome.mp3</Play>
  <Gather digits="4" finishOnKey="#">
    <Say voice="woman">
      Please enter the last four digits of your credit card number, followed by
      the pound sign.
    </Say>
  </Gather>
</Response>

The twiml macro simply returns a binary (or string), so you're not limited to the pattern above. Just use twiml wherever you need a TwiML string.

Configuration

You can configure default options for verbs. For example, suppose you wanted all <Say> verbs to use the "Alice" voice, and all <Gather> verbs to have the method "GET".

Simply add this code to your config/config.exs:

config :ex_twiml, :defaults,
  say: [voice: "alice"],
  gather: [method: "GET"]

Then this code:

twiml do
  gather do
    say "Hello"
  end
end

Will result in this TwiML:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Gather method="GET">
    <Say voice="alice">Hello</Say>
  </Gather>
</Response>

Defaults can be overridden:

gather method: "POST"
say "Hello", voice: "woman"

Supported Verbs and Nouns

See the Twilio Documentation for a complete list of verbs supported by Twilio. ExTwiml has built in macros for the following verbs and nouns:

To maximize compatibility with future versions of the TwiML spec, ExTwiml does not validate the attributes passed to the various verbs to ensure that they are supported by Twilio. You'll need to do this yourself.

Unsupported Verbs?

If the Twilio API adds a verb and I haven't yet added support for it, you can do two things:

  1. Submit a PR to add it
  2. Use the tag macro in the meantime while the PR is reviewed

The tag macro can be used to create arbitrary XML tags in the output, like this:

tag :custom, option_1: "value" do
  tag :speak, do: "Whatever you say, boss!"
end
# => "<Custom option1="value"><Speak>Whatever you say, boss!</Speak></Custom>"

Contributing

Contributions are welcome!

  1. Fork the repository
  2. Code up your changes
  3. Submit a PR back here with your fix.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory