{
  "name": "AI Rating Collector",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "save-rating",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-rating",
      "name": "Webhook - Rating",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=INSERT INTO ai_ratings (session_id, chat_log_id, rating, feedback_comment)\nVALUES (\n  '{{ $json.body.sessionId }}',\n  {{ $json.body.chatLogId || 'NULL' }},\n  '{{ $json.body.rating }}',\n  '{{ ($json.body.feedbackComment || '').replace(/'/g, \"''\") }}'\n)\nRETURNING id;",
        "options": {}
      },
      "id": "save-rating",
      "name": "Save Rating",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.4,
      "position": [
        450,
        300
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { success: true, message: 'Rating saved. Thank you for your feedback!' } }}"
      },
      "id": "respond-to-webhook",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Webhook - Rating": {
      "main": [
        [
          {
            "node": "Save Rating",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Rating": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "updatedAt": "2025-01-12T00:00:00.000Z",
  "versionId": "1"
}