Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 887 lines (732 sloc) 29.839 kB
8de435a @egilchri Better doc
egilchri authored
1 """
2 The TropoPython module. This module implements a set of classes and methods for manipulating the Voxeo Tropo WebAPI.
3
4 Usage:
5
15d0dc2 @danyork Modified example to include import statement
danyork authored
6 ----
5a1d33e @danyork Move name to "tropo.py" and updated refs
danyork authored
7 from tropo import Tropo
15d0dc2 @danyork Modified example to include import statement
danyork authored
8
8de435a @egilchri Better doc
egilchri authored
9 tropo = Tropo()
10 tropo.say("Hello, World")
cf73576 add voice option to Say
Jeremy Jones authored
11 json = tropo.RenderJson()
15d0dc2 @danyork Modified example to include import statement
danyork authored
12 ----
8de435a @egilchri Better doc
egilchri authored
13
cf73576 add voice option to Say
Jeremy Jones authored
14 You can write this JSON back to standard output to get Tropo to perform
8de435a @egilchri Better doc
egilchri authored
15 the action. For example, on Google Appengine you might write something like:
16
17 handler.response.out.write(json)
18
cf73576 add voice option to Say
Jeremy Jones authored
19 Much of the time, a you will interact with Tropo by examining the Result
20 object and communicating back to Tropo via the Tropo class methods, such
8de435a @egilchri Better doc
egilchri authored
21 as "say". In some cases, you'll want to build a class object directly such as in :
22
5a1d33e @danyork Move name to "tropo.py" and updated refs
danyork authored
23 choices = tropo.Choices("[5 digits]").obj
8de435a @egilchri Better doc
egilchri authored
24
cf73576 add voice option to Say
Jeremy Jones authored
25 tropo.ask(choices,
26 say="Please enter your 5 digit zip code.",
8de435a @egilchri Better doc
egilchri authored
27 attempts=3, bargein=True, name="zip", timeout=5, voice="dave")
28 ...
29
21aa381 @danyork Added notes that python 2.5 or higher is required
danyork authored
30 NOTE: This module requires python 2.5 or higher.
31
8de435a @egilchri Better doc
egilchri authored
32 """
fc239d3 @saghul Fixed module imports
saghul authored
33
34 try:
35 import cjson as jsonlib
36 jsonlib.dumps = jsonlib.encode
37 jsonlib.loads = jsonlib.decode
38 except ImportError:
39 try:
40 from django.utils import simplejson as jsonlib
41 except ImportError:
42 try:
43 import simplejson as jsonlib
44 except ImportError:
45 import json as jsonlib
46
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
47 class TropoAction(object):
48 """
49 Class representing the base Tropo action.
50 Two properties are provided in order to avoid defining the same attributes for every action.
51 """
52 @property
53 def json(self):
54 return self._dict
55
56 @property
57 def obj(self):
58 return {self.action: self._dict}
59
60 class Ask(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
61 """
8de435a @egilchri Better doc
egilchri authored
62 Class representing the "ask" Tropo action. Builds an "ask" JSON object.
63 Class constructor arg: choices, a Choices object
64 Convenience function: Tropo.ask()
65 Class constructor options: attempts, bargein, choices, minConfidence, name, recognizer, required, say, timeout, voice
66
67 Request information from the caller and wait for a response.
37dbaa3 Initial upload
Edgar Gilchrist authored
68 (See https://www.tropo.com/docs/webapi/ask.htm)
69
70 { "ask": {
71 "attempts": Integer,
2b09f49 Added allowSignals and interdigitTimeout to the ask method
Kevin Bond authored
72 "allowSiganls": String or Array,
37dbaa3 Initial upload
Edgar Gilchrist authored
73 "bargein": Boolean,
74 "choices": Object, #Required
2b09f49 Added allowSignals and interdigitTimeout to the ask method
Kevin Bond authored
75 "interdigitTimeout": Integer,
37dbaa3 Initial upload
Edgar Gilchrist authored
76 "minConfidence": Integer,
77 "name": String,
78 "recognizer": String,
79 "required": Boolean,
80 "say": Object,
2b09f49 Added allowSignals and interdigitTimeout to the ask method
Kevin Bond authored
81 "sensitivity": Integer,
82 "speechCompleteTimeout": Integer,
83 "speechIncompleteTimeout": Integer,
37dbaa3 Initial upload
Edgar Gilchrist authored
84 "timeout": Float,
8f9acea fixed the on events voice param and added 'interdigitTimeout', 'speec…
Kevin Bond authored
85 "voice": String,
2b09f49 Added allowSignals and interdigitTimeout to the ask method
Kevin Bond authored
86
87 ,
88 } }
37dbaa3 Initial upload
Edgar Gilchrist authored
89
90 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
91 action = 'ask'
2b09f49 Added allowSignals and interdigitTimeout to the ask method
Kevin Bond authored
92 options_array = ['attempts', 'allowSiganls', 'bargein', 'choices', 'interdigitTimeout', 'minConfidence', 'name', 'recognizer', 'required', 'say', 'sensitivity', 'speechCompleteTimeout', 'speechIncompleteTimeout', 'timeout', 'voice']
37dbaa3 Initial upload
Edgar Gilchrist authored
93
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
94 def __init__(self, choices, **options):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
95 self._dict = {}
f68c4db @saghul Check object type with isinstance(obj, basestring) since basestring
saghul authored
96 if (isinstance(choices, basestring)):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
97 self._dict['choices'] = Choices(choices).json
bcfb063 @egilchri Things basically working but not yet ready for prime time
egilchri authored
98 else:
67e8d6b @egilchri Made changes to Ask class init function to handle choices argument.
egilchri authored
99 # self._dict['choices'] = choices['choices']
100 self._dict['choices'] = choices.json
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
101 for opt in self.options_array:
37dbaa3 Initial upload
Edgar Gilchrist authored
102 if opt in options:
f68c4db @saghul Check object type with isinstance(obj, basestring) since basestring
saghul authored
103 if ((opt == 'say') and (isinstance(options['say'], basestring))):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
104 self._dict['say'] = Say(options['say']).json
37dbaa3 Initial upload
Edgar Gilchrist authored
105 else:
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
106 self._dict[opt] = options[opt]
37dbaa3 Initial upload
Edgar Gilchrist authored
107
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
108 class Call(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
109 """
8de435a @egilchri Better doc
egilchri authored
110 Class representing the "call" Tropo action. Builds a "call" JSON object.
111 Class constructor arg: to, a String
fe7ab2a @kevinbond Added machineDetection to call method
kevinbond authored
112 Class constructor options: answerOnMedia, channel, from, headers, name, network, recording, required, timeout, machineDetection
8de435a @egilchri Better doc
egilchri authored
113 Convenience function: Tropo.call()
114
5a1d33e @danyork Move name to "tropo.py" and updated refs
danyork authored
115 (See https://www.tropo.com/docswebapi/call.htm)
37dbaa3 Initial upload
Edgar Gilchrist authored
116
117 { "call": {
118 "to": String or Array,#Required
119 "answerOnMedia": Boolean,
ddc7964 Added allowSignals to the call method
Kevin Bond authored
120 "allowSignals": String or Array
37dbaa3 Initial upload
Edgar Gilchrist authored
121 "channel": string,
122 "from": string,
123 "headers": Object,
124 "name": String,
125 "network": String,
126 "recording": Array or Object,
127 "required": Boolean,
fe7ab2a @kevinbond Added machineDetection to call method
kevinbond authored
128 "timeout": Float.
129 "machineDetection: Boolean or Object" } }
37dbaa3 Initial upload
Edgar Gilchrist authored
130 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
131 action = 'call'
fe7ab2a @kevinbond Added machineDetection to call method
kevinbond authored
132 options_array = ['answerOnMedia', 'allowSignals', 'channel', '_from', 'headers', 'name', 'network', 'recording', 'required', 'timeout', 'machineDetection']
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
133
37dbaa3 Initial upload
Edgar Gilchrist authored
134 def __init__(self, to, **options):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
135 self._dict = {'to': to}
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
136 for opt in self.options_array:
37dbaa3 Initial upload
Edgar Gilchrist authored
137 if opt in options:
dfa584a @egilchri Fixed gh-14 (conflict with 'as' and 'from' Python reserved words), an…
egilchri authored
138 if (opt == "_from"):
139 self._dict['from'] = options[opt]
140 else:
141 self._dict[opt] = options[opt]
142
143
37dbaa3 Initial upload
Edgar Gilchrist authored
144
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
145 class Choices(TropoAction):
8de435a @egilchri Better doc
egilchri authored
146 """
147 Class representing choice made by a user. Builds a "choices" JSON object.
148 Class constructor options: terminator, mode
149
150 (See https://www.tropo.com/docs/webapi/ask.htm)
151 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
152 action = 'choices'
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
153 options_array = ['terminator', 'mode']
8de435a @egilchri Better doc
egilchri authored
154
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
155 def __init__(self, value, **options):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
156 self._dict = {'value': value}
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
157 for opt in self.options_array:
8de435a @egilchri Better doc
egilchri authored
158 if opt in options:
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
159 self._dict[opt] = options[opt]
8de435a @egilchri Better doc
egilchri authored
160
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
161 class Conference(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
162 """
8de435a @egilchri Better doc
egilchri authored
163 Class representing the "conference" Tropo action. Builds a "conference" JSON object.
164 Class constructor arg: id, a String
165 Convenience function: Tropo.conference()
166 Class constructor options: mute, name, playTones, required, terminator
167
37dbaa3 Initial upload
Edgar Gilchrist authored
168 (See https://www.tropo.com/docs/webapi/conference.htm)
169
170 { "conference": {
171 "id": String,#Required
5e2b854 Added allowSignals and interdigitTimeout to the conference method
Kevin Bond authored
172 "allowSignals": String or Array,
173 "interdigitTimeout":Integer,
37dbaa3 Initial upload
Edgar Gilchrist authored
174 "mute": Boolean,
175 "name": String,
176 "playTones": Boolean,
177 "required": Boolean,
d5308e1 @kevinbond Added join/leave prompt to the conference method
kevinbond authored
178 "terminator": String,
179 "joinPrompt": Object,
180 "leavePrompt": Object } }
37dbaa3 Initial upload
Edgar Gilchrist authored
181 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
182 action = 'conference'
d5308e1 @kevinbond Added join/leave prompt to the conference method
kevinbond authored
183 options_array = ['allowSignals', 'interdigitTimeout', 'mute', 'name', 'playTones', 'required', 'terminator', 'joinPrompt', 'leavePrompt']
37dbaa3 Initial upload
Edgar Gilchrist authored
184
8de435a @egilchri Better doc
egilchri authored
185 def __init__(self, id, **options):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
186 self._dict = {'id': id}
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
187 for opt in self.options_array:
37dbaa3 Initial upload
Edgar Gilchrist authored
188 if opt in options:
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
189 self._dict[opt] = options[opt]
37dbaa3 Initial upload
Edgar Gilchrist authored
190
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
191 class Hangup(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
192 """
8de435a @egilchri Better doc
egilchri authored
193 Class representing the "hangup" Tropo action. Builds a "hangup" JSON object.
cf73576 add voice option to Say
Jeremy Jones authored
194 Class constructor arg:
195 Class constructor options:
8de435a @egilchri Better doc
egilchri authored
196 Convenience function: Tropo.hangup()
197
37dbaa3 Initial upload
Edgar Gilchrist authored
198 (See https://www.tropo.com/docs/webapi/hangup.htm)
199
cf73576 add voice option to Say
Jeremy Jones authored
200 { "hangup": { } }
37dbaa3 Initial upload
Edgar Gilchrist authored
201 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
202 action = 'hangup'
203
37dbaa3 Initial upload
Edgar Gilchrist authored
204 def __init__(self):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
205 self._dict = {}
d5308e1 @kevinbond Added join/leave prompt to the conference method
kevinbond authored
206
207 class JoinPrompt(TropoAction):
208 """
209 Class representing join prompts for the conference method. Builds a "joinPrompt" JSON object.
210 Class constructor options: value, voice
211
212 (See https://www.tropo.com/docs/webapi/conference.htm)
213 """
214 action = 'joinPrompt'
215 options_array = ['value', 'voice']
37dbaa3 Initial upload
Edgar Gilchrist authored
216
d5308e1 @kevinbond Added join/leave prompt to the conference method
kevinbond authored
217 def __init__(self, value, **options):
218 self._dict = {'value': value}
219 for opt in self.options_array:
220 if opt in options:
221 self._dict[opt] = options[opt]
fe7ab2a @kevinbond Added machineDetection to call method
kevinbond authored
222
d5308e1 @kevinbond Added join/leave prompt to the conference method
kevinbond authored
223 class LeavePrompt(TropoAction):
224 """
225 Class representing leave prompts for the conference method. Builds a "leavePrompt" JSON object.
226 Class constructor options: value, voice
227
228 (See https://www.tropo.com/docs/webapi/conference.htm)
229 """
230 action = 'leavePrompt'
231 options_array = ['value', 'voice']
232
233 def __init__(self, value, **options):
234 self._dict = {'value': value}
235 for opt in self.options_array:
236 if opt in options:
237 self._dict[opt] = options[opt]
238
fe7ab2a @kevinbond Added machineDetection to call method
kevinbond authored
239 class MachineDetection(TropoAction):
240 """
241 Class representing machine detection for the call method. Builds a "machineDetection" JSON object.
242 Class constructor options: introduction, voice
243
d5308e1 @kevinbond Added join/leave prompt to the conference method
kevinbond authored
244 (See https://www.tropo.com/docs/webapi/call.htm)
fe7ab2a @kevinbond Added machineDetection to call method
kevinbond authored
245 """
246 action = 'machineDetection'
247 options_array = ['introduction', 'voice']
248
249 def __init__(self, introduction, **options):
250 self._dict = {'introduction': introduction}
251 for opt in self.options_array:
252 if opt in options:
253 self._dict[opt] = options[opt]
254
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
255 class Message(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
256 """
8de435a @egilchri Better doc
egilchri authored
257 Class representing the "message" Tropo action. Builds a "message" JSON object.
258 Class constructor arg: say_obj, a Say object
259 Class constructor arg: to, a String
260 Class constructor options: answerOnMedia, channel, from, name, network, required, timeout, voice
261 Convenience function: Tropo.message()
262
263 (See https://www.tropo.com/docs/webapi/message.htm)
264 { "message": {
37dbaa3 Initial upload
Edgar Gilchrist authored
265 "say": Object,#Required
266 "to": String or Array,#Required
267 "answerOnMedia": Boolean,
268 "channel": string,
dfa584a @egilchri Fixed gh-14 (conflict with 'as' and 'from' Python reserved words), an…
egilchri authored
269 "from": String,
37dbaa3 Initial upload
Edgar Gilchrist authored
270 "name": String,
271 "network": String,
272 "required": Boolean,
273 "timeout": Float,
cf73576 add voice option to Say
Jeremy Jones authored
274 "voice": String } }
37dbaa3 Initial upload
Edgar Gilchrist authored
275 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
276 action = 'message'
dfa584a @egilchri Fixed gh-14 (conflict with 'as' and 'from' Python reserved words), an…
egilchri authored
277 options_array = ['answerOnMedia', 'channel', '_from', 'name', 'network', 'required', 'timeout', 'voice']
37dbaa3 Initial upload
Edgar Gilchrist authored
278
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
279 def __init__(self, say_obj, to, **options):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
280 self._dict = {'say': say_obj['say'], 'to': to}
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
281 for opt in self.options_array:
37dbaa3 Initial upload
Edgar Gilchrist authored
282 if opt in options:
dfa584a @egilchri Fixed gh-14 (conflict with 'as' and 'from' Python reserved words), an…
egilchri authored
283 if (opt == "_from"):
284 self._dict['from'] = options[opt]
285 else:
286 self._dict[opt] = options[opt]
287
37dbaa3 Initial upload
Edgar Gilchrist authored
288
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
289 class On(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
290 """
8de435a @egilchri Better doc
egilchri authored
291 Class representing the "on" Tropo action. Builds an "on" JSON object.
292 Class constructor arg: event, a String
293 Class constructor options: name,next,required,say
294 Convenience function: Tropo.on()
295
37dbaa3 Initial upload
Edgar Gilchrist authored
296 (See https://www.tropo.com/docs/webapi/on.htm)
297
298 { "on": {
299 "event": String,#Required
300 "name": String,
301 "next": String,
302 "required": Boolean,
8f9acea fixed the on events voice param and added 'interdigitTimeout', 'speec…
Kevin Bond authored
303 "say": Object
304 "voice": String } }
37dbaa3 Initial upload
Edgar Gilchrist authored
305 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
306 action = 'on'
0f3b31f @kevinbond added whisper to transfer
kevinbond authored
307 options_array = ['name','next','required','say', 'voice', 'ask', 'message', 'wait']
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
308
37dbaa3 Initial upload
Edgar Gilchrist authored
309 def __init__(self, event, **options):
0f3b31f @kevinbond added whisper to transfer
kevinbond authored
310 self._dict = {}
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
311 for opt in self.options_array:
37dbaa3 Initial upload
Edgar Gilchrist authored
312 if opt in options:
f68c4db @saghul Check object type with isinstance(obj, basestring) since basestring
saghul authored
313 if ((opt == 'say') and (isinstance(options['say'], basestring))):
8f9acea fixed the on events voice param and added 'interdigitTimeout', 'speec…
Kevin Bond authored
314 if('voice' in options):
315 self._dict['say'] = Say(options['say'], voice=options['voice']).json
316 else:
317 self._dict['say'] = Say(options['say']).json
0f3b31f @kevinbond added whisper to transfer
kevinbond authored
318
319 elif ((opt == 'ask') and (isinstance(options['ask'], basestring))):
320 if('voice' in options):
321 self._dict['ask'] = Ask(options['ask'], voice=options['voice']).json
322 else:
323 self._dict['ask'] = Ask(options['ask']).json
324
325 elif ((opt == 'message') and (isinstance(options['message'], basestring))):
326 if('voice' in options):
327 self._dict['message'] = Message(options['message'], voice=options['voice']).json
328 else:
329 self._dict['message'] = Message(options['message']).json
330
331 elif ((opt == 'wait') and (isinstance(options['wait'], basestring))):
332 self._dict['wait'] = Wait(options['wait']).json
333
8f9acea fixed the on events voice param and added 'interdigitTimeout', 'speec…
Kevin Bond authored
334 elif(opt != 'voice'):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
335 self._dict[opt] = options[opt]
0f3b31f @kevinbond added whisper to transfer
kevinbond authored
336
337 self._dict['event'] = event
37dbaa3 Initial upload
Edgar Gilchrist authored
338
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
339 class Record(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
340 """
8de435a @egilchri Better doc
egilchri authored
341 Class representing the "record" Tropo action. Builds a "record" JSON object.
cf73576 add voice option to Say
Jeremy Jones authored
342 Class constructor arg:
8de435a @egilchri Better doc
egilchri authored
343 Class constructor options: attempts, bargein, beep, choices, format, maxSilence, maxTime, method, minConfidence, name, password, required, say, timeout, transcription, url, username
344 Convenience function: Tropo.record()
345
37dbaa3 Initial upload
Edgar Gilchrist authored
346 (See https://www.tropo.com/docs/webapi/record.htm)
347
348 { "record": {
349 "attempts": Integer,
350 "bargein": Boolean,
351 "beep": Boolean,
352 "choices": Object,
353 "format": String,
354 "maxSilence": Float,
355 "maxTime": Float,
356 "method": String,
357 "minConfidence": Integer,
358 "name": String,
359 "password": String,
360 "required": Boolean,
361 "say": Object,
362 "timeout": Float,
363 "transcription": Array or Object,
364 "url": String,#Required ?????
df69173 Update tropo.py
Kevin Bond authored
365 "username": String,
366 "voice": String} }
37dbaa3 Initial upload
Edgar Gilchrist authored
367 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
368 action = 'record'
df69173 Update tropo.py
Kevin Bond authored
369 options_array = ['attempts', 'bargein', 'beep', 'choices', 'format', 'maxSilence', 'maxTime', 'method', 'minConfidence', 'name', 'password', 'required', 'say', 'timeout', 'transcription', 'url', 'username', 'allowSignals', 'voice', 'interdigitTimeout']
37dbaa3 Initial upload
Edgar Gilchrist authored
370
371 def __init__(self, **options):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
372 self._dict = {}
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
373 for opt in self.options_array:
37dbaa3 Initial upload
Edgar Gilchrist authored
374 if opt in options:
f68c4db @saghul Check object type with isinstance(obj, basestring) since basestring
saghul authored
375 if ((opt == 'say') and (isinstance(options['say'], basestring))):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
376 self._dict['say'] = Say(options['say']).json
37dbaa3 Initial upload
Edgar Gilchrist authored
377 else:
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
378 self._dict[opt] = options[opt]
37dbaa3 Initial upload
Edgar Gilchrist authored
379
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
380 class Redirect(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
381 """
8de435a @egilchri Better doc
egilchri authored
382 Class representing the "redirect" Tropo action. Builds a "redirect" JSON object.
383 Class constructor arg: to, a String
384 Class constructor options: name, required
385 Convenience function: Tropo.redirect()
386
37dbaa3 Initial upload
Edgar Gilchrist authored
387 (See https://www.tropo.com/docs/webapi/redirect.htm)
388
389 { "redirect": {
390 "to": Object,#Required
391 "name": String,
cf73576 add voice option to Say
Jeremy Jones authored
392 "required": Boolean } }
37dbaa3 Initial upload
Edgar Gilchrist authored
393 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
394 action = 'redirect'
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
395 options_array = ['name', 'required']
37dbaa3 Initial upload
Edgar Gilchrist authored
396
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
397 def __init__(self, to, **options):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
398 self._dict = {'to': to}
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
399 for opt in self.options_array:
37dbaa3 Initial upload
Edgar Gilchrist authored
400 if opt in options:
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
401 self._dict[opt] = options[opt]
37dbaa3 Initial upload
Edgar Gilchrist authored
402
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
403 class Reject(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
404 """
8de435a @egilchri Better doc
egilchri authored
405 Class representing the "reject" Tropo action. Builds a "reject" JSON object.
cf73576 add voice option to Say
Jeremy Jones authored
406 Class constructor arg:
407 Class constructor options:
8de435a @egilchri Better doc
egilchri authored
408 Convenience function: Tropo.reject()
409
37dbaa3 Initial upload
Edgar Gilchrist authored
410 (See https://www.tropo.com/docs/webapi/reject.htm)
411
cf73576 add voice option to Say
Jeremy Jones authored
412 { "reject": { } }
37dbaa3 Initial upload
Edgar Gilchrist authored
413 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
414 action = 'reject'
37dbaa3 Initial upload
Edgar Gilchrist authored
415
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
416 def __init__(self):
417 self._dict = {}
8de435a @egilchri Better doc
egilchri authored
418
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
419 class Say(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
420 """
8de435a @egilchri Better doc
egilchri authored
421 Class representing the "say" Tropo action. Builds a "say" JSON object.
422 Class constructor arg: message, a String, or a List of Strings
423 Class constructor options: attempts, bargein, choices, minConfidence, name, recognizer, required, say, timeout, voice
424 Convenience function: Tropo.say()
425
426 (See https://www.tropo.com/docs/webapi/say.htm)
37dbaa3 Initial upload
Edgar Gilchrist authored
427
428 { "say": {
cf73576 add voice option to Say
Jeremy Jones authored
429 "voice": String,
37dbaa3 Initial upload
Edgar Gilchrist authored
430 "as": String,
431 "name": String,
432 "required": Boolean,
433 "value": String #Required
cf73576 add voice option to Say
Jeremy Jones authored
434 } }
37dbaa3 Initial upload
Edgar Gilchrist authored
435 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
436 action = 'say'
dfa584a @egilchri Fixed gh-14 (conflict with 'as' and 'from' Python reserved words), an…
egilchri authored
437 # added _as because 'as' is reserved
438 options_array = ['_as', 'name', 'required', 'voice', 'allowSignals']
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
439
37dbaa3 Initial upload
Edgar Gilchrist authored
440 def __init__(self, message, **options):
441 dict = {}
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
442 for opt in self.options_array:
37dbaa3 Initial upload
Edgar Gilchrist authored
443 if opt in options:
dfa584a @egilchri Fixed gh-14 (conflict with 'as' and 'from' Python reserved words), an…
egilchri authored
444 if (opt == "_as"):
445 dict['as'] = options['_as']
446 else:
447 dict[opt] = options[opt]
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
448 self._list = []
8de435a @egilchri Better doc
egilchri authored
449 if (isinstance (message, list)):
450 for mess in message:
451 new_dict = dict.copy()
452 new_dict['value'] = mess
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
453 self._list.append(new_dict)
8de435a @egilchri Better doc
egilchri authored
454 else:
455 dict['value'] = message
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
456 self._list.append(dict)
37dbaa3 Initial upload
Edgar Gilchrist authored
457
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
458 @property
459 def json(self):
460 return self._list[0] if len(self._list) == 1 else self._list
37dbaa3 Initial upload
Edgar Gilchrist authored
461
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
462 @property
463 def obj(self):
464 return {self.action: self._list[0]} if len(self._list) == 1 else {self.action: self._list}
37dbaa3 Initial upload
Edgar Gilchrist authored
465
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
466 class StartRecording(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
467 """
8de435a @egilchri Better doc
egilchri authored
468 Class representing the "startRecording" Tropo action. Builds a "startRecording" JSON object.
469 Class constructor arg: url, a String
470 Class constructor options: format, method, username, password
471 Convenience function: Tropo.startRecording()
472
473 (See https://www.tropo.com/docs/webapi/startrecording.htm)
474
37dbaa3 Initial upload
Edgar Gilchrist authored
475 { "startRecording": {
476 "format": String,
477 "method": String,
478 "url": String,#Required
479 "username": String,
a730f8c Added transcriptionID, transcriptionEmailFormat and transcriptionOutU…
Kevin Bond authored
480 "password": String,
481 "transcriptionID": String
482 "transcriptionEmailFormat":String
483 "transcriptionOutURI": String} }
37dbaa3 Initial upload
Edgar Gilchrist authored
484 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
485 action = 'startRecording'
a730f8c Added transcriptionID, transcriptionEmailFormat and transcriptionOutU…
Kevin Bond authored
486 options_array = ['format', 'method', 'username', 'password', 'transcriptionID', 'transcriptionEmailFormat', 'transcriptionOutURI']
37dbaa3 Initial upload
Edgar Gilchrist authored
487
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
488 def __init__(self, url, **options):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
489 self._dict = {'url': url}
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
490 for opt in self.options_array:
37dbaa3 Initial upload
Edgar Gilchrist authored
491 if opt in options:
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
492 self._dict[opt] = options[opt]
37dbaa3 Initial upload
Edgar Gilchrist authored
493
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
494 class StopRecording(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
495 """
8de435a @egilchri Better doc
egilchri authored
496 Class representing the "stopRecording" Tropo action. Builds a "stopRecording" JSON object.
497 Class constructor arg:
498 Class constructor options:
499 Convenience function: Tropo.stopRecording()
500
501 (See https://www.tropo.com/docs/webapi/stoprecording.htm)
cf73576 add voice option to Say
Jeremy Jones authored
502 { "stopRecording": { } }
37dbaa3 Initial upload
Edgar Gilchrist authored
503 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
504 action = 'stopRecording'
505
37dbaa3 Initial upload
Edgar Gilchrist authored
506 def __init__(self):
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
507 self._dict = {}
37dbaa3 Initial upload
Edgar Gilchrist authored
508
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
509 class Transfer(TropoAction):
37dbaa3 Initial upload
Edgar Gilchrist authored
510 """
8de435a @egilchri Better doc
egilchri authored
511 Class representing the "transfer" Tropo action. Builds a "transfer" JSON object.
512 Class constructor arg: to, a String, or List
513 Class constructor options: answerOnMedia, choices, from, name, required, terminator
514 Convenience function: Tropo.transfer()
515
516 (See https://www.tropo.com/docs/webapi/transfer.htm)
37dbaa3 Initial upload
Edgar Gilchrist authored
517 { "transfer": {
518 "to": String or Array,#Required
519 "answerOnMedia": Boolean,
520 "choices": Object,
5b6fbe5 @egilchri Fix gh-22, passing in headers to transfer()
egilchri authored
521 # # **Wed May 18 21:14:05 2011** -- egilchri
522 "headers": Object,
523 # # **Wed May 18 21:14:05 2011** -- egilchri
524
dfa584a @egilchri Fixed gh-14 (conflict with 'as' and 'from' Python reserved words), an…
egilchri authored
525 "from": String,
37dbaa3 Initial upload
Edgar Gilchrist authored
526 "name": String,
527 "required": Boolean,
528 "terminator": String,
bf68866 @kevinbond added machineDetection to the transfer method
kevinbond authored
529 "timeout": Float,
530 "machineDetection": Boolean or Object } }
37dbaa3 Initial upload
Edgar Gilchrist authored
531 """
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
532 action = 'transfer'
bf68866 @kevinbond added machineDetection to the transfer method
kevinbond authored
533 options_array = ['answerOnMedia', 'choices', '_from', 'name', 'on', 'required', 'allowSignals', 'headers', 'interdigitTimeout', 'ringRepeat', 'timeout', 'machineDetection']
37dbaa3 Initial upload
Edgar Gilchrist authored
534
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
535 def __init__(self, to, **options):
0f3b31f @kevinbond added whisper to transfer
kevinbond authored
536 self._dict = {'to': to}
537 for opt in self.options_array:
538 if opt in options:
539 whisper = []
540 for key, val in options['on'].iteritems():
541 newDict = {}
542
543 if(key == "ask"):
544 newDict['ask'] = val
b0967b1 @kevinbond fixed whisper to have both connect and ring
kevinbond authored
545 newDict['event'] = 'connect'
0f3b31f @kevinbond added whisper to transfer
kevinbond authored
546
547 elif(key == "say"):
548 newDict['say'] = val
b0967b1 @kevinbond fixed whisper to have both connect and ring
kevinbond authored
549 newDict['event'] = 'connect'
0f3b31f @kevinbond added whisper to transfer
kevinbond authored
550
551 elif(key == "wait"):
552 newDict['wait'] = val
b0967b1 @kevinbond fixed whisper to have both connect and ring
kevinbond authored
553 newDict['event'] = 'connect'
0f3b31f @kevinbond added whisper to transfer
kevinbond authored
554
555 elif(key == "message"):
556 newDict['message'] = val
b0967b1 @kevinbond fixed whisper to have both connect and ring
kevinbond authored
557 newDict['event'] = 'connect'
558
559 elif(key == "ring"):
560 newDict['say'] = val
561 newDict['event'] = 'ring'
562
0f3b31f @kevinbond added whisper to transfer
kevinbond authored
563
564 whisper.append(newDict)
565
566 self._dict['on'] = whisper
567 if (opt == '_from'):
568 self._dict['from'] = options['_from']
569 elif(opt == 'choices'):
570 self._dict['choices'] = options['choices']
571 elif(opt != 'on'):
572 self._dict[opt] = options[opt]
573
5d4026f Added the wait method with params milliseconds and allowsiganls
Kevin Bond authored
574 class Wait(TropoAction):
575 """
576 Class representing the "wait" Tropo action. Builds a "wait" JSON object.
577 Class constructor arg: milliseconds, an Integer
578 Class constructor options: allowSignals
579 Convenience function: Tropo.wait()
580
581 (See https://www.tropo.com/docs/webapi/wait.htm)
582 { "wait": {
583 "milliseconds": Integer,#Required
584 "allowSignals": String or Array
585 """
586
587 action = 'wait'
588 options_array = ['allowSignals']
589
590 def __init__(self, milliseconds, **options):
591 self._dict = {'milliseconds': milliseconds}
592 for opt in self.options_array:
593 if opt in options:
594 self._dict[opt] = options[opt]
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
595
596 class Result(object):
597 """
cf73576 add voice option to Say
Jeremy Jones authored
598 Returned anytime a request is made to the Tropo Web API.
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
599 Method: getValue
600 (See https://www.tropo.com/docs/webapi/result.htm)
601
602 { "result": {
603 "actions": Array or Object,
604 "complete": Boolean,
605 "error": String,
606 "sequence": Integer,
607 "sessionDuration": Integer,
608 "sessionId": String,
609 "state": String } }
610 """
680d20c @kevinbond added 'connectedDuration', 'duration', 'calledID'
kevinbond authored
611 options_array = ['actions','complete','error','sequence', 'sessionDuration', 'sessionId', 'state', 'userType', 'connectedDuration', 'duration', 'calledID']
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
612
613 def __init__(self, result_json):
614 result_data = jsonlib.loads(result_json)
615 result_dict = result_data['result']
616
449ecd6 @saghul Simplified code in Result class
saghul authored
617 for opt in self.options_array:
5c3f9d9 @saghul Fixed setting of attributes
saghul authored
618 if result_dict.get(opt, False):
619 setattr(self, '_%s' % opt, result_dict[opt])
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
620
621 def getValue(self):
622 """
623 Get the value of the previously POSTed Tropo action.
624 """
625 actions = self._actions
626
627 if (type (actions) is list):
628 dict = actions[0]
629 else:
630 dict = actions
dfa584a @egilchri Fixed gh-14 (conflict with 'as' and 'from' Python reserved words), an…
egilchri authored
631 # return dict['value'] Fixes issue 17
d02ab2e @egilchri getValue() should utilize value, not interpretation. Fixes gh-17
egilchri authored
632 return dict['value']
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
633
fc81080 @kevinbond added a GET method for userType(machineDetection) and added a full ex…
kevinbond authored
634
635 def getUserType(self):
636 """
637 Get the userType of the previously POSTed Tropo action.
638 """
639 userType = self._userType
640 return userType
641
07fd03f @egilchri tropo.py should have gone out with previous push
egilchri authored
642 # # **Tue May 17 07:17:38 2011** -- egilchri
643
644 def getInterpretation(self):
645 """
646 Get the value of the previously POSTed Tropo action.
647 """
648 actions = self._actions
649
650 if (type (actions) is list):
651 dict = actions[0]
652 else:
653 dict = actions
654 return dict['interpretation']
655
656 # # **Tue May 17 07:17:38 2011** -- egilchri
657
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
658
659 class Session(object):
660 """
cf73576 add voice option to Say
Jeremy Jones authored
661 Session is the payload sent as an HTTP POST to your web application when a new session arrives.
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
662 (See https://www.tropo.com/docs/webapi/session.htm)
d69fd08 Document that 'from' in the session object is 'fromaddress' in Python…
Adam Kalsey authored
663
664 Because 'from' is a reserved word in Python, the session object's 'from' property is called
665 fromaddress in the Python library
24b3395 @saghul Added TropoAction class as the parent class of all actions:
saghul authored
666 """
667 def __init__(self, session_json):
668 session_data = jsonlib.loads(session_json)
669 session_dict = session_data['session']
670 for key in session_dict:
671 val = session_dict[key]
5b39095 @akalsey "from" address in session object can't be converted to an attribute s…
akalsey authored
672 if key == "from":
cf73576 add voice option to Say
Jeremy Jones authored
673 setattr(self, "fromaddress", val)
5b39095 @akalsey "from" address in session object can't be converted to an attribute s…
akalsey authored
674 else:
675 setattr(self, key, val)
5646184 @danyork Fixed indentation level on Ted's addition
danyork authored
676 setattr(self, 'dict', session_dict)
37dbaa3 Initial upload
Edgar Gilchrist authored
677
678
4da67a7 @saghul Made all classes inherit from object
saghul authored
679 class Tropo(object):
37dbaa3 Initial upload
Edgar Gilchrist authored
680 """
681 This is the top level class for all the Tropo web api actions.
8de435a @egilchri Better doc
egilchri authored
682 The methods of this class implement individual Tropo actions.
37dbaa3 Initial upload
Edgar Gilchrist authored
683 Individual actions are each methods on this class.
684
8de435a @egilchri Better doc
egilchri authored
685 Each method takes one or more required arguments, followed by optional
37dbaa3 Initial upload
Edgar Gilchrist authored
686 arguments expressed as key=value pairs.
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
687
8de435a @egilchri Better doc
egilchri authored
688 The optional arguments for these methods are described here:
689 https://www.tropo.com/docs/webapi/
37dbaa3 Initial upload
Edgar Gilchrist authored
690 """
691 def __init__(self):
692 self._steps = []
693
07fd03f @egilchri tropo.py should have gone out with previous push
egilchri authored
694 # # **Sun May 15 21:05:01 2011** -- egilchri
695 def setVoice(self, voice):
696 self.voice = voice
697
698 # # end **Sun May 15 21:05:01 2011** -- egilchri
699
37dbaa3 Initial upload
Edgar Gilchrist authored
700 def ask(self, choices, **options):
701 """
8de435a @egilchri Better doc
egilchri authored
702 Sends a prompt to the user and optionally waits for a response.
703 Arguments: "choices" is a Choices object
704 See https://www.tropo.com/docs/webapi/ask.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
705 """
07fd03f @egilchri tropo.py should have gone out with previous push
egilchri authored
706 # # **Sun May 15 21:21:29 2011** -- egilchri
707
708 # Settng the voice in this method call has priority.
709 # Otherwise, we can pick up the voice from the Tropo object,
710 # if it is set there.
711 if hasattr (self, 'voice'):
712 if (not 'voice' in options):
713 options['voice'] = self.voice
714
715 # # **Sun May 15 21:21:29 2011** -- egilchri
716
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
717 self._steps.append(Ask(choices, **options).obj)
37dbaa3 Initial upload
Edgar Gilchrist authored
718
07fd03f @egilchri tropo.py should have gone out with previous push
egilchri authored
719
37dbaa3 Initial upload
Edgar Gilchrist authored
720 def call (self, to, **options):
721 """
cf73576 add voice option to Say
Jeremy Jones authored
722 Places a call or sends an an IM, Twitter, or SMS message. To start a call, use the Session API to tell Tropo to launch your code.
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
723
8de435a @egilchri Better doc
egilchri authored
724 Arguments: to is a String.
725 Argument: **options is a set of optional keyword arguments.
726 See https://www.tropo.com/docs/webapi/call.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
727 """
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
728 self._steps.append(Call (to, **options).obj)
37dbaa3 Initial upload
Edgar Gilchrist authored
729
730 def conference(self, id, **options):
731 """
cf73576 add voice option to Say
Jeremy Jones authored
732 This object allows multiple lines in separate sessions to be conferenced together so that the parties on each line can talk to each other simultaneously.
733 This is a voice channel only feature.
8de435a @egilchri Better doc
egilchri authored
734 Argument: "id" is a String
735 Argument: **options is a set of optional keyword arguments.
736 See https://www.tropo.com/docs/webapi/conference.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
737 """
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
738 self._steps.append(Conference(id, **options).obj)
37dbaa3 Initial upload
Edgar Gilchrist authored
739
740 def hangup(self):
741 """
8de435a @egilchri Better doc
egilchri authored
742 This method instructs Tropo to "hang-up" or disconnect the session associated with the current session.
743 See https://www.tropo.com/docs/webapi/hangup.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
744 """
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
745 self._steps.append(Hangup().obj)
37dbaa3 Initial upload
Edgar Gilchrist authored
746
bcfb063 @egilchri Things basically working but not yet ready for prime time
egilchri authored
747 def message (self, say_obj, to, **options):
37dbaa3 Initial upload
Edgar Gilchrist authored
748 """
cf73576 add voice option to Say
Jeremy Jones authored
749 A shortcut method to create a session, say something, and hang up, all in one step. This is particularly useful for sending out a quick SMS or IM.
845f0e9 @saghul Simplified dict handling code a bit and cleaned up whitespaces.
saghul authored
750
8de435a @egilchri Better doc
egilchri authored
751 Argument: "say_obj" is a Say object
752 Argument: "to" is a String
753 Argument: **options is a set of optional keyword arguments.
754 See https://www.tropo.com/docs/webapi/message.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
755 """
f68c4db @saghul Check object type with isinstance(obj, basestring) since basestring
saghul authored
756 if isinstance(say_obj, basestring):
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
757 say = Say(say_obj).obj
bcfb063 @egilchri Things basically working but not yet ready for prime time
egilchri authored
758 else:
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
759 say = say_obj
760 self._steps.append(Message(say, to, **options).obj)
37dbaa3 Initial upload
Edgar Gilchrist authored
761
762 def on(self, event, **options):
763 """
cf73576 add voice option to Say
Jeremy Jones authored
764 Adds an event callback so that your application may be notified when a particular event occurs.
8f9acea fixed the on events voice param and added 'interdigitTimeout', 'speec…
Kevin Bond authored
765 Possible events are: "continue", "error", "incomplete" and "hangup".
766 Argument: event is an event
8de435a @egilchri Better doc
egilchri authored
767 Argument: **options is a set of optional keyword arguments.
768 See https://www.tropo.com/docs/webapi/on.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
769 """
8f9acea fixed the on events voice param and added 'interdigitTimeout', 'speec…
Kevin Bond authored
770
771 if hasattr (self, 'voice'):
772 if (not 'voice' in options):
773 options['voice'] = self.voice
774
775
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
776 self._steps.append(On(event, **options).obj)
37dbaa3 Initial upload
Edgar Gilchrist authored
777
778 def record(self, **options):
779 """
cf73576 add voice option to Say
Jeremy Jones authored
780 Plays a prompt (audio file or text to speech) and optionally waits for a response from the caller that is recorded.
8de435a @egilchri Better doc
egilchri authored
781 Argument: **options is a set of optional keyword arguments.
782 See https://www.tropo.com/docs/webapi/record.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
783 """
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
784 self._steps.append(Record(**options).obj)
37dbaa3 Initial upload
Edgar Gilchrist authored
785
786 def redirect(self, id, **options):
787 """
cf73576 add voice option to Say
Jeremy Jones authored
788 Forwards an incoming call to another destination / phone number before answering it.
8de435a @egilchri Better doc
egilchri authored
789 Argument: id is a String
790 Argument: **options is a set of optional keyword arguments.
791 See https://www.tropo.com/docs/webapi/redirect.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
792 """
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
793 self._steps.append(Redirect(id, **options).obj)
37dbaa3 Initial upload
Edgar Gilchrist authored
794
d3dcee6 @egilchri Work on unittest setup
egilchri authored
795 def reject(self):
37dbaa3 Initial upload
Edgar Gilchrist authored
796 """
cf73576 add voice option to Say
Jeremy Jones authored
797 Allows Tropo applications to reject incoming sessions before they are answered.
8de435a @egilchri Better doc
egilchri authored
798 See https://www.tropo.com/docs/webapi/reject.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
799 """
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
800 self._steps.append(Reject().obj)
37dbaa3 Initial upload
Edgar Gilchrist authored
801
802 def say(self, message, **options):
803 """
cf73576 add voice option to Say
Jeremy Jones authored
804 When the current session is a voice channel this key will either play a message or an audio file from a URL.
805 In the case of an text channel it will send the text back to the user via i nstant messaging or SMS.
8de435a @egilchri Better doc
egilchri authored
806 Argument: message is a string
807 Argument: **options is a set of optional keyword arguments.
808 See https://www.tropo.com/docs/webapi/say.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
809 """
dfa584a @egilchri Fixed gh-14 (conflict with 'as' and 'from' Python reserved words), an…
egilchri authored
810 #voice = self.voice
07fd03f @egilchri tropo.py should have gone out with previous push
egilchri authored
811 # # **Sun May 15 21:21:29 2011** -- egilchri
812
813 # Settng the voice in this method call has priority.
814 # Otherwise, we can pick up the voice from the Tropo object,
815 # if it is set there.
816 if hasattr (self, 'voice'):
817 if (not 'voice' in options):
818 options['voice'] = self.voice
819 # # **Sun May 15 21:21:29 2011** -- egilchri
820
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
821 self._steps.append(Say(message, **options).obj)
37dbaa3 Initial upload
Edgar Gilchrist authored
822
823 def startRecording(self, url, **options):
824 """
cf73576 add voice option to Say
Jeremy Jones authored
825 Allows Tropo applications to begin recording the current session.
8de435a @egilchri Better doc
egilchri authored
826 Argument: url is a string
827 Argument: **options is a set of optional keyword arguments.
828 See https://www.tropo.com/docs/webapi/startrecording.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
829 """
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
830 self._steps.append(StartRecording(url, **options).obj)
37dbaa3 Initial upload
Edgar Gilchrist authored
831
832 def stopRecording(self):
833 """
8de435a @egilchri Better doc
egilchri authored
834 Stops a previously started recording.
835 See https://www.tropo.com/docs/webapi/stoprecording.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
836 """
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
837 self._steps.append(StopRecording().obj)
37dbaa3 Initial upload
Edgar Gilchrist authored
838
839 def transfer(self, to, **options):
840 """
cf73576 add voice option to Say
Jeremy Jones authored
841 Transfers an already answered call to another destination / phone number.
8de435a @egilchri Better doc
egilchri authored
842 Argument: to is a string
843 Argument: **options is a set of optional keyword arguments.
844 See https://www.tropo.com/docs/webapi/transfer.htm
37dbaa3 Initial upload
Edgar Gilchrist authored
845 """
77964ff @saghul Simplified code in Tropo class functions.
saghul authored
846 self._steps.append(Transfer(to, **options).obj)
5d4026f Added the wait method with params milliseconds and allowsiganls
Kevin Bond authored
847
848 def wait(self, milliseconds, **options):
849 """
850 Allows the thread to sleep for a given amount of time in milliseconds
851 Argument: milliseconds is an Integer
852 Argument: **options is a set of optional keyword arguments.
853 See https://www.tropo.com/docs/webapi/wait.htm
854 """
855 self._steps.append(Wait(milliseconds, **options).obj)
856
4672596 @saghul Removed PrettyJson function and merged funtionality with RenderJson.
saghul authored
857 def RenderJson(self, pretty=False):
8de435a @egilchri Better doc
egilchri authored
858 """
859 Render a Tropo object into a Json string.
860 """
37dbaa3 Initial upload
Edgar Gilchrist authored
861 steps = self._steps
862 topdict = {}
863 topdict['tropo'] = steps
4672596 @saghul Removed PrettyJson function and merged funtionality with RenderJson.
saghul authored
864 if pretty:
865 try:
866 json = jsonlib.dumps(topdict, indent=4, sort_keys=False)
867 except TypeError:
868 json = jsonlib.dumps(topdict)
869 else:
870 json = jsonlib.dumps(topdict)
37dbaa3 Initial upload
Edgar Gilchrist authored
871 return json
872
49e9a4d @danyork Updated tropo_web_api.py to print test instructions when run
danyork authored
873 if __name__ == '__main__':
874 print """
cf73576 add voice option to Say
Jeremy Jones authored
875
49e9a4d @danyork Updated tropo_web_api.py to print test instructions when run
danyork authored
876 This is the Python web API for http://www.tropo.com/
cf73576 add voice option to Say
Jeremy Jones authored
877
49e9a4d @danyork Updated tropo_web_api.py to print test instructions when run
danyork authored
878 To run the test suite, please run:
cf73576 add voice option to Say
Jeremy Jones authored
879
49e9a4d @danyork Updated tropo_web_api.py to print test instructions when run
danyork authored
880 cd test
881 python test.py
cf73576 add voice option to Say
Jeremy Jones authored
882
49e9a4d @danyork Updated tropo_web_api.py to print test instructions when run
danyork authored
883
884 """
885
886
Something went wrong with that request. Please try again.