Quick overview
This workflow ingests crowd density and incident reports via webhook or a 5‑minute schedule, assesses risk with Python thresholds, uses OpenAI to generate a short rerouting recommendation, then sends an SMS via Twilio and logs each alert to a Google Sheets heatmap tracker.
How it works
- Triggers when a POST request hits the n8n webhook or every 5 minutes on a schedule.
- Normalizes incoming fields (location, crowd density, safety score, incidents, traveler contact, and preferences) and fills in defaults when values are missing.
- Calculates risk level in Python based on configurable thresholds for high density, incident count, and low safety score.
- Continues only for high-risk items and pauses briefly before the AI call.
- Uses OpenAI (via an AI agent) to generate a personalized rerouting suggestion under 150 words from the live data and traveler preferences.
- Sends the rerouting alert to the traveler via Twilio SMS and appends the alert details and reroute text to a Google Sheets log via the Google Sheets API.
Setup
- Add an OpenAI API credential and select the model in the OpenAI Chat Model connection.
- Configure Twilio credentials (Account SID and Auth Token), replace YOUR_TWILIO_ACCOUNT_SID in the Twilio API URL, and set an SMS-capable Twilio “From” number.
- Enable Google Sheets API access, replace YOUR_HEATMAP_SHEET_ID, and ensure Sheet1 exists with columns that match the appended values (date, risk area, location, risk level, density, status, timestamp, reroute text).
- If using the webhook trigger, copy the webhook URL from n8n and configure your crowd/incident data source to POST the expected fields (location, crowdDensity, safetyScore, optional incidents and travelerContact).