Skip to content

Instantly share code, notes, and snippets.

@ianjuma
Created June 23, 2016 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianjuma/ec27ad460e1b46f1613c0daa197a2e1e to your computer and use it in GitHub Desktop.
Save ianjuma/ec27ad460e1b46f1613c0daa197a2e1e to your computer and use it in GitHub Desktop.
@app.route('/api/voice/callback/', methods=['POST'])
def voice_callback():
is_active = request.values.get('isActive', None)
session_id = request.values.get('sessionId', None)
caller_number = request.values.get('callerNumber', None)
direction = request.values.get('direction', None)
destination = request.values.get('destination', None)
if isActive:
r.hset(destination, 'phoneNumber', caller_number)
r.hset(destination, 'sessionId', session_id)
response = '<?xml version="1.0" encoding="UTF-8"?>'
response += '<Response>'
response += '<Say maxDuration="5" playBeep="false"> Demo, call in to see your location </Say>'
response += '</Response>'
else:
durationInSeconds = request.values.get('durationInSeconds', None)
if int(durationInSeconds) > 0:
# publish call conversion - initiated event
visitor = Visitor()
visitor.ip_address = request.remote_addr
session = Session()
event = Event(‘conversion’, ‘call-initiated’) # category — action
else:
# publish call conversion - droppped event
visitor = Visitor()
visitor.ip_address = request.remote_addr
session = Session()
event = Event(‘conversion’, ‘call-dropped’)
tracker.track_event(event, session, visitor)
resp = make_response(response, 200)
resp.headers['Content-Type'] = "application/xml"
resp.cache_control.no_cache = True
return resp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment