Conversation Design Using Local Time and Weather
# 📖tutorials
Here in Britain we love to moan about the weather in most daily conversations we have with each other, its just what we do. haha! So i thought why not build that into the bot to make conversations feel more natural. I guess you could also use this for say a bot that tells the weather or I am sure someone will think of some more use cases. You can completely change what you want the bot to say to make it personalised for your use case.
Here's a breakdown of what each part of the code does: 1. API Key and Location Information: - An API key (
) is provided for accessing the OpenWeatherMap API. - The city (
) and country (
) are specified as "Moscow" and "Russia," respectively. 2. Current Time: - The Luxon library is used to get the current time in the local timezone. - The
variable holds the current time in a simple time format (e.g., "9:30 AM"). 3. Fetching Weather Data: - The weather data is fetched from the OpenWeatherMap API using Axios. - The
is constructed with the city, country, API key, and units as metric. - The
holds the response from the API. - The current temperature is extracted from the API response using Lodash's
function. 4. Getting Weather Conditions and Cloud Coverage: - The weather conditions (e.g., "Clouds," "Rain") are extracted from the API response. - The cloud coverage percentage is also extracted from the API response.
5. Time-based Greetings: - Based on the current hour, a suitable greeting message is assigned to the
variable. - Different greetings are chosen for different time ranges (morning, afternoon, evening, etc.). 6. Constructing Welcome Message: - The
is constructed by combining the
with other messages. 7. Checking Cloud Conditions: - The cloud coverage percentage is used to add information about the sky conditions to the
. - Different cloud coverage ranges trigger different messages. 8. Checking for Rain: - If the weather conditions include "Rain," the message is appended to indicate rain. 9. Checking Temperature Ranges: - Depending on the temperature range, the message about the temperature is added. - Different temperature ranges lead to different comments. 10. Finalizing Welcome Message: - The temperature information and city name are added to the
. - The
is then stored in a variable called
to use the weather function you will need an API key with - you can get 1000 free api calls per day. here is the code below: I had to upload a file as it ran over my character limit per message. I have marked out where to change the code with capital letters.
Oh wowwwww 💖 !!!!!! Amazing work. Thanks for sharing with the community @freezing-carpenter-9818 !
I have problem with getting user's location and local time to use for some process, but I always get the Botpress information ( Auburn Virginia). I want to use to get the location.
@early-train-33247 can you please help here!
@lemon-rocket-12038 your bot's code always run on Botpress Servers, so we don't have access to your user IP.
The workarounds: - Creating a website and adding a script that makes a request to ipapi and then passes that information to the Webchat which will make it available for your bot in the Studio. Check out this docs and this tutorial

- Asking your user for their timezone and language. Consider that sometimes the IP doesn't match the user location 😉
Hope that helps
Appreciate it Gui. Thanks
Thank you @early-train-33247 .