A weather notification Slackbot designed for delivery and logistics operations. It fetches and sends real-time weather updates for three regions — Klang Valley (Malaysia), Singapore, and Hong Kong — to a designated Slack channel at scheduled intervals using cron jobs. The bot also includes an interactive map feature for visualizing weather updates based on coordinates.
- Features
- Tech Stack
- Project Structure
- Prerequisites
- Installation
- Configuration
- Usage
- API Endpoints
- Cron Schedule
- Deployment
- Future Development
- Contributing
- Contact
- Multi-region weather data — Fetches real-time weather from official government APIs:
- 🇲🇾 Klang Valley: MET Malaysia via Data.gov.my
- 🇸🇬 Singapore: 2-hour forecast via Data.gov.sg
- 🇭🇰 Hong Kong: Hong Kong Observatory API
- Automated Slack notifications — Sends weather updates to a Slack channel on a cron schedule
- Peak hour alerts — More frequent updates during peak delivery hours (10 AM–11:30 AM, 5 PM–6:30 PM)
- Interactive Slack messages — Buttons linking directly to weather maps
- 5-minute data caching — Minimizes redundant API calls
- Interactive map interface — View weather on a map using lat/lng/zoom parameters
- Manual trigger endpoint — Trigger notifications on demand for testing
| Technology | Purpose |
|---|---|
| Node.js | Backend runtime |
| Express | Web server and routing |
| Axios | HTTP requests to external APIs |
| node-cron | Scheduled weather notifications |
| @slack/web-api | Slack bot integration |
| dotenv | Environment variable management |
| Puppeteer | Headless browser for map screenshots |
| Chart.js | Weather data visualization |
| Imgur | Image hosting for map snapshots |
| OpenAI | AI-powered weather summaries |
| Jest + Sinon + Supertest | Testing framework |
SlackBot-Project/
├── backend/
│ ├── index.js # Entry point — starts server + cron
│ ├── app.js # Express setup, middleware, routes
│ ├── cron-schedule.js # Cron job definitions
│ ├── index.html # Homepage
│ ├── package.json
│ ├── .env.example # Environment variable template
│ ├── config/
│ │ └── locations.js # Static location/area data
│ ├── middleware/
│ │ ├── rateLimiter.js # Express rate limiter
│ │ └── errorHandler.js # Global error handler
│ ├── services/
│ │ ├── weatherService.js # Weather API fetch + cache
│ │ ├── trafficService.js # SG & HK traffic fetch
│ │ └── slackService.js # Slack message build + send
│ ├── controllers/
│ │ ├── weatherController.js
│ │ ├── trafficController.js
│ │ └── slackController.js
│ ├── routes/
│ │ ├── api.js # /api/* routes
│ │ └── pages.js # /, /map, /send-notification
│ ├── public/ # Static assets
│ └── icon/ # Icon assets
├── render.yaml # Render deployment config
└── README.md
- Node.js v18+
- A Slack workspace with bot permissions
- Slack Bot Token and Channel ID
- (Optional) LTA Account Key for additional transport data
-
Clone the repository:
git clone https://github.com/timothylee58/SlackBot-Project.git cd SlackBot-Project/backend -
Install dependencies:
npm install
-
Set up environment variables (see Configuration)
-
Start the server:
npm start
Copy .env.example to .env inside the backend/ directory and fill in your values:
cp backend/.env.example backend/.envSLACK_BOT_TOKEN=xoxb-your-slack-bot-token
SLACK_CHANNEL_ID=your-slack-channel-id
LTA_ACCOUNT_KEY=your-lta-account-key
BASE_URL=https://your-app.onrender.com- Go to api.slack.com/apps → Create New App
- Under OAuth & Permissions, add these Bot Token Scopes:
chat:writefiles:write
- Install the app to your workspace and copy the Bot User OAuth Token
- Invite the bot to your channel:
/invite @your-bot-name - Copy the Channel ID from the channel settings
View an interactive weather map in your browser:
http://localhost:3000/map?lat=3.1390&lng=101.6869&zoom=10
Parameters:
lat— Latitude of the locationlng— Longitude of the locationzoom— Map zoom level (1–18)
Example coordinates:
| Region | lat | lng | zoom |
|---|---|---|---|
| Klang Valley | 3.1390 | 101.6869 | 10 |
| Singapore | 1.3521 | 103.8198 | 11 |
| Hong Kong | 22.3193 | 114.1694 | 11 |
Trigger a weather notification manually (useful for testing):
GET http://localhost:3000/send-notification
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Serves the homepage (index.html) |
| GET | /map?lat=&lng=&zoom= |
Interactive map view with coordinates |
| GET | /send-notification |
Manually trigger a Slack weather notification |
The bot sends automated weather updates on the following schedule:
| Frequency | Time | Reason |
|---|---|---|
| Every 2 hours | 8 AM – 10 PM | Regular updates throughout the day |
| Every 30 minutes | 10 AM – 11:30 AM | Morning peak hour |
| Every 30 minutes | 5 PM – 6:30 PM | Evening peak hour |
This project is configured for deployment on Render via render.yaml:
- Runtime: Node.js
- Region: Singapore
- Build command:
npm install - Start command:
node index.js - Auto-deploy: Enabled on push to main branch
Set the following environment variables in your Render dashboard:
SLACK_BOT_TOKENSLACK_CHANNEL_IDLTA_ACCOUNT_KEYBASE_URL
Console logs are printed when:
- Weather data is fetched from APIs
- Notifications are sent to Slack
- Cron jobs are triggered
Run with Node.js debug mode for more verbose output:
DEBUG=* node index.js- More locations — Extend support by adding entries to the
locationsobject inindex.js. Each location needs:name, weather API endpoint,coordinates, andzoomlevel. - Severity alerts — Push urgent notifications for extreme weather conditions
- Dashboard UI — Web dashboard for viewing historical weather notifications
- Multi-channel support — Route different regions to different Slack channels
- Fork the repository
- Create a new branch:
git checkout -b feature/your-feature - Make your changes
- Commit:
git commit -m 'Add some feature' - Push:
git push origin feature/your-feature - Open a Pull Request
For issues, questions, or suggestions:
- GitHub: timothylee58
- LinkedIn: Timothy Lee