{
  "id": "LNYbmoLsxQQkUjWj",
  "name": "AI-Powered Women Safety Emergency Alert System",
  "tags": [],
  "nodes": [
    {
      "id": "7df819ef-3d27-43ab-a390-281eb39a5cd1",
      "name": "Sticky Note: Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -736,
        -576
      ],
      "parameters": {
        "width": 640,
        "height": 528,
        "content": "## \ud83d\udea8 Women's Safety Emergency Alert System\n\n### How it works\nWhen a safety app or button sends a POST request to this webhook, the workflow immediately extracts the person's name, phone number, and GPS coordinates, builds a Google Maps link, and passes everything through an AI agent that formats a clear, urgent alert message. That message is sent simultaneously to a Telegram group and logged to a Google Sheet for a permanent safety record.\n\nThis is designed for real-time personal safety \u2014 no delay, no manual steps. One trigger fires everything at once.\n\n### Setup steps\n1. **Webhook** \u2014 Copy the webhook URL and configure your safety app or frontend to POST `name`, `phone`, `lat`, and `lng` in the request body.\n2. **OpenAI** \u2014 Connect your OpenAI credential to the `OpenAI Chat Model` node. Uses `gpt-4o-mini` by default.\n3. **Telegram** \u2014 Connect a Telegram Bot credential and update the `chatId` in `Send Alert to Telegram Group` with your safety group's chat ID.\n4. **Google Sheets** \u2014 Connect your Google Sheets OAuth2 credential and update the `documentId` in `Log Incident to Google Sheets` with your own tracking spreadsheet ID.\n5. **Test** \u2014 Send a test POST payload with sample name, phone, lat, and lng values. Confirm the Telegram message arrives and a row is added to the sheet."
      },
      "typeVersion": 1
    },
    {
      "id": "1774a9ae-48df-48e6-8632-a8787402149d",
      "name": "Sticky Note: Webhook",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -64,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 348,
        "height": 380,
        "content": "## \ud83d\udce1 Webhook Trigger\nReceives an emergency POST request from a safety app or panic button. Expects `name`, `phone`, `lat`, and `lng` in the body. This is the only entry point \u2014 nothing runs until this fires."
      },
      "typeVersion": 1
    },
    {
      "id": "73d826e7-5251-4d19-9239-a22ca9144058",
      "name": "Sticky Note: Data Prep",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        304,
        16
      ],
      "parameters": {
        "color": 7,
        "width": 424,
        "height": 374,
        "content": "## \ud83d\uddfa\ufe0f Data Preparation\nExtracts the incoming fields, builds a Google Maps link from the GPS coordinates, and assembles a timestamped message (IST timezone). These two steps prepare all the data before the AI formats the final alert."
      },
      "typeVersion": 1
    },
    {
      "id": "d238ecb3-5fbc-492f-8758-917fe7219752",
      "name": "Sticky Note: AI Formatting",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        736,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 472,
        "height": 630,
        "content": "## \ud83e\udd16 AI Alert Formatting\nPasses the structured data to GPT-4o-mini, which formats a concise, emoji-tagged emergency alert. The prompt enforces a strict output format so the Telegram message is always readable at a glance \u2014 no filler, no variation."
      },
      "typeVersion": 1
    },
    {
      "id": "251ec537-0572-4c28-b2c9-6e19acb6f1a9",
      "name": "Sticky Note: Dispatch & Logging",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1216,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 428,
        "height": 790,
        "content": "## \ud83d\udcec Alert Dispatch & Logging\nThe formatted alert fires to both destinations simultaneously: a Telegram group for immediate human response, and a Google Sheet for a permanent incident record with name, phone, location, and timestamp."
      },
      "typeVersion": 1
    },
    {
      "id": "38fc1764-6dbc-451b-8ab1-91d270e93437",
      "name": "Sticky Note: Security",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1744,
        320
      ],
      "parameters": {
        "color": 3,
        "width": 308,
        "height": 194,
        "content": "## \ud83d\udd10 Credentials & Security\nUse OAuth2 for Google Sheets. Store Telegram and OpenAI keys as named n8n credentials \u2014 never paste tokens directly into nodes. Replace all sheet and chat IDs before sharing this template."
      },
      "typeVersion": 1
    },
    {
      "id": "641e795b-b72d-4ec6-8064-c5e0f9217602",
      "name": "Receive Emergency Alert",
      "type": "n8n-nodes-base.webhook",
      "position": [
        80,
        208
      ],
      "parameters": {
        "path": "emergency-alert",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 1
    },
    {
      "id": "0297c8d3-f1ee-4994-86ba-4a0ff17decd7",
      "name": "Generate Maps Link",
      "type": "n8n-nodes-base.function",
      "position": [
        368,
        208
      ],
      "parameters": {
        "functionCode": "const body = $input.first().json.body || $input.first().json;\n\nconst name = body.name || 'Unknown';\nconst phone = body.phone || 'Unknown';\nconst lat = body.lat || '0';\nconst lng = body.lng || '0';\n\nconst mapsLink = `https://www.google.com/maps?q=${lat},${lng}`;\n\nreturn [{\n  json: {\n    name,\n    phone,\n    lat,\n    lng,\n    mapsLink\n  }\n}];"
      },
      "typeVersion": 1
    },
    {
      "id": "c1056bb8-f60d-4c3e-bded-0a0003e1776d",
      "name": "Build Timestamped Message",
      "type": "n8n-nodes-base.function",
      "position": [
        608,
        208
      ],
      "parameters": {
        "functionCode": "const data = $input.first().json;\n\nconst now = new Date();\nconst timestamp = now.toLocaleString('en-IN', {\n  timeZone: 'Asia/Kolkata',\n  dateStyle: 'full',\n  timeStyle: 'long'\n});\n\nconst message = `\ud83d\udea8 EMERGENCY ALERT \ud83d\udea8\\n\\nName: ${data.name}\\nPhone: ${data.phone}\\n\\n\u26a0\ufe0f I feel unsafe. Please help immediately.\\n\\n\ud83d\udccd Live Location:\\n${data.mapsLink}\\n\\n\u23f0 Time: ${timestamp}`;\n\nreturn [{\n  json: {\n    ...data,\n    message,\n    timestamp\n  }\n}];"
      },
      "typeVersion": 1
    },
    {
      "id": "a04b3537-464e-4d31-88d0-10b4ab4ea9f1",
      "name": "AI Agent: Format Emergency Alert",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        912,
        208
      ],
      "parameters": {
        "text": "=You are an assistant for a Women Safety Emergency Alert System.\n\nYour task is to generate a clear, urgent, and well-formatted emergency alert message.\n\n---\n\n## INPUT DATA\n\nName: {{ $json.name }}\nPhone: {{ $json.phone }}\nLatitude: {{ $json.lat }}\nLongitude: {{ $json.lng }}\nLocation Link: {{ $json.mapsLink }}\nTime: {{ $json.timestamp }}\n\n---\n\n## INSTRUCTIONS\n\n* The message must sound **urgent but clear**\n* Keep it **short and easy to read**\n* Add emojis for visibility\n* Make sure the location is clearly visible\n* Do NOT include unnecessary explanation\n\n---\n\n## OUTPUT FORMAT\n\n\ud83d\udea8 EMERGENCY ALERT \ud83d\udea8\n\n\ud83d\udc64 Name: [Name]\n\ud83d\udcde Phone: [Phone]\n\n\u26a0\ufe0f I feel unsafe. Please help immediately.\n\n\ud83d\udccd Live Location:\n[Google Maps Link]\n\n\u23f0 Time: [Timestamp]\n\n---\n\n## IMPORTANT\n\n* Always return the formatted message\n* Do NOT return \"IGNORE\"\n* Do NOT add extra text outside the format\n",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 3
    },
    {
      "id": "d838e1a4-1cdb-4f69-8215-611c5699fe80",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        848,
        432
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "d82e5023-5f3d-4a66-bf74-09afff500adc",
      "name": "Send Alert to Telegram Group",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1424,
        48
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "YOUR_TELEGRAM_CHAT_ID",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "02d8f456-0d3a-4f5b-9d82-1c224fef2649",
      "name": "Log Incident to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1424,
        320
      ],
      "parameters": {
        "columns": {
          "value": {
            "name": "={{ $('Build Timestamped Message').item.json.name }}",
            "phone": "={{ $('Build Timestamped Message').item.json.phone }}",
            "message": "={{ $('Build Timestamped Message').item.json.message }}",
            "mapsLink": "={{ $('Build Timestamped Message').item.json.mapsLink }}",
            "timestamp": "={{ $('Build Timestamped Message').item.json.timestamp }}"
          },
          "schema": [
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "phone",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "phone",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "mapsLink",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "mapsLink",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "message",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_SHEET_ID/edit#gid=0",
          "cachedResultName": "safety data"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEET_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_SHEET_ID/edit",
          "cachedResultName": "Safety Incidents Log"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "75d6ae79-012f-4e1d-81d8-4330a2d7df3a",
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent: Format Emergency Alert",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Generate Maps Link": {
      "main": [
        [
          {
            "node": "Build Timestamped Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive Emergency Alert": {
      "main": [
        [
          {
            "node": "Generate Maps Link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Timestamped Message": {
      "main": [
        [
          {
            "node": "AI Agent: Format Emergency Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent: Format Emergency Alert": {
      "main": [
        [
          {
            "node": "Send Alert to Telegram Group",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log Incident to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}