examples/amazon-lex-with-lambda.js
function buildOptions(slot, appointmentType, date, bookingMap) {
    const dayStrings = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
    if (slot === 'AppointmentType') {
        return [
            { text: 'cleaning (30 min)', value: 'cleaning' },
            { text: 'root canal (60 min)', value: 'root canal' },
            { text: 'whitening (30 min)', value: 'whitening' },
        ];
    } else if (slot === 'Date') {
        // Return the next five weekdays.
        const options = [];
        const potentialDate = new Date();
        while (options.length < 5) {
            potentialDate.setDate(potentialDate.getDate() + 1);
            if (potentialDate.getDay() > 0 && potentialDate.getDay() < 6) {
                options.push({ text: `${potentialDate.getMonth() + 1}-${potentialDate.getDate()} (${dayStrings[potentialDate.getDay()]})`,
                    value: potentialDate.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }) });
            }
        }
        return options;
    } else if (slot === 'Time') {
        // Return the availabilities on the given date.
        if (!appointmentType || !date) {
            return null;
        }
        let availabilities = bookingMap[`${date}`];
        if (!availabilities) {
            return null;
        }
        availabilities = getAvailabilitiesForDuration(getDuration(appointmentType), availabilities);
        if (availabilities.length === 0) {
            return null;
        }
        const options = [];
        for (let i = 0; i < Math.min(availabilities.length, 5); i++) {
            options.push({ text: buildTimeOutputString(availabilities[i]), value: buildTimeOutputString(availabilities[i]) });
        }
        return options;
    }
}
function buildOptions(slot, appointmentType, date, bookingMap) {
    const dayStrings = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
    if (slot === 'AppointmentType') {
        return [
            { text: 'cleaning (30 min)', value: 'cleaning' },
            { text: 'root canal (60 min)', value: 'root canal' },
            { text: 'whitening (30 min)', value: 'whitening' },
        ];
    } else if (slot === 'Date') {
        // Return the next five weekdays.
        const options = [];
        const potentialDate = new Date();
        while (options.length < 5) {
            potentialDate.setDate(potentialDate.getDate() + 1);
            if (potentialDate.getDay() > 0 && potentialDate.getDay() < 6) {
                options.push({ text: `${potentialDate.getMonth() + 1}-${potentialDate.getDate()} (${dayStrings[potentialDate.getDay()]})`,
                    value: potentialDate.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }) });
            }
        }
        return options;
    } else if (slot === 'Time') {
        // Return the availabilities on the given date.
        if (!appointmentType || !date) {
            return null;
        }
        let availabilities = bookingMap[`${date}`];
        if (!availabilities) {
            return null;
        }
        availabilities = getAvailabilitiesForDuration(getDuration(appointmentType), availabilities);
        if (availabilities.length === 0) {
            return null;
        }
        const options = [];
        for (let i = 0; i < Math.min(availabilities.length, 5); i++) {
            options.push({ text: buildTimeOutputString(availabilities[i]), value: buildTimeOutputString(availabilities[i]) });
        }
        return options;
    }
}
function buildOptions ( slot , appointmentType , date , bookingMap ) { const dayStrings = [ 'Sun' , 'Mon' , 'Tue' , 'Wed' , 'Thu' , 'Fri' , 'Sat' ] ; if ( slot === 'AppointmentType' ) { return [ { text : 'cleaning (30 min)' , value : 'cleaning' } , { text : 'root canal (60 min)' , value : 'root canal' } , { text : 'whitening (30 min)' , value : 'whitening' } , ] ; } else if ( slot === 'Date' ) { // Return the next five weekdays. const options = [ ] ; const potentialDate = new Date ( ) ; while ( options . length < 5 ) { potentialDate . setDate ( potentialDate . getDate ( ) + 1 ) ; if ( potentialDate . getDay ( ) > 0 && potentialDate . getDay ( ) < 6 ) { options . push ( { text : ` ${ potentialDate . getMonth ( ) + 1 } ${ potentialDate . getDate ( ) } ${ dayStrings [ potentialDate . getDay ( ) ] } ` , value : potentialDate . toLocaleDateString ( 'en-US' , { year : 'numeric' , month : 'long' , day : 'numeric' } ) } ) ; } } return options ; } else if ( slot === 'Time' ) { // Return the availabilities on the given date. if ( ! appointmentType || ! date ) { return null ; } let availabilities = bookingMap [ ` ${ date } ` ] ; if ( ! availabilities ) { return null ; } availabilities = getAvailabilitiesForDuration ( getDuration ( appointmentType ) , availabilities ) ; if ( availabilities . length === 0 ) { return null ; } const options = [ ] ; for ( let i = 0 ; i < Math . min ( availabilities . length , 5 ) ; i ++ ) { options . push ( { text : buildTimeOutputString ( availabilities [ i ] ) , value : buildTimeOutputString ( availabilities [ i ] ) } ) ; } return options ; } }
Build a list of potential options for a given slot, to be used in responseCard generation.
Build a list of potential options for a given slot to be used in responseCard generation .