twilio.twiml

Make sure to check out the TwiML overview and tutorial at https://www.twilio.com/docs/api/twiml

class twilio.twiml.Response(**kwargs)

Twilio response object.

dial(number=None, **kwargs)

Return a newly created Dial verb, nested inside this Response

enqueue(name, **kwargs)

Return a newly created Enqueue verb, nested inside this Response

gather(**kwargs)

Return a newly created Gather verb, nested inside this Response

hangup(**kwargs)

Return a newly created Hangup verb, nested inside this Response

leave(**kwargs)

Return a newly created Leave verb, nested inside this Response

message(msg=None, **kwargs)

Return a newly created Message verb, nested inside this Response

pause(**kwargs)

Return a newly created Pause verb, nested inside this Response

play(url=None, digits=None, **kwargs)

Return a newly created Play verb, nested inside this Response

record(**kwargs)

Return a newly created Record verb, nested inside this Response

redirect(url=None, **kwargs)

Return a newly created Redirect verb, nested inside this Response

reject(reason=None, **kwargs)

Return a newly created Hangup verb, nested inside this Response

say(text, **kwargs)

Return a newly created Say verb, nested inside this Response

sms(msg, **kwargs)

Return a newly created Sms verb, nested inside this Response

Primary Verbs

class twilio.twiml.Say(text, **kwargs)

The Say verb converts text to speech that is read back to the caller.

Parameters:
  • voice – allows you to choose a male or female voice to read text back.
  • language – allows you pick a voice with a specific language’s accent and pronunciations. Twilio currently supports languages ‘en’ (English), ‘es’ (Spanish), ‘fr’ (French), and ‘de’ (German), ‘en-gb’ (English Great Britain”).
  • loop – specifies how many times you’d like the text repeated. Specifying ‘0’ will cause the the Say verb to loop until the call is hung up. Defaults to 1.
class twilio.twiml.Play(url=None, digits=None, **kwargs)

Play DTMF digits or audio from a URL.

Parameters:
  • url (str) – point to an audio file. The MIME type on the file must be set correctly. At least one of url and digits must be specified. If both are given, the digits will play prior to the audio from the URL.
  • digits (str) – a string of digits to play. To pause before playing digits, use leading ‘w’ characters. Each ‘w’ will cause Twilio to wait 0.5 seconds instead of playing a digit. At least one of url and digits must be specified. If both are given, the digits will play first.
  • loop (int) – specifies how many times you’d like the text repeated. Specifying ‘0’ will cause the the Play verb to loop until the call is hung up. Defaults to 1.
class twilio.twiml.Dial(number=None, **kwargs)

Dial another phone number and connect it to this call

Parameters:
  • action – submit the result of the dial to this URL
  • method – submit to ‘action’ url using GET or POST
  • timeout (int) – The number of seconds to waits for the called party to answer the call
  • hangupOnStar (bool) – Allow the calling party to hang up on the called party by pressing the ‘*’ key
  • timeLimit (int) – The maximum duration of the Call in seconds
  • callerId – The caller ID that will appear to the called party
  • record (bool) – Record both legs of a call within this <Dial>
class twilio.twiml.Gather(**kwargs)

Gather digits from the caller’s keypad

Parameters:
  • action – URL to which the digits entered will be sent
  • method – submit to ‘action’ url using GET or POST
  • numDigits – how many digits to gather before returning
  • timeout – wait for this many seconds before returning
  • finishOnKey – key that triggers the end of caller input
class twilio.twiml.Record(**kwargs)

Record audio from caller

Parameters:
  • action – submit the result of the dial to this URL
  • method – submit to ‘action’ url using GET or POST
  • maxLength – maximum number of seconds to record
  • timeout – seconds of silence before considering the recording done

Secondary Verbs

class twilio.twiml.Hangup(**kwargs)

Hangup the call

class twilio.twiml.Redirect(url='', **kwargs)

Redirect call flow to another URL

Parameters:
  • url – specifies the url which Twilio should query to retrieve new TwiML. The default is the current url
  • method – specifies the HTTP method to use when retrieving the url
class twilio.twiml.Reject(**kwargs)

Hangup the call

Parameters:reason – not sure
class twilio.twiml.Pause(**kwargs)

Pause the call

Parameters:length – specifies how many seconds Twilio will wait silently before continuing on.
class twilio.twiml.Message(msg=None, **kwargs)

Send an MMS Message to a phone number.

Parameters:
  • to – whom to send message to
  • sender – whom to send message from.
  • action – url to request after the message is queued
  • method – submit to ‘action’ url using GET or POST
  • statusCallback – url to hit when the message is actually sent
class twilio.twiml.Enqueue(name, **kwargs)

Enqueue the call into a specific queue.

Parameters:
  • name – friendly name for the queue
  • action – url to a twiml document that executes when the call leaves the queue. When dequeued via a <Dial> verb, this url is executed after the bridged parties disconnect
  • method – HTTP method for action GET/POST
  • waitUrl – url to a twiml document that executes while the call is on the queue
  • waitUrlMethod – HTTP method for waitUrl GET/POST
class twilio.twiml.Leave(**kwargs)

Signals the call to leave its queue

Nouns

class twilio.twiml.Conference(name, **kwargs)

Specify conference in a nested Dial element.

Parameters:
  • name – friendly name of conference
  • muted (bool) – keep this participant muted
  • beep (bool) – play a beep when this participant enters/leaves
  • startConferenceOnEnter (bool) – start conf when this participants joins
  • endConferenceOnExit (bool) – end conf when this participants leaves
  • waitUrl – TwiML url that executes before conference starts
  • waitMethod – HTTP method for waitUrl GET/POST
class twilio.twiml.Number(number, **kwargs)

Specify phone number in a nested Dial element.

Parameters:
  • number – phone number to dial
  • sendDigits – key to press after connecting to the number
class twilio.twiml.Client(name, **kwargs)

Specify a client name to call in a nested Dial element.

Parameters:name – Client name to connect to
class twilio.twiml.Queue(name, **kwargs)

Specify queue in a nested Dial element.

Parameters:
  • name – friendly name for the queue
  • url – url to a twiml document that executes after a call is dequeued and before the call is connected
  • method – HTTP method for url GET/POST