I am facing one issue in this:
I have created 4 intents bookTable, bookingDate, bookingTime and people count intent.i have added intent chaining using input and output context.
Suppose I am on third intent right now which is “Booking Time” & when I will say “Book A Table” to google home, it will directly jump to the first intent.
I need solution to not jump to the first intent but if user will say any except required input, then it will call custom fallback intent and stuck on that particular intent.
Please provide me the solution for not jumping the intent to any other..
// welcome intent here
app.intent('DefaultWelcomeIntent', (conv) => {
conv.ask('What would you like me to do for you?. Book a table or Check your calendar?');
});
// Booktable intent
app.intent('BookTable', (conv) => {
conv.ask('Please provide a date?');
});
// bookingDate intent
app.intent('bookingDate', (conv, params) => {
var speech = new Speech();
const currentDate = moment().format("YYYY-MM-DD");
const bookingDate = moment(params.date).format("YYYY-MM-DD");
const displayBookingDate = moment(bookingDate).format("DD MMM YYYY");
let say = '';
if (bookingDate && moment(bookingDate).isSameOrAfter(currentDate)) {
speech.say(`OK, ${displayBookingDate}`)
.pause('300ms')
.say(`Please provide time?`);
const speechOutput = speech.toObject();
conv.ask(speechOutput.speech);
conv.data.restaurantData.date = bookingDate;
} else {
say = `Please provide today's or upcoming date.`;
conv.ask(say);
}
});
// bookingTime intent
app.intent('bookingTime', (conv, params) => {
var speech = new Speech();
const currentDateTime = moment().format("YYYY-MM-DD HH:mm");
const bookingDate = moment(conv.data.restaurantData.date).format("YYYY-MM-DD");
const bookingTime = moment(params.time).format("HH:mm");
const booking12HourTimeString = moment(bookingTime, ["HH:mm"]).format("hh:mm A");
const concateDateTime = moment(bookingDate + " " + bookingTime).format('YYYY-MM-DD HH:mm');
let say = '';
if(moment(concateDateTime).isSameOrAfter(currentDateTime)) {
speech.say(`OK, ${booking12HourTimeString}`)
.pause('300ms')
.say(`How many people?`);
const speechOutput = speech.toObject();
conv.ask(speechOutput.speech);
conv.data.restaurantData.time = bookingTime;
} else {
say = `please provide a valid booking time.`;
conv.ask(say);
}
});
// people count intent
app.intent('peopleCount', (conv, params) => {
let peopleCounts = parseInt(params.count);
let restaurantName = 'Dominos pizza';
let restaurantAddress = 'San Francisco, ca';
let bookingDate = conv.data.restaurantData.date;
let bookingTime = conv.data.restaurantData.time;
const booking12HourTimeString = moment(bookingTime, ["HH:mm"]).format("hh:mm A");
let bookingDisplayDate = moment(bookingDate).format("DD MMM YYYY");
if (peopleCounts > 0) {
conv.ask(`OK You would like to create a table for ${restaurantName} in ${restaurantAddress} on ${bookingDisplayDate} at ${booking12HourTimeString} for ${peopleCounts} people`);
} else {
conv.ask(`Please add people more than zero`);
}
});
app.intent('customFallback', (conv, params) => {
conv.ask(`I couldn't understand. Can you say that again?`);
});
Your use case is not very clear, but as per my understanding what you really need is contexts or follow-up intents. Using these you can chain the intents.
If you still want to get previous intents name, i think you should store that in cache so that you can get that. There is no provision in dialogflow to get that.