Skip to content

Commit

Permalink
TROPO-12172
Browse files Browse the repository at this point in the history
Add answer to TROPO JSON helper library with support for RPID parameters
- WebAPI Python
  • Loading branch information
frankyuCisco committed Aug 24, 2017
1 parent b1bcf22 commit 595fd39
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
19 changes: 19 additions & 0 deletions samples/test_answer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
sys.path = ['..'] + sys.path
from itty import *
from tropo import Tropo


@post('/index.json')
def index(request):
t = Tropo()
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"})
t.say('This is your mother. Did you brush your teeth today?')
json = t.RenderJson()
print json
return json


run_itty(server='wsgiref', host='192.168.26.1', port=8888)


31 changes: 31 additions & 0 deletions tropo.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ def __init__(self, choices, **options):
else:
self._dict[opt] = options[opt]

class Answer(TropoAction):
"""
Class representing the "answer" Tropo action. Builds a "answer" JSON object.
Class constructor arg: headers, a Object
Class constructor options: headers
Convenience function: Tropo.answer()
(See https://www.tropo.com/docswebapi/answer)
{ "answer": {
"headers": Object } }
"""
action = 'answer'
options_array = []

def __init__(self, headers, **options):
self._dict = {'headers': headers}
for opt in self.options_array:
if opt in options:
self._dict[opt] = options[opt]


class Call(TropoAction):
"""
Class representing the "call" Tropo action. Builds a "call" JSON object.
Expand Down Expand Up @@ -820,6 +842,15 @@ def ask(self, choices, **options):
self._steps.append(Ask(choices, **options).obj)


def answer (self, headers, **options):
"""
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.
Arguments: headers is a String.
Argument: **options is a set of optional keyword arguments.
See https://www.tropo.com/docs/webapi/answer
"""
self._steps.append(Answer (headers, **options).obj)

def call (self, to, **options):
"""
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.
Expand Down

0 comments on commit 595fd39

Please sign in to comment.