How do i greet user based on the time?
# 🤝help
m
How do i use the AI task card or other card to greet user based on time? I would like the output be like "Good morning/good afternoon, name" based on the time the user uses the chatbot. Thank you so much.
b
actually this is a really interesting question, I'm not sure I've seen this done before? hmm
m
@bumpy-butcher-41910 thanks for the reply. Would appreciate if any update for this feature.
b
cc @acceptable-gold-88171
g
Hey! Try using this code in an execute code card at the start of your flow: > // Force to get the current time in the Eastern Standard Time (EST) time zone (Montreal's time zone) > const currentDate = new Date().toLocaleString('en-US', { timeZone: 'America/Montreal' }) > // Extract the hours from the current time > const currentHour = new Date(currentDate).getHours() > > if (currentHour >= 6 && currentHour < 12) { > workflow.currentGreet = 'Good morning' > } else if (currentHour >= 12 && currentHour < 18) { > workflow.currentGreet = 'Good afternoon' > } else { > workflow.currentGreet = 'Good evening' > } You can change timezone based on the one you prefer, and you'll also need to create a string variable called workflow.currentGreet. You can also customize the messages sent to the user in the second part of that code 🙂
m
thank you so much !
r
This would be good for a local business with a local clientelle, but otherwise might just be confusing or awkward. I do like the idea though, to make it more personal, as long as there is not a time zone issue.
e
Would make it more personal definitely, but if you can’t find a way to do it ‘Good day!’ always works.
m
thank you !
139 Views