{
  "name": "AI-powered credit card recommendation system with OpenAI GPT, Telegram & Google Sheets",
  "nodes": [
    {
      "id": "e869214b-4356-45f8-843a-1002fecfe015",
      "name": "Get Question Text",
      "type": "n8n-nodes-base.code",
      "position": [
        -704,
        336
      ]
    },
    {
      "id": "bc1e2374-5e1a-4bd0-8c96-85bfd94e1a00",
      "name": "Send Question",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -336,
        288
      ]
    },
    {
      "id": "c3cc1299-ee15-496c-8a49-477f44669b3d",
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -1040,
        -80
      ]
    },
    {
      "id": "c3008975-38de-4aca-ad1e-984dfcbb120e",
      "name": "Is Q7 Answered?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1056,
        192
      ]
    },
    {
      "id": "d17066e8-9fb1-42c5-91cf-9932695e3dea",
      "name": "Fetch Cards",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -688,
        -112
      ]
    },
    {
      "id": "aec9f45b-29ef-476e-89a1-902ac19f16d5",
      "name": "Clean Q1–Q7 Inputs",
      "type": "n8n-nodes-base.set",
      "position": [
        -688,
        128
      ]
    },
    {
      "id": "2e850a37-bd00-469a-850c-fc5d2af9b164",
      "name": "Trigger: Incoming Telegram Message",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1104,
        -640
      ]
    },
    {
      "id": "022df149-16cb-4887-9b44-b17eda095d05",
      "name": "Extract Telegram Message Text",
      "type": "n8n-nodes-base.code",
      "position": [
        -880,
        -640
      ]
    },
    {
      "id": "1618ceb8-9480-432f-b88d-7fe85e670b1c",
      "name": "Lookup User State (Google Sheet)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -656,
        -736
      ]
    },
    {
      "id": "ac8551bc-19aa-431b-9fbc-e3fd168310ea",
      "name": "Merge Incoming Message with State",
      "type": "n8n-nodes-base.merge",
      "position": [
        -432,
        -576
      ]
    },
    {
      "id": "36e658f2-1c7f-438b-a74e-88f0f48a8a0a",
      "name": "Check if User Exists in DB",
      "type": "n8n-nodes-base.if",
      "position": [
        -208,
        -576
      ]
    },
    {
      "id": "6f5ed263-2d00-46f8-8cc2-b28f947bbda6",
      "name": "Map & Format Answer for Google Sheet",
      "type": "n8n-nodes-base.code",
      "position": [
        208,
        -528
      ]
    },
    {
      "id": "9d1cccbc-9d7e-41da-9f45-28bded82540a",
      "name": "Extract Metadata from Answer",
      "type": "n8n-nodes-base.set",
      "position": [
        400,
        -528
      ]
    },
    {
      "id": "977b8392-ddb7-4063-afbe-cecccf8d23a6",
      "name": "Append Full User State for Processing",
      "type": "n8n-nodes-base.code",
      "position": [
        592,
        -544
      ]
    },
    {
      "id": "6a7b940f-5271-4d75-9aec-a920a46b37ca",
      "name": "Merge Updated State for Next Step",
      "type": "n8n-nodes-base.merge",
      "position": [
        736,
        -800
      ]
    },
    {
      "id": "56c50495-7c4c-4768-b9ec-613194c1a480",
      "name": "Carry Forward Previous Answers",
      "type": "n8n-nodes-base.set",
      "position": [
        944,
        -816
      ]
    },
    {
      "id": "964192de-8ead-41df-85f4-a8a97cba0463",
      "name": "Update Answer in Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1136,
        -800
      ]
    },
    {
      "id": "df3fa4be-5cb4-4cd2-a8cd-9518ccd68a21",
      "name": "Insert New User into Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1088,
        -560
      ]
    },
    {
      "id": "9d8e2199-789d-4a74-a73a-bbf2053d2373",
      "name": "Determine Next Quiz Question",
      "type": "n8n-nodes-base.code",
      "position": [
        1328,
        -624
      ]
    },
    {
      "id": "a275010c-7616-4c2e-a44c-750ea4911145",
      "name": "Check if More Questions Remaining",
      "type": "n8n-nodes-base.switch",
      "position": [
        -1264,
        48
      ]
    },
    {
      "id": "0425f294-897e-44d1-a487-ee491aebd545",
      "name": "Merge User Profile & Card Dataset",
      "type": "n8n-nodes-base.merge",
      "position": [
        -320,
        80
      ]
    },
    {
      "id": "9664c35e-3b1c-4f5e-92b3-fd52b2876869",
      "name": "Build GPT Prompt with User Profile & Card Data",
      "type": "n8n-nodes-base.code",
      "position": [
        160,
        112
      ]
    },
    {
      "id": "002101d2-7798-464b-8542-e014735c4b53",
      "name": "Send Prompt to GPT for Card Matching",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        352,
        112
      ]
    },
    {
      "id": "cf11ccaf-40ee-4e44-89af-f4db4b93ac79",
      "name": "Clean GPT Output & Split into Sections",
      "type": "n8n-nodes-base.code",
      "position": [
        688,
        112
      ]
    },
    {
      "id": "babdd4b6-5f2f-4c24-aa3a-358560f97744",
      "name": "Format GPT Card Recommendations for Telegram",
      "type": "n8n-nodes-base.code",
      "position": [
        896,
        112
      ]
    },
    {
      "id": "e0fbd374-614c-4681-890a-a786b9ae0288",
      "name": "Send Card Recommendations to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1120,
        112
      ]
    },
    {
      "id": "f0acc684-bdf0-4193-9cfc-05bee0d9697e",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1280,
        608
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "d5123091-7314-45ad-a937-0e6ece77efd2",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1280,
        -880
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "2c6f97d4-261f-462f-a970-dafbc648f802",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -880
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "156beb71-93c6-4788-9dad-b735a6c4b7b4",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1280,
        -160
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "60142bf7-eaf8-472d-bdfb-3a6cb79c1848",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        -160
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    }
  ],
  "connections": {
    "Fetch Cards": {
      "main": [
        [
          {
            "node": "Merge User Profile & Card Dataset",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Q7 Answered?": {
      "main": [
        [
          {
            "node": "Fetch Cards",
            "type": "main",
            "index": 0
          },
          {
            "node": "Clean Q1–Q7 Inputs",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Question Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Question Text": {
      "main": [
        [
          {
            "node": "Send Question",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean Q1–Q7 Inputs": {
      "main": [
        [
          {
            "node": "Merge User Profile & Card Dataset",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Check if User Exists in DB": {
      "main": [
        [
          {
            "node": "Map & Format Answer for Google Sheet",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Insert New User into Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Determine Next Quiz Question": {
      "main": [
        [
          {
            "node": "Check if More Questions Remaining",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Metadata from Answer": {
      "main": [
        [
          {
            "node": "Append Full User State for Processing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Telegram Message Text": {
      "main": [
        [
          {
            "node": "Lookup User State (Google Sheet)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge Incoming Message with State",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Update Answer in Google Sheet": {
      "main": [
        [
          {
            "node": "Determine Next Quiz Question",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Carry Forward Previous Answers": {
      "main": [
        [
          {
            "node": "Update Answer in Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lookup User State (Google Sheet)": {
      "main": [
        [
          {
            "node": "Merge Updated State for Next Step",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge Incoming Message with State",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if More Questions Remaining": {
      "main": [
        [
          {
            "node": "Is Q7 Answered?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert New User into Google Sheet": {
      "main": [
        [
          {
            "node": "Determine Next Quiz Question",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Incoming Message with State": {
      "main": [
        [
          {
            "node": "Check if User Exists in DB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Updated State for Next Step": {
      "main": [
        [
          {
            "node": "Carry Forward Previous Answers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge User Profile & Card Dataset": {
      "main": [
        [
          {
            "node": "Build GPT Prompt with User Profile & Card Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger: Incoming Telegram Message": {
      "main": [
        [
          {
            "node": "Extract Telegram Message Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Map & Format Answer for Google Sheet": {
      "main": [
        [
          {
            "node": "Extract Metadata from Answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Prompt to GPT for Card Matching": {
      "main": [
        [
          {
            "node": "Clean GPT Output & Split into Sections",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append Full User State for Processing": {
      "main": [
        [
          {
            "node": "Merge Updated State for Next Step",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Clean GPT Output & Split into Sections": {
      "main": [
        [
          {
            "node": "Format GPT Card Recommendations for Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format GPT Card Recommendations for Telegram": {
      "main": [
        [
          {
            "node": "Send Card Recommendations to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build GPT Prompt with User Profile & Card Data": {
      "main": [
        [
          {
            "node": "Send Prompt to GPT for Card Matching",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}