/docs/usage/twiml.rst

https://github.com/dstockto/twilio-php · ReStructuredText · 132 lines · 86 code · 46 blank · 0 comment · 0 complexity · e47694827d2bd221e23fc301cbb0b7fb MD5 · raw file

  1. .. _usage-twiml:
  2. ==============
  3. TwiML Creation
  4. ==============
  5. TwiML creation begins with the :class:`Services_Twilio_Twiml` verb. Each succesive 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 the creation of nested TwiML.
  6. .. code-block:: php
  7. $response = new Services_Twilio_Twiml();
  8. $response->say('Hello');
  9. print $response;
  10. .. code-block:: xml
  11. <?xml version="1.0" encoding="UTF-8"?>
  12. <Response><Say>Hello</Say><Response>
  13. Primary Verbs
  14. =============
  15. These are the
  16. Response
  17. --------
  18. All TwiML starts with the `<Response>` verb. The following code creates an empty response.
  19. .. code-block:: php
  20. $response = new Services_Twilio_Twiml();
  21. print $response;
  22. .. code-block:: xml
  23. <?xml version="1.0" encoding="UTF-8"?>
  24. <Response></Response>
  25. Say
  26. ---
  27. .. code-block:: php
  28. $response = new Services_Twilio_Twiml();
  29. $response->say("Hello World");
  30. print $response;
  31. .. code-block:: xml
  32. <?xml version="1.0" encoding="UTF-8"?>
  33. <Response><Say>Hello World</Say></Response>
  34. Play
  35. ----
  36. .. code-block:: php
  37. $response = new Services_Twilio_Twiml();
  38. $response->play("monkey.mp3", array('loop' => 5));
  39. print $response;
  40. .. code-block:: xml
  41. <?xml version="1.0" encoding="UTF-8"?>
  42. <Response><Play loop="5">monkey.mp3</Play><Response>
  43. Gather
  44. ------
  45. .. code-block:: php
  46. $response = new Services_Twilio_Twiml();
  47. $gather = $response->gather(array('numDigits' => 5));
  48. $gather->say("Hello Caller");
  49. print $response;
  50. .. code-block:: xml
  51. <?xml version="1.0" encoding="UTF-8"?>
  52. <Response>
  53. <Gather numDigits="5">
  54. <Say>Hellow Caller</Say>
  55. </Gather>
  56. <Response>
  57. Record
  58. ------
  59. Sms
  60. ---
  61. Dial
  62. ----
  63. Number
  64. ~~~~~~
  65. Client
  66. ~~~~~~
  67. Conference
  68. ~~~~~~~~~~
  69. Secondary Verbs
  70. ===============
  71. Hangup
  72. ------
  73. Redirect
  74. --------
  75. Reject
  76. ------
  77. Pause
  78. -----
  79. .. code-block:: php
  80. $response = new Services_Twilio_Twiml();
  81. $response->pause("");
  82. print $response;
  83. .. code-block:: xml
  84. <?xml version="1.0" encoding="UTF-8"?>
  85. <Response></Response>
  86. The verb methods (outlined in the complete reference) take the body (only text) of the verb as the first argument. All attributes are keyword arguements.