{
  "id": "NFZV0Vu2LxpyuiBF",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Automated Lead Collection to SendPulse and AI-Generated Welcome Emails/SMS",
  "tags": [],
  "nodes": [
    {
      "id": "95139a48-a08d-4968-854b-4015f9cdc3f7",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        992,
        288
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "104332f5-e42a-4db9-a111-59a4a5fed1fa",
      "name": "Get New Access Token",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -800,
        224
      ],
      "parameters": {
        "url": "={{ $('Workflow Configuration').item.json.sendPulseApiUrl }}/oauth/access_token",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "grant_type",
              "value": "client_credentials"
            },
            {
              "name": "client_id",
              "value": "={{ $('Workflow Configuration').item.json.clientId }}"
            },
            {
              "name": "client_secret",
              "value": "={{ $('Workflow Configuration').item.json.clientSecret }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "8aa7fe30-0930-4dbf-862c-d4ee03abc0cb",
      "name": "Get Token from Storage",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        -1216,
        368
      ],
      "parameters": {
        "limit": 1,
        "filters": {
          "conditions": [
            {
              "keyName": "hash",
              "keyValue": "={{ $json.storageKey }}"
            }
          ]
        },
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "l03FRqX5p37JB7a6",
          "cachedResultUrl": "/projects/kQ7xLYGfjAX0aSkm/datatables/l03FRqX5p37JB7a6",
          "cachedResultName": "tokens"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f6682e8d-74e8-48b3-abac-9da2d71a9647",
      "name": "Save Token to Storage",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        -592,
        224
      ],
      "parameters": {
        "columns": {
          "value": {
            "hash": "={{ $('Generate Hash').item.json.storageKey }}",
            "accessToken": "={{ $json.access_token }}",
            "tokenExpiry": "={{ new Date(Date.now() + 3600000).toISOString() }}"
          },
          "schema": [
            {
              "id": "hash",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "hash",
              "defaultMatch": false
            },
            {
              "id": "accessToken",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "accessToken",
              "defaultMatch": false
            },
            {
              "id": "tokenExpiry",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "tokenExpiry",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "filters": {
          "conditions": [
            {
              "keyName": "hash",
              "keyValue": "={{ $('Generate Hash').item.json.storageKey }}"
            }
          ]
        },
        "options": {},
        "operation": "upsert",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "l03FRqX5p37JB7a6",
          "cachedResultUrl": "/projects/kQ7xLYGfjAX0aSkm/datatables/l03FRqX5p37JB7a6",
          "cachedResultName": "tokens"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3d2bbec5-91b2-487b-97a1-7c015a15375b",
      "name": "Generate Hash",
      "type": "n8n-nodes-base.code",
      "position": [
        -1424,
        368
      ],
      "parameters": {
        "jsCode": "const crypto = require('crypto');\n\nconst clientId = $input.first().json.clientId;\nconst clientSecret = $input.first().json.clientSecret;\n\nconst storageKey = crypto.createHash('md5').update(clientId + ':' + clientSecret).digest('hex');\n\nreturn [{\n  json: {\n    ...$input.first().json,\n    storageKey\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "c067bfd9-c1cf-4096-b791-d537263d1628",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -1632,
        368
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7795b978-e318-4c91-97d6-3b38251b219e",
              "name": "sendPulseApiUrl",
              "type": "string",
              "value": "https://api.sendpulse.com"
            },
            {
              "id": "id-1",
              "name": "clientId",
              "type": "string",
              "value": "<clientId>"
            },
            {
              "id": "id-2",
              "name": "clientSecret",
              "type": "string",
              "value": "<clientSecret>"
            },
            {
              "id": "d5469dd5-41f7-455a-9bba-5282552b75a5",
              "name": "mailingListWithEmails",
              "type": "string",
              "value": "Customer emails"
            },
            {
              "id": "cb5361fa-e293-461f-ae4b-c76697684740",
              "name": "mailingListWithPhones",
              "type": "string",
              "value": "Customer phone numbers"
            },
            {
              "id": "efd58129-f60c-4eee-885e-9017b932c039",
              "name": "senderName",
              "type": "string",
              "value": "<senderName>"
            },
            {
              "id": "24ee2f3b-9e89-4931-8382-888672fddfd3",
              "name": "senderEmail",
              "type": "string",
              "value": "<senderEmail>"
            },
            {
              "id": "4ea6de43-b65d-4791-af5c-d6c9320561f1",
              "name": "smsSender",
              "type": "string",
              "value": "<smsSender>"
            },
            {
              "id": "d710e732-fd52-414b-8a64-2a3c18127b85",
              "name": "routeCountryCode",
              "type": "string",
              "value": "UA"
            },
            {
              "id": "a7cdfe8b-632f-4787-b5b3-a3042b9c77b5",
              "name": "routeType",
              "type": "string",
              "value": "international"
            },
            {
              "id": "61449bd9-1968-4f71-84e3-8edee36f50a1",
              "name": "name",
              "type": "string",
              "value": "={{ $json.body.name }}"
            },
            {
              "id": "de4c5266-20e6-4339-9011-d6cbd4947025",
              "name": "email",
              "type": "string",
              "value": "={{ $json.body.email }}"
            },
            {
              "id": "601fa484-0eb8-4a16-b07b-6b9036508e60",
              "name": "phone",
              "type": "string",
              "value": "={{ $json.body.phone }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c4bd4060-4487-4c96-ba94-13c2fd5e38e6",
      "name": "Is Token Expired?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1008,
        368
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "44aee850-216d-4ca5-8cb3-83675a3fce3c",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.tokenExpiry }}",
              "rightValue": "null"
            },
            {
              "id": "0338a17d-b697-48c0-83ae-77b39d9a1a95",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ Date.now() }}",
              "rightValue": "={{ new Date($json.tokenExpiry).getTime() }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "9baae0dc-2ed8-4797-9dd9-d0c65e2b6ca0",
      "name": "Exists phone?",
      "type": "n8n-nodes-base.if",
      "position": [
        240,
        608
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1aba1c4a-88b3-4e30-855c-c290e49411af",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $('Workflow Configuration').item.json.phone }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "41dff052-04e1-4ea9-aae3-1d16b9f773f6",
      "name": "Exists email?",
      "type": "n8n-nodes-base.if",
      "position": [
        32,
        384
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "42e16418-0066-459a-bf0f-360de7917a35",
              "operator": {
                "type": "string",
                "operation": "exists",
                "singleValue": true
              },
              "leftValue": "={{ $('Workflow Configuration').item.json.email }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "34a6875d-a9de-4816-8f8e-932758400428",
      "name": "Create mailing list with phones",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        864,
        736
      ],
      "parameters": {
        "url": "={{ $('Workflow Configuration').first().json.sendPulseApiUrl }}/addressbooks ",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "bookName",
              "value": "={{ $('Workflow Configuration').first().json.mailingListWithPhones }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Set Access Token').first().json.accessToken }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "3c89b9fe-30d1-495e-953f-0de4fc71c562",
      "name": "Search Mailing Lists With Phone Numbers",
      "type": "n8n-nodes-base.code",
      "position": [
        448,
        592
      ],
      "parameters": {
        "jsCode": "const mailingLists = $('Get Mailing List').all();\nconst targetListName = $('Workflow Configuration').first().json.mailingListWithPhones;\nconst workflowConfig = $('Workflow Configuration').first().json;\nconst accessToken = $('Set Access Token').first().json;\n\nlet foundList = null;\n\nfor (const item of mailingLists) {\n  if (item.json.name === targetListName) {\n    foundList = item.json;\n    break;\n  }\n}\n\nif (foundList) {\n  return [{\n    json: {\n      isMailingList: true,\n      mailingListId: foundList.id,\n    }\n  }];\n} else {\n  return [{\n    json: {\n      isMailingList: false,\n      mailingListId: null,\n    }\n  }];\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "fd29f0bf-9238-4b17-a31c-085c99d7b69d",
      "name": "Search Mailing Lists With Emails",
      "type": "n8n-nodes-base.code",
      "position": [
        240,
        144
      ],
      "parameters": {
        "jsCode": "const mailingLists = $('Get Mailing List').all();\nconst targetListName = $('Workflow Configuration').first().json.mailingListWithEmails;\n\nlet foundList = null;\n\nfor (const item of mailingLists) {\n  if (item.json.name === targetListName) {\n    foundList = item.json;\n    break;\n  }\n}\n\nif (foundList) {\n  return [{\n    json: {\n      isMailingList: true,\n      mailingListId: foundList.id,\n    }\n  }];\n} else {\n  return [{\n    json: {\n      isMailingList: false,\n      mailingListId: null,\n    }\n  }];\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "e2b6b5b9-10c2-4ff3-b15e-681f9e45061e",
      "name": "Is Exists Mailing List With Phone Numbers",
      "type": "n8n-nodes-base.if",
      "position": [
        656,
        592
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e984e141-2fa1-461f-aeb8-17d32bbc1976",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.isMailingList }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "60f99524-5e7c-4bdf-948f-fa3ea8957c79",
      "name": "SendPulse MCP Client",
      "type": "@n8n/n8n-nodes-langchain.mcpClientTool",
      "position": [
        1296,
        288
      ],
      "parameters": {
        "include": "selected",
        "options": {},
        "endpointUrl": "https://mcp.sendpulse.com/mcp",
        "includeTools": [
          "smtp_emails_send"
        ],
        "authentication": "multipleHeadersAuth"
      },
      "credentials": {
        "httpMultipleHeadersAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "42371b2b-fbc9-4f1e-b15a-4f7428fb1e09",
      "name": "Set Access Token",
      "type": "n8n-nodes-base.set",
      "position": [
        -384,
        384
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a7f13180-d957-43e2-b279-a8123e7ea48c",
              "name": "accessToken",
              "type": "string",
              "value": "={{ $json.accessToken }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c5aa065c-9924-4043-ac55-09a2a99fd880",
      "name": "Exists Mailing List With Emails?",
      "type": "n8n-nodes-base.if",
      "position": [
        448,
        144
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e984e141-2fa1-461f-aeb8-17d32bbc1976",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.isMailingList }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "7695f2fa-8c33-4957-9dcc-fd9faab01a33",
      "name": "Create Mailing List With Emails",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        656,
        288
      ],
      "parameters": {
        "url": "={{ $('Workflow Configuration').first().json.sendPulseApiUrl }}/addressbooks",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "bookName",
              "value": "={{ $('Workflow Configuration').first().json.mailingListWithEmails }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "=Authorization",
              "value": "=Bearer {{ $('Set Access Token').first().json.accessToken }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "f30538da-376f-4673-b3b6-dfe7d3d2bc86",
      "name": "Generate And Send Welcome Email",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1072,
        128
      ],
      "parameters": {
        "text": "=You are an AI assistant responsible for generating personalized welcome email messages for clients.\n\nThe clients\u2019 email addresses and first names are collected via a web form on the website.\n\nYour task is to:\nGenerate a friendly, professional, and concise welcome email\nPersonalize each email using the client\u2019s first name\nEnsure the content is suitable for email distribution\nAvoid spammy language and excessive marketing claims\nWrite in a warm and trustworthy tone\n\nSend the created email via SMTP.\nSender details:\nSender name: {{ $('Workflow Configuration').first().json.senderName }}\nSender email: {{ $('Workflow Configuration').first().json.senderEmail }}\n\nRecipient details:\nRecipient name: {{ $('Workflow Configuration').first().json.name }}\nRecipient email: {{ $('Workflow Configuration').first().json.email }}",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 3
    },
    {
      "id": "625bab5d-8f0c-4d9b-9f6e-44f11f3f86c8",
      "name": "Generate Welcome SMS",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1280,
        576
      ],
      "parameters": {
        "text": "=You are an AI assistant responsible for generating personalized welcome SMS messages for clients.\n\nThe client\u2019s phone numbers and first names are collected via a web form on the website.\n\nClient name: {{ $('Workflow Configuration').first().json.name }}\nClient phone number: {{ $('Workflow Configuration').first().json.phone }}\n\nYour task is to:\nGenerate a short, friendly, and professional welcome SMS message\nPersonalize each message using the client\u2019s first name\nKeep the message concise and suitable for SMS length limits\nAvoid spam-like language, excessive marketing, and misleading claims\nUse a warm, trustworthy, and respectful tone\n\nThe output should be the final SMS text only, ready to be sent to the client\u2019s phone number.",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 3
    },
    {
      "id": "49e643bd-2d0a-4944-b2a6-416b74da2e10",
      "name": "Add Email to Mailing List",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        864,
        128
      ],
      "parameters": {
        "url": "={{ $('Workflow Configuration').first().json.sendPulseApiUrl }}/addressbooks/{{ $json.id || $json.mailingListId }}/emails",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"emails\": [\n    {\n      \"email\": \"{{ $('Workflow Configuration').first().json.email }}\",\n      \"variables\": {\n        \"name\": \"{{ $('Workflow Configuration').first().json.name }}\"\n      }\n    }\n  ]\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Set Access Token').first().json.accessToken }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "1ade3de5-24c6-41d4-90ab-85488f88668b",
      "name": "Add Phone Number to Mailing List",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1072,
        576
      ],
      "parameters": {
        "url": "={{ $('Workflow Configuration').first().json.sendPulseApiUrl }}/sms/numbers/variables",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"addressBookId\": {{ $json.id || $json.mailingListId }},\n  \"phones\": {\n    \"{{ $('Workflow Configuration').first().json.phone }}\": [\n      [\n        {\n          \"name\": \"Name\",\n          \"type\": \"string\",\n          \"value\": \"{{ $('Workflow Configuration').first().json.name }}\"\n        }\n      ]\n    ]\n  }\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Set Access Token').first().json.accessToken }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "4f840e47-ebbd-4f86-b959-1b7624ab5175",
      "name": "Send SMS to Client",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1616,
        576
      ],
      "parameters": {
        "url": "={{ $('Workflow Configuration').first().json.sendPulseApiUrl }}/sms/send",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n   \"sender\": \"{{ $('Workflow Configuration').first().json.smsSender }}\",\n   \"phones\": [\"{{ $('Workflow Configuration').first().json.phone }}\"],\n   \"body\":\"{{ $json.output }}\",\n   \"route\": {\n      \"{{ $('Workflow Configuration').first().json.routeCountryCode }}\": \"{{ $('Workflow Configuration').first().json.routeType }}\"\n   }\n}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('Set Access Token').first().json.accessToken }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "b6b2df53-eadd-4f41-9bc6-b3a9bdfc8791",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2832,
        128
      ],
      "parameters": {
        "width": 944,
        "height": 528,
        "content": "# Automated Lead Collection to SendPulse and AI-Generated Welcome Emails/SMS\n\n## How it works\n1. A web form posts new customer data (name, email or phone number) to the webhook.\n2. The workflow checks a stored SendPulse Access Token. If expired it requests a new token and saves it.\n3. It checks for or creates SendPulse mailing lists for emails and phones, then adds the contact to the appropriate lists.\n4. An AI model generates a personalized, professional welcome email and the workflow sends it via SendPulse SMTP.\n5. The AI also generates a short, friendly SMS which is sent through SendPulse SMS.\n\n## Setup steps\n- [ ] Add your SendPulse **Client ID** and **Client Secret** to the **Workflow Configuration**.\n- [ ] Configure **mailingListWithEmails**, **mailingListWithPhones**, **senderName**, **senderEmail**, **smsSender**, **routeCountryCode** and **routeType**.\n- [ ] Create a **tokens** data table with columns: **hash** (string), **accessToken** (string), **tokenExpiry** (stirng).\n- [ ] Add your **OpenAI API Key** to the **OpenAI Chat Model** node.\n- [ ] Point your website form to the workflow webhook (customer-registration) to POST name, email or phone number.\n- [ ] Test with a sample submission and confirm the contact is added and both email or SMS are delivered."
      },
      "typeVersion": 1
    },
    {
      "id": "c21c4ec9-1234-40e9-9efe-db54c7073dfe",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1456,
        128
      ],
      "parameters": {
        "color": 7,
        "width": 1200,
        "height": 416,
        "content": "## 2. Get access token\nSendPulse token management logic with caching in the Data Table"
      },
      "typeVersion": 1
    },
    {
      "id": "2350e3e0-bb32-4490-a855-2837c541f21b",
      "name": "New Customer Registration",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1840,
        368
      ],
      "parameters": {
        "path": "customer-registration",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "c5f3539c-9a17-41ff-96a5-a0f48e2e1439",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1696,
        128
      ],
      "parameters": {
        "color": 7,
        "width": 224,
        "height": 416,
        "content": "## 1. Workflow Configuration\nConfigure workflow variables"
      },
      "typeVersion": 1
    },
    {
      "id": "947b49bd-afaf-49c1-a657-f3c46f766a0f",
      "name": "Get Mailing List",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -176,
        384
      ],
      "parameters": {
        "url": "={{ $('Workflow Configuration').item.json.sendPulseApiUrl }}/addressbooks",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.accessToken }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "c787a6a8-52a3-4147-8e8a-b38f64cb4051",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        128
      ],
      "parameters": {
        "color": 7,
        "width": 224,
        "height": 416,
        "content": "## 3. Get mailing list\nGetting a list of all mailing lists from the Sendpulse Email service"
      },
      "typeVersion": 1
    },
    {
      "id": "2a37be64-deb8-47f9-9a55-0952c16d734b",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 1248,
        "height": 416,
        "content": "## 4. Email Processing\nChecking the existence of a mailing list for emails, creating a list if necessary, adding a contact to the mailing list, automatically generating and sending a personalized welcome email via AI and SendPulse MCP"
      },
      "typeVersion": 1
    },
    {
      "id": "cfd4b8c2-9b38-4b3d-97d6-da1b2950c287",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        480
      ],
      "parameters": {
        "color": 7,
        "width": 1664,
        "height": 416,
        "content": "## 5. SMS Processing\nChecking the existence of a mailing list for phone numbers, creating a list if necessary, adding a contact to the mailing list, automatically generating and sending a personalized welcome SMS via AI and SendPulse SMS API"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "c2bd91ed-2ba1-44c9-905b-4c0948803492",
  "connections": {
    "Exists email?": {
      "main": [
        [
          {
            "node": "Search Mailing Lists With Emails",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Exists phone?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Exists phone?": {
      "main": [
        [
          {
            "node": "Search Mailing Lists With Phone Numbers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Hash": {
      "main": [
        [
          {
            "node": "Get Token from Storage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Mailing List": {
      "main": [
        [
          {
            "node": "Exists email?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Access Token": {
      "main": [
        [
          {
            "node": "Get Mailing List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Token Expired?": {
      "main": [
        [
          {
            "node": "Get New Access Token",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Access Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Generate And Send Welcome Email",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Generate Welcome SMS",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Generate Welcome SMS": {
      "main": [
        [
          {
            "node": "Send SMS to Client",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get New Access Token": {
      "main": [
        [
          {
            "node": "Save Token to Storage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SendPulse MCP Client": {
      "ai_tool": [
        [
          {
            "node": "Generate And Send Welcome Email",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Save Token to Storage": {
      "main": [
        [
          {
            "node": "Set Access Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Token from Storage": {
      "main": [
        [
          {
            "node": "Is Token Expired?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Generate Hash",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Email to Mailing List": {
      "main": [
        [
          {
            "node": "Generate And Send Welcome Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New Customer Registration": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Mailing List With Emails": {
      "main": [
        [
          {
            "node": "Add Email to Mailing List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create mailing list with phones": {
      "main": [
        [
          {
            "node": "Add Phone Number to Mailing List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Phone Number to Mailing List": {
      "main": [
        [
          {
            "node": "Generate Welcome SMS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Exists Mailing List With Emails?": {
      "main": [
        [
          {
            "node": "Add Email to Mailing List",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Mailing List With Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Mailing Lists With Emails": {
      "main": [
        [
          {
            "node": "Exists Mailing List With Emails?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Mailing Lists With Phone Numbers": {
      "main": [
        [
          {
            "node": "Is Exists Mailing List With Phone Numbers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Exists Mailing List With Phone Numbers": {
      "main": [
        [
          {
            "node": "Add Phone Number to Mailing List",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create mailing list with phones",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}