Sha256: d3fc19d3e913b3d80c3d8e15dec944a9103c7dab1e1f46c60c7e6f1c6b31453f

Contents?: true

Size: 1.55 KB

Versions: 37

Compression:

Stored size: 1.55 KB

Contents

.. _usage-twiml:

.. module:: twilio.twiml

==============
TwiML Creation
==============

TwiML creation begins with the :class:`Response` verb.
Each successive verb is created by calling various methods on the response,
such as :meth:`say` or :meth:`play`.
These methods return the verbs they create to ease creation of nested TwiML.
To finish, call the :meth:`toxml` method on the :class:`Response`,
which returns raw TwiML.

.. code-block:: ruby

    require 'twilio-ruby'

    Twilio::TwiML::Response.new do |r|
      r.Say "Hello"
    end.text

.. code-block:: xml

   <?xml version="1.0" encoding="utf-8"?>
   <Response><Say>Hello</Say><Response>

The verb methods (outlined in the :doc:`complete reference </api/twiml>`)
take the body (only text) of the verb as the first argument.
All attributes are keyword arguments.

.. code-block:: ruby

    require 'twilio-ruby'

    Twilio::TwiML::Response.new do |r|
      r.Play "https://api.twilio.com/cowbell.mp3", loop: 5
    end.text

.. code-block:: xml

    <?xml version="1.0" encoding="utf-8"?>
    <Response>
      <Play loop="3">https://api.twilio.com/cowbell.mp3</Play>
    <Response>

Any example of nesting nouns in verbs

.. code-block:: ruby

    require 'twilio-ruby'

    Twilio::TwiML::Response.new do |r|
      r.Say "hello"
      r.Gather finishOnKey: => 4 do |g|
        g.Say "world"
      end
    end.text

which returns the following

.. code-block:: xml

    <?xml version="1.0" encoding="utf-8"?>
    <Response>
      <Say>Hello</Say>
      <Gather finishOnKey="4"><Say>World</Say></Gather>
    </Response>

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
twilio-ruby-4.13.0 docs/usage/twiml.rst
twilio-ruby-4.12.1 docs/usage/twiml.rst
twilio-ruby-4.11.1 docs/usage/twiml.rst
twilio-ruby-4.11.0 docs/usage/twiml.rst
twilio-ruby-4.10.0.edge docs/usage/twiml.rst
twilio-ruby-4.10.0 docs/usage/twiml.rst
twilio-ruby-4.9.1 docs/usage/twiml.rst
twilio-ruby-4.9.1.edge docs/usage/twiml.rst
twilio-ruby-4.9.0 docs/usage/twiml.rst
twilio-ruby-4.9.0.edge docs/usage/twiml.rst
twilio-ruby-4.8.0 docs/usage/twiml.rst
twilio-ruby-4.7.0 docs/usage/twiml.rst
twilio-ruby-4.8.3.edge docs/usage/twiml.rst
twilio-ruby-4.8.2.edge docs/usage/twiml.rst
twilio-ruby-4.8.1.edge docs/usage/twiml.rst
twilio-ruby-4.8.0.edge docs/usage/twiml.rst
twilio-ruby-4.6.2 docs/usage/twiml.rst
twilio-ruby-4.6.1 docs/usage/twiml.rst
twilio-ruby-4.6.0 docs/usage/twiml.rst
twilio-ruby-4.7.0.edge docs/usage/twiml.rst