Reputation:
I have created a chatbot in Dialogflow in which when Welcome Intent is called, I receive the user's email id from an API and I stored it in context: mail. I am accessing this email in another Intent to register the user but I get no value. Upon printing the context on the console, it showed the email id, then why not in the RegisterUser Intent? I used the inline editor for fulfillment in Dialogflow.
Welcome Intent:
function getmail(agent){
var myJSONOb = {
"param1":param1
};
var options = {
method: 'post',
uri: 'my_API',
body: myJSONOb,
json: true
};
process.env.NODE_TLS_REJECT_UNAUTHORIZED = false;
return rp( options )
.then( body => {
let ctx = {'name': 'mail', 'lifespan': 15, 'parameters': {'email':body.mail}};
agent.setContext(ctx);
// this prints: { name: 'mail', lifespan: 15, parameters: { email: '[email protected]' } }
})
.catch( err => {...
});
}
In register User:
function registerUser(agent){
let params = agent.getContext("mail").parameters;
let email = params.email;
agent.add("email "+email);
//this just prints : 'email' and no value
}
Upvotes: 0
Views: 527
Reputation: 3036
I am not sure which version you are? but you can do this like below also. I think you are using NodeJS fulfillment webhook.
// Set the context
agent.context.set({
name: 'global_main_context',
lifespan: 5,
parameters: param
});
// get the context
let globalContext = agent.context.get('global_main_context');
Hope this helps!
Upvotes: 1