Tutorial: Weather Bot
Build a bot that fetches weather data from an external API.
What We're Building
A bot that:
- Asks for a city name
- Fetches weather from an API
- Displays the current weather
Prerequisites
You'll need a free API key from a weather service:
- OpenWeatherMap (free tier)
- WeatherAPI (free tier)
Store your API key in a global variable: global.weather_api_key
Step 1: Weather Command
- Add a Command Trigger for
/weather - Add an Ask Question node:
- Question:
🌍 What city would you like weather for? - Save to:
flow.city
- Question:
Step 2: Show "Fetching"
- Add a Send Chat Action node
- Action:
typing
- Action:
This shows "typing..." while we fetch data.
Step 3: Call the Weather API
- Add an HTTP Request node
- Configure:
- Method: GET
- URL:
https://api.openweathermap.org/data/2.5/weather?q={{flow.city}}&appid={{global.weather_api_key}}&units=metric
Step 4: Parse the Response
The API returns JSON like:
{
"main": {
"temp": 22,
"humidity": 65
},
"weather": [
{"description": "partly cloudy"}
],
"name": "London"
}
Use Path Get nodes or store in flow variables:
flow.temp= responsemain.tempflow.description= responseweather.0.descriptionflow.humidity= responsemain.humidity
Step 5: Display Weather
- Add a Send Message node:
🌤️ Weather in {{flow.city}}
🌡️ Temperature: {{flow.temp}}°C
💧 Humidity: {{flow.humidity}}%
☁️ Conditions: {{flow.description}}
Updated just now!
Step 6: Handle Errors
What if the city isn't found?
Error message:
😕 Sorry, I couldn't find weather for "{{flow.city}}".
Please check the spelling and try again.
Complete Flow
Enhancements
Weather Icons
Map conditions to emojis:
| Condition | Emoji |
|---|---|
| clear | ☀️ |
| clouds | ☁️ |
| rain | 🌧️ |
| snow | ❄️ |
| thunderstorm | ⛈️ |
Forecast
Add a 5-day forecast option:
[📅 5-Day Forecast] [🕐 Right now]
Save Default City
Remember the user's city:
💾 Save {{flow.city}} as your default city?
[Yes] [No]
Then offer quick access:
/weather — Check your saved city's weather
Location Sharing
Accept location instead of typing:
📍 You can also share your location!
[📍 Send My Location]
Tips
Cache Results
Weather doesn't change by the second. Cache results for a few minutes to reduce API calls.
Rate Limiting
Free API tiers have limits. Track usage and show friendly messages if exceeded.
Units
Offer Celsius/Fahrenheit choice:
[🌡️ Celsius] [🌡️ Fahrenheit]
Next Steps
Congratulations! You've learned how to integrate external APIs.
- Best Practices → — Organize your bot
- FAQ → — Common questions