我有2个intentingbookingDate和bookingTime,用户在alexa中说“ now”或“ now now”,所以首先调用该intent,因为我为“ AMAZON.DATE”插槽类型添加了BookingDate Intent和为“ AMAZON.TIME”添加了bookingTime Intent插槽类型。
相同的“现在”或“立即”插槽类型“ AMAZON.DATE”和“ AMAZON.TIME”的插槽类型,因此如何确定alexa首先需要调用哪种意图。
// Lambda Function code for Alexa.
const Alexa = require("ask-sdk");
const moment = require('moment-timezone');
moment.tz.setDefault("Asia/Kolkata");
// 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);
}
})