# Setting time-based greetings

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.

<figure><img src="https://4261467870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6iQTvxgRZRwPS1NgIGEb%2Fuploads%2FdPo8mbGFR1sFxH4Q6JHY%2Fgreeting.gif?alt=media&#x26;token=d6355991-ac03-4598-b393-e1eddb4b67e6" alt=""><figcaption></figcaption></figure>

***

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.\
\ <mark style="color:blue;">Need basics first?</mark> [message-node](https://docs.borndigital.ai/digital-agent/conversation-flow/nodes-explained/message-node "mention")

## 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.&#x20;

<details>

<summary>Greeting based on current hour</summary>

Try it for yourself and set the following code as a value for your greeting variable!

{% code title="Example to copy" overflow="wrap" %}

```python
"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!"
```

{% endcode %}

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!"

:pencil2: **Feel free to change hours, add more conditions or craft the copywriting of the greeting string to your preference.**

</details>

<details>

<summary>Greeting based on current time</summary>

Try it for yourself and set the following code as a value for your greeting variable!

{% code title="Example to copy" overflow="wrap" %}

```python
"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!"
```

{% endcode %}

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.

:pencil2: **Feel free to add conditions, adjust time ranges and edit copywriting of the greeting strings to your liking!**

</details>

<details>

<summary>Greeting based on current day in a week</summary>

Try it for yourself and set the following code as a value for your greeting variable!

{% code title="Example to copy" overflow="wrap" %}

```python
"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!"
```

{% endcode %}

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!"

:pencil2: **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.**

</details>

<figure><img src="https://4261467870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6iQTvxgRZRwPS1NgIGEb%2Fuploads%2FCgekAaAUrJw0hdb35Bnm%2Fchrome-capture-2024-2-21%20(1).gif?alt=media&#x26;token=7392f9b3-4318-4849-8e5a-de805a7c2831" alt=""><figcaption><p>It takes just a second!</p></figcaption></figure>

## 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.

<figure><img src="https://4261467870-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6iQTvxgRZRwPS1NgIGEb%2Fuploads%2FkWCY4hmuTcvina9cPfJY%2Fchrome-capture-2024-2-21.gif?alt=media&#x26;token=bc157a34-e233-4958-bbd6-92189c165630" alt=""><figcaption><p>Aaaand, done! Next, set a target node and continue to build your flow.</p></figcaption></figure>
