I am using Dialogflow to receive user input and the received values are passed to the flask program using a webhook call. Session variables are set for this action on webhook call. For another google action, I am trying to retrieve the session variables. But, I am not able to access them. Let me know where I am going wrong. Thanks in advance.
DialogFlow Intent - setclass Receives the parameter 'class' (grade) from the User and invokes the Action setclass, which sets the session variables class and grade through webhook call.
Dialogflow Intent - getclass Action getclass gets the values set in the session through webhook call.
Flask program to store and receive values from session:
from flask import Flask, request, session, jsonify
app = Flask(__name__)
app.secret_key = "abc"
@app.route("/sessiontrial",methods=['POST','GET'])
def sessiontrial():
req = request.get_json(silent=True, force=True)
value = req.get('queryResult')
params = value.get('parameters')
action = value.get('action')
print("Inside sessiontrial")
if (action == "setclass"):
classno = params.get('class')
print (classno)
session['class'] = classno
session['grade'] = str(classno) + " Grade"
print (session['grade'])
res = {"fulfillmentText": classno}
return(jsonify(res))
if (action == "getclass"):
if 'class' in session:
classs = session['class']
print("Class is: ", classs)
gradee = session['grade']
print("Grade is: ", gradee)
res = {"fulfillmentText": gradee}
return(jsonify(res))
else:
print("Class not found in Session")
res = {"fulfillmentText": "Class not found in Session"}
return(jsonify(res))
if __name__ == '__main__':
app.run()