{
  "id": "FLkc3VV1RMwXzm65",
  "name": "AI Support Ticket Classifier with CometAPI",
  "tags": [],
  "nodes": [
    {
      "id": "b39a3bc4-7cbd-408d-b725-1d1270a6867b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -304,
        96
      ],
      "parameters": {
        "width": 768,
        "height": 864,
        "content": "## AI Support Ticket Classifier with CometAPI\n\n### How it works\n\nThis workflow classifies incoming support tickets from either a web form or Gmail. It standardizes the ticket data, uses CometAPI to analyze the issue and write a suggested reply, then routes the ticket based on the classification. Depending on the issue type, it sends a Slack message or creates a Gmail draft for follow-up.\n\n### Setup steps\n\n- Configure the form trigger fields so submitted tickets include the customer name, email, subject, and message text.\n- Connect Gmail credentials for the Gmail Trigger and the Create a draft node, and confirm the watched mailbox or label is correct.\n- Add CometAPI credentials and configure the prompts/models used by the analysis and suggested-reply nodes.\n- Connect Slack credentials and choose the destination channel for routed support alerts.\n- Review the switch rules in Check and route according to issue to ensure they match the categories returned by the AI parsing step.\n\n### Customization\n\nAdjust the CometAPI prompts to change classification categories, tone, or reply format. Update the switch branches to route different issue types to different Slack channels, Gmail draft templates, or additional support tools."
      },
      "typeVersion": 1
    },
    {
      "id": "d6a0464b-a06b-4ebd-a7af-d40148701b8c",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        144
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 576,
        "content": "## Capture ticket inputs\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "c60689f7-23f1-4c5a-8a42-7d971aa06b2c",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1088,
        256
      ],
      "parameters": {
        "color": 7,
        "width": 704,
        "height": 336,
        "content": "## Analyze and draft reply\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "c790b422-b74a-49cd-83b6-0d68d9af37ac",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1824,
        128
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 576,
        "content": "## Route and notify teams\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "c0cc99c9-8835-4d8a-ad6e-38205491d0ae",
      "name": "When Form Submitted",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        640,
        272
      ],
      "parameters": {
        "options": {},
        "formTitle": "Submit a Support Ticket",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Name"
            },
            {
              "fieldType": "email",
              "fieldLabel": "Email"
            },
            {
              "fieldLabel": "Subject"
            },
            {
              "fieldType": "textarea",
              "fieldLabel": "Ticket Text"
            }
          ]
        },
        "formDescription": "Please describe your issue below. Our support team (powered by AI) will review, classify, and respond to your request as soon as possible."
      },
      "typeVersion": 2.6
    },
    {
      "id": "e601e6e9-ce39-4108-8840-fd46ba01a9b2",
      "name": "Post to Slack Channel",
      "type": "n8n-nodes-base.slack",
      "position": [
        2096,
        256
      ],
      "parameters": {
        "text": "=\ud83d\udea8 High Urgency Ticket Name: {{ $('When Form Submitted').item.json.Name }} Subject: {{ $('When Form Submitted').item.json.Subject }} Category: {{ $('Parse AI Analysis').item.json.category }} Sentiment: {{ $('Parse AI Analysis').item.json.sentiment }}  Suggested Reply: {{ $('Generate Reply Suggestion').item.json.choices[0].message.content }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "C0BHQ36U8MS"
        },
        "otherOptions": {}
      },
      "typeVersion": 2.5
    },
    {
      "id": "bbcfdd5e-ebc0-4823-aac5-11802ffb66f1",
      "name": "When Gmail Triggered",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        624,
        528
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "98789459-34f2-4366-b95d-134dd4ec8ebe",
      "name": "Send Email via Gmail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2096,
        544
      ],
      "parameters": {
        "message": "={{ $('Generate Reply Suggestion').item.json.choices[0].message.content }}",
        "options": {
          "sendTo": "= {{ $('When Form Submitted').isExecuted ? $('When Form Submitted').item.json.Email : $('Set Ticket Fields').item.json.Email }}"
        },
        "subject": "=Re: {{ $('When Form Submitted').isExecuted ? $('When Form Submitted').item.json.Subject : $('Set Ticket Fields').item.json.Subject }}",
        "resource": "draft"
      },
      "typeVersion": 2.2
    },
    {
      "id": "e4c37102-ded3-4d42-bb67-4f29c86adbf9",
      "name": "Set Ticket Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        880,
        384
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "966bb075-ef5d-430a-bace-1628abb0c791",
              "name": "Name",
              "type": "string",
              "value": "={{ $json.From }}"
            },
            {
              "id": "a11c2f2a-fce7-4280-b972-2a0928cc93ba",
              "name": "Email",
              "type": "string",
              "value": "={{ $json.From }}"
            },
            {
              "id": "ac2592e7-9a91-4e24-9ba0-37c063ce7387",
              "name": "Subject",
              "type": "string",
              "value": "={{ $json.Subject }}"
            },
            {
              "id": "b472f446-9052-493b-823f-3d8adcd529cd",
              "name": "Ticket Text",
              "type": "string",
              "value": "={{ $json.snippet }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "b32f154e-332b-4815-b489-1618244e3ce5",
      "name": "AI Ticket Issue Analysis",
      "type": "@cometapi-dev/n8n-nodes-cometapi.cometApi",
      "position": [
        1136,
        384
      ],
      "parameters": {
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=Read this support ticket and return three things: category (billing, technical, or general), urgency (low, medium, or high), and sentiment (positive, neutral, or negative). Return ONLY valid JSON with keys category, urgency, sentiment. Ticket: {{ $json.text || $json['Ticket Text'] }}"
            }
          ]
        }
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "964d86cf-1f0b-4c2d-bc76-defab4f1ef51",
      "name": "Parse AI Analysis",
      "type": "n8n-nodes-base.code",
      "position": [
        1392,
        384
      ],
      "parameters": {
        "jsCode": " const input = $input.item.json;\nconst response = Array.isArray(input) ? input[0] : input;\nconst raw = response?.choices?.[0]?.message?.content;\n\nlet parsed;\ntry {\n  const clean = raw.replace(/```json|```/g, \"\").trim();\n  parsed = JSON.parse(clean);\n} catch (e) {\n  parsed = { category: \"general\", urgency: \"low\", sentiment: \"neutral\" };\n}\n\n// Original ticket data CometAPI node ke baad lost ho jata hai,\n// isliye seedha trigger/set node se wapas le rahe hain\nlet original = {};\ntry {\n  original = $('When Form Submitted').item.json;\n} catch (e) {\n  try {\n    original = $('Set Ticket Fields').item.json;\n  } catch (e2) {\n    original = {};\n  }\n}\n\nreturn {\n  json: {\n    ...original,\n    category: parsed.category,\n    urgency: parsed.urgency,\n    sentiment: parsed.sentiment\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "8df076cf-3358-4d1b-8280-81566d537f41",
      "name": "Generate Reply Suggestion",
      "type": "@cometapi-dev/n8n-nodes-cometapi.cometApi",
      "position": [
        1648,
        384
      ],
      "parameters": {
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=Write a short, polite reply to this support ticket. Use the actual ticket content to personalize the response. \n\nStrict rules:\n- Do NOT use any placeholders in square brackets, such as [Customer's Name], [Your Name], or [Your Company].\n- If the sender's name isn't available, address them as \"Hi there\".\n- Sign off simply as \"Best regards, Support Team\" \u2014 do not invent a person's name.\n\nClassification \u2014 category: {{ $json.category }}, urgency: {{ $json.urgency }}, sentiment: {{ $json.sentiment }}\nTicket: {{ $json.text || $json['Ticket Text'] }}"
            }
          ]
        }
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "id": "d35b4e60-ec91-4dfd-a185-a4a10e10463f",
      "name": "Route by Ticket Issue",
      "type": "n8n-nodes-base.switch",
      "position": [
        1872,
        384
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "11732b2c-c6ce-4859-aa30-32525c309543",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Parse AI Analysis').item.json.urgency }}",
                    "rightValue": "high"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "e0e344ec-d95e-4488-baad-c2eeb1f68cb3",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Parse AI Analysis').item.json.urgency }}",
                    "rightValue": "medium"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 3,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "d02c2bc7-30c8-4c06-a127-4aceb662c23b",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Parse AI Analysis').item.json.urgency }}",
                    "rightValue": "low"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.4
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "ccf7e2dd-8c00-4478-881a-254c208c88bd",
  "nodeGroups": [],
  "connections": {
    "Parse AI Analysis": {
      "main": [
        [
          {
            "node": "Generate Reply Suggestion",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Ticket Fields": {
      "main": [
        [
          {
            "node": "AI Ticket Issue Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Form Submitted": {
      "main": [
        [
          {
            "node": "Set Ticket Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Gmail Triggered": {
      "main": [
        [
          {
            "node": "Set Ticket Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Ticket Issue": {
      "main": [
        [
          {
            "node": "Post to Slack Channel",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Post to Slack Channel",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Email via Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Ticket Issue Analysis": {
      "main": [
        [
          {
            "node": "Parse AI Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Reply Suggestion": {
      "main": [
        [
          {
            "node": "Route by Ticket Issue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}