Skip to content

Commit 595fd39

Browse files
committed
TROPO-12172
Add answer to TROPO JSON helper library with support for RPID parameters - WebAPI Python
1 parent b1bcf22 commit 595fd39

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

samples/test_answer.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import sys
2+
sys.path = ['..'] + sys.path
3+
from itty import *
4+
from tropo import Tropo
5+
6+
7+
@post('/index.json')
8+
def index(request):
9+
t = Tropo()
10+
t.answer(headers={"P-Header":"value goes here","Remote-Party-ID":"\"John Doe\"<sip:jdoe@foo.com>;party=calling;id-type=subscriber;privacy=full;screen=yes"})
11+
t.say('This is your mother. Did you brush your teeth today?')
12+
json = t.RenderJson()
13+
print json
14+
return json
15+
16+
17+
run_itty(server='wsgiref', host='192.168.26.1', port=8888)
18+
19+

tropo.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,28 @@ def __init__(self, choices, **options):
104104
else:
105105
self._dict[opt] = options[opt]
106106

107+
class Answer(TropoAction):
108+
"""
109+
Class representing the "answer" Tropo action. Builds a "answer" JSON object.
110+
Class constructor arg: headers, a Object
111+
Class constructor options: headers
112+
Convenience function: Tropo.answer()
113+
114+
(See https://www.tropo.com/docswebapi/answer)
115+
116+
{ "answer": {
117+
"headers": Object } }
118+
"""
119+
action = 'answer'
120+
options_array = []
121+
122+
def __init__(self, headers, **options):
123+
self._dict = {'headers': headers}
124+
for opt in self.options_array:
125+
if opt in options:
126+
self._dict[opt] = options[opt]
127+
128+
107129
class Call(TropoAction):
108130
"""
109131
Class representing the "call" Tropo action. Builds a "call" JSON object.
@@ -820,6 +842,15 @@ def ask(self, choices, **options):
820842
self._steps.append(Ask(choices, **options).obj)
821843

822844

845+
def answer (self, headers, **options):
846+
"""
847+
Places a call or sends an an IM, Twitter, or SMS message. To start a call, use the Session API headers tell Tropo headers launch your code.
848+
Arguments: headers is a String.
849+
Argument: **options is a set of optional keyword arguments.
850+
See https://www.tropo.com/docs/webapi/answer
851+
"""
852+
self._steps.append(Answer (headers, **options).obj)
853+
823854
def call (self, to, **options):
824855
"""
825856
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.

0 commit comments

Comments
 (0)