Quick overview
This workflow collects train trip details via an n8n Form, predicts station crowding and queue times with a rule-based algorithm, generates a short advisory with OpenAI, then emails a color-coded HTML alert via Gmail and logs each prediction to Google Sheets.
How it works
- Receives a submission from an n8n Form containing the traveler’s train, station, date/time, class, e-ticket status, passenger count, and email.
- Calculates a crowd score, alert level, queue-time breakdown (platform, ticket counter, security, walking), and an optimal station arrival time using an in-workflow rules engine.
- Sends the prediction context to OpenAI Chat Completions (gpt-4o-mini) to generate a plain-text, under-120-word travel advisory.
- Combines the advisory with the prediction results and assigns alert colors and text based on the computed alert level.
- Builds a color-coded HTML email summarizing the recommended arrival time and queue breakdown.
- Appends the prediction details to a Google Sheets tab and sends the HTML alert email to the traveler via Gmail.
Setup
- Add an OpenAI API credential for the HTTP request to
https://api.openai.com/v1/chat/completions.
- Connect Google Sheets OAuth2 and replace
YOUR_QUEUE_LOG_SHEET_ID with your spreadsheet ID, ensuring a tab named Predictions exists with matching column headers.
- Connect Gmail OAuth2 so the workflow can send emails to the address collected in the form.
- Activate the workflow and share the Form URL (
railway-queue-predictor) with travelers who will submit requests.