Creating a dynamic time using JavaScript

(victor) #1

Hello!!!.

I felt the community could benefit from this code.

if you want to change the dynamics of your time inorder for the bot to understand the time of the day and respond accordingly. Find below;

let timeOfDay = new Date();

if (timeOfDay.getHours() >= 0 && timeOfDay.getHours() <= 11) {
return resolve(“Good morning {{greetingss.user_first_name}}”)
} else if (timeOfDay.getHours() >= 12 && timeOfDay.getHours() <= 16) {
return resolve(“Good afternoon {{greetingss.user_first_name}}”)
} else {
return resolve(“Good evening {{greetingss.user_first_name}}”)
}

(Nathan Stults) #2

Very nice, thanks for sharing!