
n8n Automation Projectπ
- Jean-Christophe Miler
- N8n , Project
- January 26, 2026
Table of Contents
Belgian Train Departure Agent: An n8n Automation Project
Overview
This project showcases a powerful n8n workflow that creates an intelligent Belgian train departure agent. The system integrates with the iRail API to provide real-time train departure information through Telegram bot interactions and scheduled checks, demonstrating the capabilities of low-code automation for real-world transportation data.
Features
- Real-time Train Data: Fetches live departure information from Belgian railway stations via the iRail API
- Telegram Bot Integration: Users can query train departures through natural language messages
- Smart Station Matching: Intelligent fuzzy matching algorithm to find stations from user input
- Multiple Input Methods: Supports both webhook triggers and scheduled automated checks
- Rich Formatting: Displays departure information with platform details, delays, and status indicators
- Error Handling: Robust error handling for invalid station names or API failures
Architecture
The workflow consists of several key components working in harmony:
Core Components
- Webhook Trigger (
Webhook): Listens for POST requests at/train-departuresendpoint - Message Parser (
Code in JavaScript1): Extracts city and time information from natural language messages - Station Finder (
Find Station): Matches user input to official Belgian station names using fuzzy logic - API Integration (
Get Stations&Get Liveboard): Retrieves station data and live departure information - Response Formatter (
Code in JavaScript3): Formats departure data into user-friendly messages - Telegram Bot (
Send to Telegram): Delivers formatted results to users
Additional Features
- Schedule Trigger: Enables automated departure checks at specified intervals
- Chat Interface: Provides an interactive chat-based interface for users
- HTTP Request Nodes: Allow testing and integration with external systems
Technical Implementation
Natural Language Processing
The system uses sophisticated regex patterns to parse user messages:
const patterns = [
/departures?\s+from\s+([^\s]+)\s+at\s+(\d{1,2}:?\d{0,2})/i,
/([^\s]+)\s+(\d{1,2}:?\d{0,2})/,
/([^\s]+)\s+at\s+(\d{1,2}:?\d{0,2})/i
];
Station Matching Algorithm
The fuzzy matching system scores stations based on:
- Perfect match: Exact name match (100 points)
- Close match: Partial name inclusion (80 points)
- Weak match: First three characters (40 points)
Response Formatting
The system displays up to 5 departures with rich formatting:
- Train numbers and destinations
- Departure times with delay information
- Platform numbers
- Real-time status (on time, delayed, or canceled)
API Integration
iRail API Endpoints
- Stations:
https://api.irail.be/stations/?format=json&lang=en - Liveboard:
https://api.irail.be/liveboard/?station={station}&format=json&lang=en
Data Processing
The workflow handles:
- Timestamp conversion from Unix timestamps to human-readable format
- Delay calculations (seconds to minutes)
- Vehicle ID cleanup (removes “BE.NMBS.” prefix)
- Cancellation status detection
Use Cases
For Commuters
- Quick departure checks before leaving home/office
- Real-time delay information
- Platform changes and service updates
For Travelers
- Tourist-friendly station name matching
- Multi-language support (English)
- Intuitive natural language queries
For Developers
- Example of n8n workflow design
- API integration patterns
- Error handling best practices
Configuration Requirements
Prerequisites
- n8n instance with webhook capabilities
- Telegram Bot API token
- Internet access to iRail API endpoints
Setup Steps
- Import the workflow JSON into n8n
- Configure Telegram bot credentials
- Set up webhook endpoint URL
- Test with sample requests
- Configure schedule triggers if needed
Example Interactions
User Message: “Charleroi” Bot Response:
π Departures: Charleroi-Central
1. π S614160
π 09:54
π Platform 10
π§ To: Jambes
β
On time
2. π S624260
π 09:55
π Platform 6
π§ To: Luttre
β
On time
3. π IC932
π 10:13
π Platform 9
π§ To: Lille Flandres
β
On time
4. π S614560
π 10:16
π Platform 1
π§ To: Jambes
β
On time
5. π IC3810
π 10:19
π Platform 7
π§ To: Herstal
β
On time
π
Requested for: now
π Updated: 9:53:26 AM
Benefits
- Automation: Reduces manual checking of train schedules
- Accessibility: Provides instant information through familiar chat interfaces
- Reliability: Handles errors gracefully with helpful messages
- Scalability: Can be extended to support multiple languages or regions
- Integration: Easy to integrate with other systems and workflows
Future Enhancements
Potential improvements could include:
- Multi-language support (English, French, Dutch…)
- Journey planning with route information
- Fare information and ticket booking integration
- Push notifications for favorite routes
- Historical delay analytics
Conclusion
This Belgian Train Departure Agent demonstrates how n8n can be used to create sophisticated, real-world automation solutions that integrate multiple APIs and provide genuine value to users. The combination of natural language processing, API integration, and messaging platform connectivity creates a seamless user experience while showcasing the power of low-code automation platforms.
The project serves as an excellent reference for developers looking to build similar transportation or data-driven automation workflows using n8n.