How to persist data through HTTP redirects in an IVR call

61 views
Skip to first unread message

Joan Perals

unread,
Jan 22, 2015, 5:16:42 AM1/22/15
to plivo...@googlegroups.com
Hi,

I'm writing an IVR app with Python/Flask. The app is nothing too special, and I've based my work on the examples around. However I'm facing a problem regarding keeping session data.

It looks like the way to ask questions to the caller is to write separate methods with their own URLs so that Plivo is subsequently redirected to them with POST requests. So to ask something we need to write the code for the question somewhere and the answer validation/analysis somewhere else, like this:

@app.route('/ask_something', methods=['GET', 'POST',])
def ask_something():
    response = plivo.Response()
    action_url = url_for('validate_answer', _external=True)
    getDigits = plivo.GetDigits(action=action_url, method='POST',
                                timeout=4, numDigits=1, retries=4)
    getDigits.addSpeak(body='This is a question. Press 1 for yes, press 2 for no')
    response.add(getDigits)
    return Response(str(response), mimetype='text/xml')


@app.route('/validate_answer', methods=['POST',])
def validate_answer():
    response = plivo.Response()
    input_digits = request.form.get('Digits', None)
    print input_digits # outputs: 1

    session['answer'] = input_digits
    print session #outputs: <SecureCookieSession {'results': u'1'}>
    go_to(response, 'next_step')
    return Response(str(response), mimetype='text/xml')

The problem is, I want to ask something, have the answer stored somewhere and retreive it again in a subsequent step/method. Sounds simple, but of course we have to manage concurrent calls so we can't use global variables. Flask's 'session' functionality seems the way to go, but it's not working for me. For each redirect the 'session' object starts being empty again.

@app.route('/next_step', methods=['GET', 'POST',])
def next_step():
    print session.get('answer', 'no answer in the session!') # outputs: no answer in the session!
    print session #outputs: <SecureCookieSession {}>
    (...)

I've already tried quite a lot of things like tweaking the SERVER_NAME or SESSION_TYPE config variables... Basically everything I have found around about Flask session management that could be the cause of the problem. I have also tried Flask's built-in session object as well as Shipeng Feng's Flask.Session extension. But it looks like I am still not able to make Flask identify the subsequent URL calls as coming from the same user/caller. The server runs behind Apache with a proxy directive.

I've tried visiting the initial URL (with all the extra parameters that Plivo adds to it) with a browser and I get a cookie. Is it possible that Plivo doesn't 'swallow' it, and/or doesn't give it back on the next call? Or am I just doing something wrong?

Thanks!

parth shah

unread,
Jan 22, 2015, 5:30:23 AM1/22/15
to plivo...@googlegroups.com
Plivo [opensource - I am using ] is working in backend process won't create session for any of call.
Have you tried to pass extra parameters with URL with every call?

AnswerUrl?someUserId=123 [greetings]
-> questionUrl?someUserId=123 [Question related to user]
    -> checkAnswer?someUserId=123 [chekc answer for particular user]


You can pass individual parameters to each call, and managed the actions through your code.

--
You received this message because you are subscribed to the Google Groups "Plivo Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plivo-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joan Perals

unread,
Jan 22, 2015, 6:02:41 AM1/22/15
to plivo...@googlegroups.com
Thanks Parth. Hopefully this will work!

I was also thinking that I could use the CallUUID that seems to come with every request.

In any case, I have some alternatives to try out now so I'm not stuck anymore :-) Thanks!
Reply all
Reply to author
Forward
0 new messages