A Slack bot that provides weather forecasts using the Open-Meteo API and OpenWeatherMap's geocoding service.
- Current weather conditions
- 4-day forecast
- Temperature and precipitation charts
- Location name lookup from coordinates
- Support for both space and comma-separated coordinates
- Direct message support
- Channel mention support
- Interactive help command
- Create a new Slack app at https://api.slack.com/apps
- Under "Basic Information", scroll down to "Display Information" and set:
- App Name
- App Icon
- App Description
- Under "Basic Information", scroll down to "App-Level Tokens" and:
- Click "Generate Token and Scopes"
- Name it something like "weather-bot-token"
- Add the
connections:writescope - Copy the generated token
- Under "OAuth & Permissions", add the following bot scopes:
commandschat:writeapp_mentions:readim:historychannels:historygroups:historyim:write(for direct messages)chat:write.public(for channel messages)
- Under "Event Subscriptions":
- Toggle "Enable Events" to On
- Add your Request URL:
https://your-worker-url.workers.dev/slack/events - Subscribe to the following bot events:
message.im(for direct messages)message.channels(for public channels)message.groups(for private channels)
- Under "Interactivity & Shortcuts":
- Toggle "Interactivity" to On
- Add your Request URL:
https://your-worker-url.workers.dev/slack/events
- Under "Slash Commands":
- Click "Create New Command"
- Command:
/weather - Request URL:
https://your-worker-url.workers.dev/slack/events - Short Description: "Get weather forecast for coordinates"
- Usage Hint: "[latitude] [longitude]"
- Install the app to your workspace
- Copy the signing secret and bot token
- Note your bot's user ID (you can find this in the "Basic Information" section of your app settings)
The following secrets need to be set using Wrangler:
# Set Slack signing secret
wrangler secret put SLACK_SIGNING_SECRET
# Set OpenWeatherMap API key for geocoding
wrangler secret put OPENWEATHER_API_KEY
# Set Slack bot user ID
wrangler secret put SLACK_BOT_USER_IDYou can get an OpenWeatherMap API key by:
- Creating an account at https://openweathermap.org/
- Going to your account page
- Generating a new API key
- Install dependencies:
npm install- Start the development server:
npm run dev- Deploy to Cloudflare Workers:
npm run deployYou can interact with the bot in three ways:
- Use the
/weathercommand with coordinates:
/weather 37.7749 -122.4194
or
/weather 37.7749,-122.4194
- Direct message the bot with coordinates:
37.7749 -122.4194
or
37.7749,-122.4194
- Mention the bot in a channel with coordinates:
@weatherbot 37.7749 -122.4194
The bot will respond with:
- Current weather conditions
- 4-day forecast
- Temperature and precipitation charts
- Location name (if available)
You can also type help in a direct message or after mentioning the bot to see a list of available commands and usage instructions.
If the bot isn't responding to mentions or direct messages:
- Make sure you've added all the required scopes
- Verify that the bot has been invited to the channel where you're trying to mention it
- Check that the bot's user ID is correctly set in the environment variables
- Ensure all the event subscriptions are properly configured
- Try reinstalling the app to your workspace after making any changes to scopes or events
- Integration with Summits on the Air (SOTA) locations
- Additional weather data points
- Weather alerts and notifications
- Customizable units (metric/imperial)
- Weather alerts for specific locations