|
2 | 2 | Make sure to check out the TwiML overview and tutorial
|
3 | 3 | """
|
4 | 4 | import xml.etree.ElementTree as ET
|
5 |
| -from six import iteritems |
6 | 5 |
|
7 | 6 |
|
8 | 7 | class TwimlException(Exception):
|
@@ -115,10 +114,10 @@ def say(self, text, **kwargs):
|
115 | 114 | :class:`Response` """
|
116 | 115 | return self.append(Say(text, **kwargs))
|
117 | 116 |
|
118 |
| - def play(self, url, **kwargs): |
| 117 | + def play(self, url=None, digits=None, **kwargs): |
119 | 118 | """Return a newly created :class:`Play` verb, nested inside this
|
120 | 119 | :class:`Response` """
|
121 |
| - return self.append(Play(url, **kwargs)) |
| 120 | + return self.append(Play(url=url, digits=digits, **kwargs)) |
122 | 121 |
|
123 | 122 | def pause(self, **kwargs):
|
124 | 123 | """Return a newly created :class:`Pause` verb, nested inside this
|
@@ -238,18 +237,34 @@ def __init__(self, text, **kwargs):
|
238 | 237 |
|
239 | 238 |
|
240 | 239 | class Play(Verb):
|
241 |
| - """Play an audio file at a URL |
| 240 | + """Play DTMF digits or audio from a URL. |
242 | 241 |
|
243 |
| - :param url: point to af audio file. The MIME type on the file must be set |
244 |
| - correctly. |
| 242 | + :param str url: point to an audio file. The MIME type on the file must be |
| 243 | + set correctly. At least one of `url` and `digits` must be |
| 244 | + specified. If both are given, the digits will play prior |
| 245 | + to the audio from the URL. |
245 | 246 |
|
246 |
| - :param loop: specifies how many times you'd like the text repeated. |
| 247 | + :param str digits: a string of digits to play. To pause before playing |
| 248 | + digits, use leading 'w' characters. Each 'w' will cause |
| 249 | + Twilio to wait 0.5 seconds instead of playing a digit. |
| 250 | + At least one of `url` and `digits` must be specified. |
| 251 | + If both are given, the digits will play first. |
| 252 | +
|
| 253 | + :param int loop: specifies how many times you'd like the text repeated. |
247 | 254 | Specifying '0' will cause the the :class:`Play` verb to loop
|
248 | 255 | until the call is hung up. Defaults to 1.
|
249 | 256 | """
|
250 |
| - def __init__(self, url, **kwargs): |
| 257 | + def __init__(self, url=None, digits=None, **kwargs): |
| 258 | + if url is None and digits is None: |
| 259 | + raise TwimlException( |
| 260 | + "Please specify either a url or digits to play.", |
| 261 | + ) |
| 262 | + |
| 263 | + if digits is not None: |
| 264 | + kwargs['digits'] = digits |
251 | 265 | super(Play, self).__init__(**kwargs)
|
252 |
| - self.body = url |
| 266 | + if url is not None: |
| 267 | + self.body = url |
253 | 268 |
|
254 | 269 |
|
255 | 270 | class Pause(Verb):
|
|
0 commit comments