Harshad Sharma avatar Harshad Sharma committed 9c2c1ac

An example of how kookoo can be used + a commandline testing app.
Has _very_ rough edges.

Comments (0)

Files changed (1)

commandline_example.py

+from kookoo import *
+
+class RequestHandler(KookooRequestHandler):
+    response = KookooResponse()
+    
+    def new_call(self, caller):
+        r = self.response
+        return r.response(r.get_input(r.say('Enter your age: ')))
+    
+    def got_input(self, data):
+        r = self.response
+        text = 'Hi! You are %s years old!' %data
+        return r.response(r.say(text + r.hangup()))
+
+    def got_voice(self, data):
+        return self.session.data
+
+
+
+if __name__ == "__main__":
+    req = RequestHandler()
+    
+    print req.process(sid=1223, cid=9850885021, event='NewCall')
+    user_input = ''
+    sid = '123'
+    expecting_voice = False
+    
+    while user_input is not 'q':
+        user_input = raw_input('> ')
+        
+        if user_input == 'q':
+            print req.process(sid=sid, event='Disconnect')
+            break
+
+        if user_input == 'r':
+            if expecting_voice is True:
+                print req.process(sid=sid, event='Record', data='http://example.com/foobar.wav')
+            else:
+                print "Not expecting voice."
+            
+        try:
+            if user_input[-1] == '#':
+                user_input = user_input[:-1]
+                
+            numbers = int(user_input)
+            response = req.process(sid=sid, event='GotDTMF', data=user_input)
+            print response
+        except:
+            session = KookooSession(sid, {})
+            response = ''
+            pass
+        
+        if response is not None:
+            if '<hangup></hangup>' in response:
+                print 
+                print "="*10 + " hanging up " + "="*10
+                break
+        else:
+            session = KookooSession(sid, {})
+            print "Invalid response. Reseting and hanging up."
+            break
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.