Craft dynamic digital agent greetings that adapt to the time of day. Elevate user engagement with personalized messages, creating a seamless and responsive interaction experience. Explore smart strategies for automating greetings based on real-time considerations, making your digital agent's interactions more dynamic and effective.
Follow these simple steps to implement time-based greetings in your message:
Step 1: Create a MSG node
Start by creating a new MSG node in the Flow editor. This node will serve as the foundation for setting both your dynamic greeting and the digital agent's message content.
Need basics first? MESSAGE node
Step 2: Set a greeting variable
Within the MSG node, set a new variable named greeting to determine the appropriate greeting string based on the current time.
Greeting based on current hour
Try it for yourself and set the following code as a value for your greeting variable!
Example to copy
"Good moorning!" if current_time().hour > 7 and current_time().hour < 9 else "Good afternoon!" if current_time().hour > 12 and current_time().hour < 18 else "Good evening!" if current_time().hour > 18 or current_time().hour < 23 else "Hello!"
Here's what is being set:
If the current hour is greater than 7 and less than 9, set the greeting to "Good morning!"
If the current hour is greater than 12 and less than 18, set the greeting to "Good afternoon!"
If the current hour is greater than 18 or less than 23, set the greeting to "Good evening!"
If none of the above conditions are met, set the greeting to "Hello!"
Greeting based on current time
Try it for yourself and set the following code as a value for your greeting variable!
Example to copy
"Good morning!" if current_time().strftime("%H:%M:%S") > '"07:30:00"' and current_time().strftime("%H:%M:%S") < '"09:00:00"' else "Good evening" if current_time().strftime("%H:%M:%S") > '"18:59:59"' and current_time().strftime("%H:%M:%S") < '"22:30:00"' else "Hello!"
Here's what you've just set:
"Good morning!" is assigned if the current time is between "07:30:00" (7:30 AM) and "09:00:00" (9:00 AM).
"Good evening!" is assigned if the current time is between "18:59:59" (6:59:59 PM) and "22:30:00" (10:30 PM).
If none of the above conditions are met, "Hello!" is assigned as a default greeting.
These time ranges are based on the 24-hour format (HH:MM:SS), and you can adjust them according to your preferences or specific use case. The time ranges are inclusive of the start time and exclusive of the end time, meaning that a time exactly equal to "09:00:00" or "22:30:00" would fall into the next greeting category.
Greeting based on current day in a week
Try it for yourself and set the following code as a value for your greeting variable!
Example to copy
"Hi. Mondays, uh?" if current_time().weekday() == 0 else "Taco Tuesday!" if current_time().weekday() == 1 else "Wonderful Wednesday!" if current_time().weekday() == 2 else "Terrific Thursday" if current_time().weekday() == 3 else "Finally Friday!" if current_time().weekday() == 4 else "Hello!"
Here's a breakdown:
current_time().weekday() returns the current day of the week as an integer (Monday is 0, Tuesday is 1, ..., Sunday is 6).
The conditional expression uses a series of if and else statements to check the current day of the week and set a specific greeting accordingly.
If today is Monday (0), the greeting is "Hi. Mondays, uh?"
If today is Tuesday (1), the greeting is "Taco Tuesday!"
If today is Wednesday (2), the greeting is "Wonderful Wednesday!"
If today is Thursday (3), the greeting is "Terrific Thursday"
If today is Friday (4), the greeting is "Finally Friday!"
For any other day, the default greeting is "Hello!"
Step 3: Use the variable in the message content
In your digital agent's message content, incorporate the variable to dynamically display the appropriate greeting. Reference the variable you set in step 2 (in this example, "greeting") within the message content.
Feel free to change hours, add more conditions or craft the copywriting of the greeting string to your preference.
Feel free to add conditions, adjust time ranges and edit copywriting of the greeting strings to your liking!
This code provides a fun and varied greeting based on the day of the week. Adjust the greetings as needed for your specific use case.