lakshmi
lakshmi

Reputation: 211

I want to retrieve the value of the parameter of the previous intent in dialogflow

I have a dialogflow bot that asks for firstname,lastname,dobday,dobmonth,dob year individually from the user(so I have 5 intents in DF and 5 seperate intent.js files for each field in webhook ).
I want to validate the dob in such a way that when the user gives the month ,bot should validate whether the user is entering the days in correct format.This should be in Nodejs

example:

Bot:Hi,please enter your first name
User:John
Bot:your last name
user:Sally
Bot:your dob month?
User:02
Bot:your dob day?
User:31
Bot:sorry,this is invalid dob

I created a seperate intents for each of the fields and validating in webhook for each field using nodejs.I am not sure how to proceed for this type of validation.For this,do I need to use any contexts or followup intents?If I have to validate dob day in a seperate .js file ,I need to retreive the month value retained from the user.

Till now: I have validated the date of birth month that I get from the user .I am new to Javascript and node js.

enter image description here

enter image description here

Upvotes: 0

Views: 452

Answers (3)

Mizar Contasti
Mizar Contasti

Reputation: 26

First I recommend you to get the variable from the Dialogflow without backend, then read it from the diagnostic info, if the information is watched you can get from the backend response.

Upvotes: 0

Ricco D
Ricco D

Reputation: 7287

To add on to the answer of @MizarConstanti, you can use the following for your entities:

  • For date you can use entity @sys.date
  • For first name @sys.given-name
  • For last name @sys.last-name

NOTE: For given name and last name entities, these entities could only recognize the common names (reference).

An alternative for getting dates and names is you can create training phrases in this manner and extract the information using the defined entities.

Intent-> test intent

enter image description here

enter image description here

Intent -> getName enter image description here enter image description here

If you are using library dialogflow-fulfillment in Dialogflow inline editor these entities could be called using this code:

'use strict';

const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const axios = require('axios'); 

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });


function yourFunctionHandler(agent) {
    // initial value of agent.parameters.date is 1994-07-29T12:00:00+08:00
    // thus the splitting done below
    const date = agent.parameters.date.split('T')[0];
    const year = agent.parameters.date.split('-')[0];
    const month = agent.parameters.date.split('-')[1];
    const day = agent.parameters.date.split('-')[2].split('T')[0];
    agent.add(`year: ${year}, month:${month}, day:${day}`);
  }

function getName(agent) {
    const lastName = agent.parameters.lastName;
    const firstName= agent.parameters.givenName;
    agent.add(`first: ${firstName}, last: ${lastName}`);
}  
  
  // Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('test intent', yourFunctionHandler);
  intentMap.set('getName', getName);
  agent.handleRequest(intentMap);
});

Test for date and name intent: enter image description here

Upvotes: 1

Mizar Contasti
Mizar Contasti

Reputation: 26

I recommend you to save the information in a context. then you can retrieve the data on whatever intent that is in the same context.

Upvotes: 1

Related Questions