AutomationFlowsAI & RAG › Classify Gmail Support Emails with AI and Store Tickets in Postgresql

Classify Gmail Support Emails with AI and Store Tickets in Postgresql

ByJyothish S L @jyothishsl on n8n.io

This workflow automatically converts incoming Gmail messages into structured support tickets using AI classification. It assigns categories, generates a unique ticket ID, stores data in PostgreSQL, assigns a support agent based on workload, and sends an automated email reply to…

Event trigger★★★★☆ complexityAI-powered22 nodesGmailText ClassifierLm OllamaPostgresGmail Trigger
AI & RAG Trigger: Event Nodes: 22 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #15522 — we link there as the canonical source.

This workflow follows the Gmail → Gmail Trigger recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "ANM0XWTjlsQvNUbf",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "AI Ticket Classifier",
  "tags": [],
  "nodes": [
    {
      "id": "2624805e-f8f9-4cb7-8de2-c3ae7cd2f975",
      "name": "Get many messages",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -576,
        -240
      ],
      "parameters": {
        "limit": 1,
        "filters": {},
        "operation": "getAll"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "c9ed6968-dbad-4990-bbdd-cd97f3b09d28",
      "name": "Text Classifier",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "position": [
        -304,
        -288
      ],
      "parameters": {
        "options": {
          "systemPromptTemplate": "You are an intelligent email and support ticket classifier.\n\nClassify the user's message into exactly ONE of these categories:{categories}\n"
        },
        "inputText": "={{ $json.Subject }}",
        "categories": {
          "categories": [
            {
              "category": "Payment Issue",
              "description": "Issues related to payment failure, duplicate payment, refund requests, subscription activation, invoice problems, or money deducted from customer account."
            },
            {
              "category": "Login Failure",
              "description": "Issues where users cannot log in, forgot password, account locked, OTP problems, authentication failure, or access denied."
            },
            {
              "category": "Enhancement Request",
              "description": "Requests for new features, UI improvements, integrations, performance enhancements, or product suggestions."
            },
            {
              "category": "Fraud Alert",
              "description": "Unauthorized access attempts, suspicious transactions, account hacking concerns, phishing reports, or security-related complaints."
            },
            {
              "category": "Other",
              "description": "Unclassified "
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "647ddb9c-73dc-42b4-bf8b-cc0ef7fe34f1",
      "name": "Ollama Model",
      "type": "@n8n/n8n-nodes-langchain.lmOllama",
      "position": [
        -304,
        112
      ],
      "parameters": {
        "model": "llama3:latest",
        "options": {
          "lowVram": true
        }
      },
      "credentials": {
        "ollamaApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "832507a4-bce5-4d85-af99-fe775b2e53bf",
      "name": "Insert rows in a table",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1408,
        -256
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "tickets",
          "cachedResultName": "tickets"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public",
          "cachedResultName": "public"
        },
        "columns": {
          "value": {
            "status": "Active",
            "message": "={{ $('Get many messages').item.json.snippet }}",
            "subject": "={{ $('Get many messages').item.json.Subject }}",
            "category": "Oher Unclassified",
            "priority": "Less",
            "sentiment": "NA",
            "assigned_to": "={{ $json.id }}",
            "ticket_number": "={{ $('Code in JavaScript').item.json.ticket_number }}",
            "customer_email": "={{ $('Get many messages').item.json.From }}"
          },
          "schema": [
            {
              "id": "id",
              "type": "number",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "ticket_number",
              "type": "string",
              "display": true,
              "required": true,
              "displayName": "ticket_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "customer_email",
              "type": "string",
              "display": true,
              "required": true,
              "displayName": "customer_email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subject",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "message",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "category",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "priority",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "priority",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "sentiment",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "sentiment",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "assigned_to",
              "type": "number",
              "display": true,
              "required": false,
              "displayName": "assigned_to",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "created_at",
              "type": "dateTime",
              "display": true,
              "required": false,
              "displayName": "created_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "updated_at",
              "type": "dateTime",
              "display": true,
              "required": false,
              "displayName": "updated_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "5eeb559e-759c-4566-aaa6-670c091f336a",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        960,
        -256
      ],
      "parameters": {
        "jsCode": "for (const item of $input.all()) {\n\n  const now = new Date();\n\n  const year = now.getFullYear();\n  const month = String(now.getMonth() + 1).padStart(2, '0');\n  const day = String(now.getDate()).padStart(2, '0');\n  const hours = String(now.getHours()).padStart(2, '0');\n  const minutes = String(now.getMinutes()).padStart(2, '0');\n  const seconds = String(now.getSeconds()).padStart(2, '0');\n  const random = Math.floor(100 + Math.random() * 900);\n\n  const ticketId =\n    `TKT[Other]-${year}${month}${day}-${hours}${minutes}${seconds}-${random}`;\n\n  item.json.ticket_number = ticketId;\n\n\n  item.json.myNewField = $input.first().json.myNewField;\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "9baf8647-e6b9-4320-9f1a-ba2ecad19093",
      "name": "Select rows from a table",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1184,
        -256
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "support_persons",
          "cachedResultName": "support_persons"
        },
        "where": {
          "values": [
            {
              "value": "={{ $json.myNewField }}",
              "column": "skill_category",
              "condition": "LIKE"
            },
            {
              "value": "5",
              "column": "active_tickets",
              "condition": "<"
            }
          ]
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "options": {},
        "operation": "select"
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "79c08a8a-3724-4d30-ac92-8944bf0ef1ae",
      "name": "Update rows in a table",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1632,
        -256
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "support_persons",
          "cachedResultName": "support_persons"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "id": "={{ $('Select rows from a table').item.json.id }}",
            "active_tickets": "={{ Number($('Select rows from a table').item.json.active_tickets) + 1 }}"
          },
          "schema": [
            {
              "id": "id",
              "type": "number",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": true,
              "required": true,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "removed": true,
              "required": true,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "department",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "department",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "skill_category",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "skill_category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "status",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "active_tickets",
              "type": "number",
              "display": true,
              "required": false,
              "displayName": "active_tickets",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "max_tickets",
              "type": "number",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "max_tickets",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "created_at",
              "type": "dateTime",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "created_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update"
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "33cc911f-732a-4039-abd3-2bb0bbb11654",
      "name": "Insert rows in a table1",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1856,
        -256
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "list",
          "value": "ticket_assignment_logs",
          "cachedResultName": "ticket_assignment_logs"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "ticket_id": "={{ $('Code in JavaScript').item.json.ticket_number }}",
            "assignment_reason": "={{ $('Select rows from a table').item.json.status }}",
            "support_person_id": "={{ $('Select rows from a table').item.json.id }}"
          },
          "schema": [
            {
              "id": "id",
              "type": "number",
              "display": true,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "ticket_id",
              "type": "string",
              "display": true,
              "required": true,
              "displayName": "ticket_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "support_person_id",
              "type": "number",
              "display": true,
              "required": true,
              "displayName": "support_person_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "assigned_at",
              "type": "dateTime",
              "display": true,
              "required": false,
              "displayName": "assigned_at",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "assignment_reason",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "assignment_reason",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.6
    },
    {
      "id": "063c92c3-4ba6-472a-95ab-bd0bb6ead7db",
      "name": "Reply to a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2080,
        -256
      ],
      "parameters": {
        "message": "=<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <title>Ticket Confirmation</title>\n</head>\n<body style=\"font-family: Arial, sans-serif; line-height: 1.6; color: #333;\">\n\n  <h2 style=\"color: #16a085;\">Support Ticket Generated Successfully</h2>\n\n  <p>Dear Customer,</p>\n\n  <p>Thank you for contacting our support team. We have successfully received your request and created a support ticket for your issue.</p>\n\n  <h3 style=\"color: #16a085;\">Ticket Details</h3>\n\n  <table style=\"border-collapse: collapse; width: 100%; max-width: 600px;\">\n    <tr>\n      <td style=\"border: 1px solid #ddd; padding: 8px;\"><b>Ticket ID</b></td>\n      <td style=\"border: 1px solid #ddd; padding: 8px;\">{{ $('Code in JavaScript').item.json.ticket_number }}</td>\n    </tr>\n    <tr>\n      <td style=\"border: 1px solid #ddd; padding: 8px;\"><b>Support Person</b></td>\n      <td style=\"border: 1px solid #ddd; padding: 8px;\">{{ $('Select rows from a table').item.json.name }}</td>\n    </tr>\n    <tr>\n      <td style=\"border: 1px solid #ddd; padding: 8px;\"><b>Support Person Contact</b></td>\n      <td style=\"border: 1px solid #ddd; padding: 8px;\">{{ $('Select rows from a table').item.json.email }}</td>\n    </tr>\n    <tr>\n      <td style=\"border: 1px solid #ddd; padding: 8px;\"><b>Status</b></td>\n      <td style=\"border: 1px solid #ddd; padding: 8px;\">Under Review</td>\n    </tr>\n  </table>\n\n  <p>\n    We appreciate your patience. You will receive another update once the issue is resolved.\n  </p>\n\n  <br>\n\n  <p>Regards,<br>\n  <b>Support Team</b></p>\n\n</body>\n</html>",
        "options": {
          "ccList": "={{ $('Select rows from a table').item.json.email }}"
        },
        "messageId": "={{ $('Get many messages').item.json.id }}",
        "operation": "reply"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "37b78d8c-d365-408e-a10d-74f624f7d4f6",
      "name": "Code in JavaScript1",
      "type": "n8n-nodes-base.code",
      "position": [
        400,
        -624
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 'Payment Issue';\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "09dbcfce-663e-4164-944c-aaaa5bbbd6cf",
      "name": "Code in JavaScript2",
      "type": "n8n-nodes-base.code",
      "position": [
        400,
        -432
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 'Bug Report';\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "d27192a8-7fd7-43e5-a1b9-0038bd37c582",
      "name": "Code in JavaScript3",
      "type": "n8n-nodes-base.code",
      "position": [
        400,
        -240
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 'General Query';\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "62cc5b11-2887-4417-81c1-7fae3026f9dc",
      "name": "Code in JavaScript4",
      "type": "n8n-nodes-base.code",
      "position": [
        400,
        -48
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 'Fraud Alert';\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "d57bf31f-b6f3-442b-b3ea-6de3553f79a3",
      "name": "Code in JavaScript5",
      "type": "n8n-nodes-base.code",
      "position": [
        400,
        144
      ],
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 'General';\n}\n\nreturn $input.all();"
      },
      "typeVersion": 2
    },
    {
      "id": "ff05d10c-ff67-418b-8b0c-fe31473e5ee5",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2352,
        -256
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "024437d9-6d7f-48d4-ad1d-6994f20062cc",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1104,
        -384
      ],
      "parameters": {
        "color": 4,
        "width": 928,
        "height": 480,
        "content": "## Ticket Creation in Postgres\n                                                          \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "23a73d52-b771-4740-8e0c-a348f787c459",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -352,
        -1072
      ],
      "parameters": {
        "width": 896,
        "height": 384,
        "content": "# This workflow automatically converts incoming Gmail messages into structured support tickets using AI classification. It assigns categories, generates a unique ticket ID, stores data in PostgreSQL, assigns a support agent based on workload, and sends an automated email reply to the customer."
      },
      "typeVersion": 1
    },
    {
      "id": "c66b99ac-24f0-47e4-bf7e-bb9055c1438f",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -848,
        -240
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "e1a72df2-99aa-4887-8028-e0ba548eac01",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -384,
        -464
      ],
      "parameters": {
        "color": 6,
        "width": 608,
        "height": 512,
        "content": "# Classify Email based on Ticket Priorirty Using Ollma \n"
      },
      "typeVersion": 1
    },
    {
      "id": "4be5854a-42a1-4d35-8c8b-3429079183c4",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        784,
        -320
      ],
      "parameters": {
        "width": 320,
        "height": 240,
        "content": "##  Ticket ID Generation"
      },
      "typeVersion": 1
    },
    {
      "id": "133aad6c-b7bc-4146-a541-349a482b104b",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -896,
        -1056
      ],
      "parameters": {
        "color": 6,
        "width": 416,
        "height": 448,
        "content": "# \ud83d\udce6 Requirements\n## n8n (latest version)\n## Gmail OAuth2 credentials\n## PostgreSQL database\n## AI model (Ollama or compatible LLM)\n## Support tables:\n## tickets\n## support_persons\n## ticket_assignment_logs"
      },
      "typeVersion": 1
    },
    {
      "id": "37cfa514-af80-4496-94d6-e9081302aa8f",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1808,
        -1056
      ],
      "parameters": {
        "width": 816,
        "height": 1424,
        "content": "# AI Ticket Classifier Database Setup\n\n\n\n# Create support_persons Table\n\n```sql\nCREATE TABLE support_persons (\n    id SERIAL PRIMARY KEY,\n    name VARCHAR(100) NOT NULL,\n    email VARCHAR(150) UNIQUE NOT NULL,\n    department VARCHAR(100),\n    skill_category VARCHAR(100),\n    status VARCHAR(20) DEFAULT 'available',\n    active_tickets INT DEFAULT 0,\n    max_tickets INT DEFAULT 5,\n    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n);\n```\n\n---\n\n# Create tickets Table\n\n```sql\nCREATE TABLE tickets (\n    id SERIAL PRIMARY KEY,\n    ticket_number VARCHAR(30) UNIQUE NOT NULL,\n    customer_email VARCHAR(150) NOT NULL,\n    subject VARCHAR(255),\n    message TEXT,\n    category VARCHAR(100),\n    priority VARCHAR(20),\n    sentiment VARCHAR(20),\n    status VARCHAR(30) DEFAULT 'open',\n\n    assigned_to INT REFERENCES support_persons(id),\n\n    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n);\n```\n\n---\n\n# Create ticket_assignment_logs Table\n\n```sql\nCREATE TABLE ticket_assignment_logs (\n    id SERIAL PRIMARY KEY,\n\n    ticket_id VARCHAR(100) NOT NULL,\n\n    support_person_id INT NOT NULL,\n\n    assigned_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n\n    assignment_reason TEXT,\n\n    CONSTRAINT fk_support\n        FOREIGN KEY (support_person_id)\n        REFERENCES support_persons(id)\n);\n```\n\n\n# Supported Ticket Categories\n\n- Technical Issue\n- Payment Issue\n- Refund Request\n- Fraud Alert\n- Bug Report\n- General Query\n- General\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "08ee582c-1daf-40c0-9417-060d6a5cc16a",
  "connections": {
    "Ollama Model": {
      "ai_languageModel": [
        [
          {
            "node": "Text Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Get many messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text Classifier": {
      "main": [
        [
          {
            "node": "Code in JavaScript1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code in JavaScript2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code in JavaScript3",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code in JavaScript4",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code in JavaScript5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get many messages": {
      "main": [
        [
          {
            "node": "Text Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Select rows from a table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply to a message": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript1": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript2": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript3": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript4": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript5": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert rows in a table": {
      "main": [
        [
          {
            "node": "Update rows in a table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update rows in a table": {
      "main": [
        [
          {
            "node": "Insert rows in a table1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert rows in a table1": {
      "main": [
        [
          {
            "node": "Reply to a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select rows from a table": {
      "main": [
        [
          {
            "node": "Insert rows in a table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow automatically converts incoming Gmail messages into structured support tickets using AI classification. It assigns categories, generates a unique ticket ID, stores data in PostgreSQL, assigns a support agent based on workload, and sends an automated email reply to…

Source: https://n8n.io/workflows/15522/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This workflow delivers a complete, enterprise-grade Gmail automation system designed for high-volume teams. It classifies incoming emails, applies labels, generates AI-powered responses, and routes me

Gmail, OpenAI, Telegram +3
AI & RAG

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

Gmail Trigger, Write Binary File, Information Extractor +3
AI & RAG

Automatically analyze email attachments with AI and forward invoices/receipts to freee's File Box. Polls Gmail for new emails with attachments every minute Extracts text from PDF attachments and sends

Gmail Trigger, Gmail, Google Gemini
AI & RAG

This workflow is perfect for IT departments, helpdesk teams, or internal service units that manage incoming support requests through Jotform. It automates ticket handling, classification, and response

Jot Form Trigger, Google Gemini Chat, Chain Summarization +4
AI & RAG

Automatically organise your Gmail inbox using AI. This workflow categorises every incoming email and applies Gmail labels, keeping only important emails in your inbox while filing everything else auto

OpenAI, Gmail, Gmail Trigger