Skip to main content

Tutorial: Weather Bot

Build a bot that fetches weather data from an external API.


What We're Building

A bot that:

  1. Asks for a city name
  2. Fetches weather from an API
  3. Displays the current weather

Prerequisites

You'll need a free API key from a weather service:

Store your API key in a global variable: global.weather_api_key


Step 1: Weather Command

  1. Add a Command Trigger for /weather
  2. Add an Ask Question node:
    • Question: 🌍 What city would you like weather for?
    • Save to: flow.city

Step 2: Show "Fetching"

  1. Add a Send Chat Action node
    • Action: typing

This shows "typing..." while we fetch data.


Step 3: Call the Weather API

  1. Add an HTTP Request node
  2. 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 = response main.temp
  • flow.description = response weather.0.description
  • flow.humidity = response main.humidity

Step 5: Display Weather

  1. 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:

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