{
  "name": "Auto Follow-up Email (AI)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8,
              "triggerAtMinute": 0
            }
          ]
        }
      },
      "id": "schedule-trigger",
      "name": "Codziennie o 8:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "getAll",
        "returnAll": false,
        "limit": 50,
        "filters": {
          "q": "is:sent -in:draft after:{{$today.minus({days:2}).toFormat('yyyy/MM/dd')}} -has:userlabels",
          "includeSpamTrash": false
        },
        "options": {}
      },
      "id": "gmail-check-sent",
      "name": "Gmail \u2014 wys\u0142ane bez odpowiedzi (48h)",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        480,
        300
      ],
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "getAll",
        "returnAll": false,
        "limit": 200,
        "filters": {
          "q": "is:inbox after:{{$today.minus({days:2}).toFormat('yyyy/MM/dd')}}",
          "includeSpamTrash": false
        },
        "options": {}
      },
      "id": "gmail-check-inbox",
      "name": "Gmail \u2014 sprawd\u017a odpowiedzi w inbox",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        480,
        520
      ],
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "combine",
        "mergeByFields": {
          "values": [
            {
              "field1": "threadId",
              "field2": "threadId"
            }
          ]
        },
        "joinMode": "keepNonMatches",
        "outputDataFrom": "input1",
        "options": {}
      },
      "id": "merge-filter",
      "name": "Filtruj \u2014 tylko bez odpowiedzi",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        720,
        400
      ]
    },
    {
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "Jeste\u015b asystentem sprzeda\u017cowym polskiej firmy M\u015aP. Pisz kr\u00f3tkie, uprzejme follow-upy po polsku. U\u017cywaj polskich znak\u00f3w (\u0105,\u0107,\u0119,\u0142,\u0144,\u00f3,\u015b,\u017a,\u017c). Ton: profesjonalny ale ciep\u0142y, bez nachalno\u015bci. Maksymalnie 4-5 zda\u0144."
            },
            {
              "role": "user",
              "content": "Napisz follow-up do wiadomo\u015bci, na kt\u00f3r\u0105 nie dosta\u0142em odpowiedzi od 48h.\n\nOryginalny temat: {{$json.subject}}\nOdbiorca: {{$json.to}}\nTre\u015b\u0107 orygina\u0142u (skr\u00f3t): {{$json.snippet}}\n\nZwr\u00f3\u0107 TYLKO tre\u015b\u0107 follow-upu, bez tematu."
            }
          ]
        },
        "options": {
          "temperature": 0.7,
          "maxTokens": 300
        }
      },
      "id": "openai-generate",
      "name": "OpenAI \u2014 generuj follow-up",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        960,
        400
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "send",
        "sendTo": "={{$('merge-filter').item.json.to}}",
        "subject": "Re: {{$('merge-filter').item.json.subject}}",
        "emailType": "text",
        "message": "={{$json.message.content}}",
        "options": {
          "threadId": "={{$('merge-filter').item.json.threadId}}"
        }
      },
      "id": "gmail-send-followup",
      "name": "Gmail \u2014 wy\u015blij follow-up",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1200,
        400
      ],
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "REPLACE_WITH_YOUR_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Follow-upy",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Data": "={{$today.toFormat('yyyy-MM-dd HH:mm')}}",
            "Odbiorca": "={{$('merge-filter').item.json.to}}",
            "Temat": "={{$('merge-filter').item.json.subject}}",
            "Tre\u015b\u0107 follow-upu": "={{$('openai-generate').item.json.message.content}}",
            "Status": "Wys\u0142ano"
          },
          "matchingColumns": []
        },
        "options": {}
      },
      "id": "gsheets-log",
      "name": "Google Sheets \u2014 loguj follow-up",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1440,
        400
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Codziennie o 8:00": {
      "main": [
        [
          {
            "node": "Gmail \u2014 wys\u0142ane bez odpowiedzi (48h)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Gmail \u2014 sprawd\u017a odpowiedzi w inbox",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail \u2014 wys\u0142ane bez odpowiedzi (48h)": {
      "main": [
        [
          {
            "node": "Filtruj \u2014 tylko bez odpowiedzi",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail \u2014 sprawd\u017a odpowiedzi w inbox": {
      "main": [
        [
          {
            "node": "Filtruj \u2014 tylko bez odpowiedzi",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Filtruj \u2014 tylko bez odpowiedzi": {
      "main": [
        [
          {
            "node": "OpenAI \u2014 generuj follow-up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI \u2014 generuj follow-up": {
      "main": [
        [
          {
            "node": "Gmail \u2014 wy\u015blij follow-up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail \u2014 wy\u015blij follow-up": {
      "main": [
        [
          {
            "node": "Google Sheets \u2014 loguj follow-up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner"
  },
  "staticData": null,
  "tags": [
    {
      "name": "email"
    },
    {
      "name": "ai"
    },
    {
      "name": "follow-up"
    },
    {
      "name": "automatyzacja"
    }
  ],
  "triggerCount": 1,
  "updatedAt": "2026-04-08T00:00:00.000Z",
  "versionId": "1"
}