{
  "name": "Daily AI summary of new support tickets",
  "nodes": [
    {
      "id": "00000000-0000-4000-8000-000000000020",
      "name": "Weekday summary time",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 8 * * 1-5"
            }
          ]
        }
      }
    },
    {
      "id": "00000000-0000-4000-8000-000000000021",
      "name": "Fetch new tickets",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        280,
        300
      ],
      "parameters": {
        "method": "GET",
        "url": "https://helpdesk.example.com/api/tickets?status=new",
        "options": {
          "timeout": 20000,
          "response": {
            "response": {
              "neverError": true,
              "fullResponse": true
            }
          }
        },
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000,
      "onError": "continueErrorOutput",
      "credentials": {
        "httpHeaderAuth": {
          "id": "HELPDESK_HEADER_AUTH",
          "name": "Helpdesk API header"
        }
      }
    },
    {
      "id": "00000000-0000-4000-8000-000000000022",
      "name": "Compact the ticket list",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const body = $json.body ?? $json;\nconst tickets = Array.isArray(body) ? body : Array.isArray(body.tickets) ? body.tickets : [];\nconst lines = tickets.slice(0, 50).map((ticket) => {\n  const id = ticket.id ?? ticket.key ?? \"unknown\";\n  const subject = String(ticket.subject ?? ticket.title ?? \"(no subject)\").slice(0, 160);\n  const status = ticket.status ?? \"new\";\n  return `${id} | ${status} | ${subject}`;\n});\nconst ticketText = lines.length ? lines.join(\"\\n\") : \"No new tickets.\";\nreturn [{ json: { count: tickets.length, ticketText } }];"
      }
    },
    {
      "id": "00000000-0000-4000-8000-000000000023",
      "name": "Summarize tickets with OpenAI",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        840,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "options": {
          "timeout": 30000,
          "response": {
            "response": {
              "neverError": true,
              "fullResponse": false
            }
          }
        },
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: \"gpt-4.1-mini\", temperature: 0, messages: [{ role: \"system\", content: \"Summarize support tickets for an operator. Group by theme, name blockers, and list ticket ids. Do not invent tickets that are not in the list. If the list is empty, say there were no new tickets.\" }, { role: \"user\", content: $json.ticketText }] }) }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000,
      "onError": "continueErrorOutput",
      "credentials": {
        "httpHeaderAuth": {
          "id": "OPENAI_HEADER_AUTH",
          "name": "OpenAI Authorization header"
        }
      }
    },
    {
      "id": "00000000-0000-4000-8000-000000000024",
      "name": "Read the summary",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1120,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const count = $(\"Compact the ticket list\").item.json.count;\nconst summary = $json.choices?.[0]?.message?.content || $json.body || \"The summary call did not return text.\";\nreturn [{ json: { count, summary } }];"
      }
    },
    {
      "id": "00000000-0000-4000-8000-000000000025",
      "name": "Email the daily summary",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1400,
        300
      ],
      "parameters": {
        "fromEmail": "summaries@example.com",
        "toEmail": "support-lead@example.com",
        "subject": "=Daily support summary",
        "emailFormat": "text",
        "text": "=New tickets: {{ $json.count }}\\n\\n{{ $json.summary }}"
      },
      "credentials": {
        "smtp": {
          "id": "SMTP_CREDENTIAL",
          "name": "SMTP account"
        }
      }
    },
    {
      "id": "00000000-0000-4000-8000-000000000026",
      "name": "Alert summary failed",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        840,
        540
      ],
      "parameters": {
        "resource": "message",
        "operation": "post",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "name",
          "value": "#support-ops"
        },
        "text": "=The daily ticket summary did not finish. Check the helpdesk or OpenAI node in n8n.",
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "id": "SLACK_CREDENTIAL",
          "name": "Slack account"
        }
      }
    }
  ],
  "pinData": {
    "Fetch new tickets": [
      {
        "json": {
          "statusCode": 200,
          "body": {
            "tickets": [
              {
                "id": "T-101",
                "status": "new",
                "subject": "Cannot reset the password after the email link expires"
              },
              {
                "id": "T-102",
                "status": "new",
                "subject": "Invoice total does not match the checkout page"
              }
            ]
          }
        }
      }
    ]
  },
  "connections": {
    "Weekday summary time": {
      "main": [
        [
          {
            "node": "Fetch new tickets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch new tickets": {
      "main": [
        [
          {
            "node": "Compact the ticket list",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Alert summary failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compact the ticket list": {
      "main": [
        [
          {
            "node": "Summarize tickets with OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Summarize tickets with OpenAI": {
      "main": [
        [
          {
            "node": "Read the summary",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Alert summary failed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read the summary": {
      "main": [
        [
          {
            "node": "Email the daily summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "timezone": "UTC",
    "saveDataErrorExecution": "all",
    "saveDataSuccessExecution": "all",
    "saveManualExecutions": true
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
