Reputation: 204
I am working on a chat bot in Dialogflow and want to validate someones age. A quick bit of context: I'm creating a chat bot for identifying care needs such as residential or dementia care. In the initial enquiry I want to be able to make sure that the user is 65 years or older by doing a quick IF statement in the fulfilment code in Dialogflow!
Here are my current intents: Current Intents
Here is the getUserInfo intent: getUserInfo intent
Here is the fulfilment code:
'use strict';
// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');
// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');
// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});
app.intent('careEqnuiry - yourself - getUserInfo', (conv, {age}) => {
const userAge = age;
if (userAge < 65) {
conv.add("You're not old enough to recieve care!");
}
});
// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
This is all new to me.
Upvotes: 2
Views: 1565
Reputation: 381
The second argument to the callback of the intent handler is an object that contains all the parameters (entities) from Dialogflow.
In your current code you are deconstructing this object for the age parameter (i.e.: {age}
).
I noticed you have two different parameters, age and given-name.
You can get these values by doing the following:
'use strict';
// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');
// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');
// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});
app.intent('careEqnuiry - yourself - getUserInfo', (conv, params) => {
const name = params['given-name'];
const age = params['age'];
if (age.amount < 65) {
conv.ask("You're not old enough to receive care!");
}
});
// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
Also, the correct way to return a response from a conversation is to use the ask()
or close()
methods on the conversation object. ask()
sends a response while allowing the conversation to continue, and close
sends a response and ends the conversation.
Upvotes: 2