Last active
July 11, 2018 07:32
-
-
Save adicuco/03e3607393b30d4859d2aae63f4a2a35 to your computer and use it in GitHub Desktop.
Dialogflow Restaurant Chatbot Tutorial | 5 (https://chatbotslife.com/dialogflow-restaurant-bot-tutorial-5-47b8a3d9a30c)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function createBooking(agent) { | |
| let guests = agent.parameters.guests; | |
| let time = new Date(agent.parameters.time); | |
| let date = new Date(agent.parameters.date); | |
| let bookingDate = new Date(date); | |
| bookingDate.setHours(time.getHours()); | |
| bookingDate.setMinutes(time.getMinutes()); | |
| let now = new Date(); | |
| if (guests < 1){ | |
| agent.add('You need to reserve a table for at least one person. Please try again!'); | |
| } else if (bookingDate < now){ | |
| agent.add(`You can't make a reservation in the past. Please try again!`); | |
| } else if (bookingDate.getFullYear() > now.getFullYear()) { | |
| agent.add(`You can't make a reservation for ${bookingDate.getFullYear()} yet. Please choose a date in ${now.getFullYear()}.`); | |
| } else { | |
| let timezone = parseInt(agent.parameters.time.toString().slice(19,22)); | |
| bookingDate.setHours(bookingDate.getHours() + timezone); | |
| agent.add(`You have successfully booked a table for ${guests} guests on ${bookingDate.toString().slice(0,21)}`); | |
| agent.add('See you at the restaurant!'); | |
| agent.add('Have a wonderful day!'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment