{
  "name": "DS- My Lead Gen",
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "67cac486-b224-4268-9991-c02571667fcb",
              "name": "Process URL",
              "value": "={{ \"https://mermaid.ink/img/\"+$json.choices[0].message.content.replace(/```mermaid\\n([^`]+)```/, '$1').trim().base64Encode() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        840,
        340
      ],
      "id": "edb29a78-ad6f-427a-a253-1e1114090fc8",
      "name": "Process Response and encode image url",
      "notesInFlow": true,
      "notes": "Algorithm for parsing and converting mermaid code to Base64 with light ETL"
    },
    {
      "parameters": {
        "fromEmail": "DoNotReply@davidsoden.com",
        "toEmail": "={{ $('JotForm Trigger').item.json.Email }}",
        "subject": "Process Management Image URL",
        "html": "=<h2>{{ $('JotForm Trigger').item.json.Name.first }}, Thank you for telling me about your process.</h2> \n\n<p>Here is a visual representation of what you described.</p>\n<img src=\"{{ $('Process Response and encode image url').item.json['Process URL'] }}\"><p>Open this image in a browser <a href=\"{{ $('Process Response and encode image url').item.json['Process URL'] }}\">HERE</a> |Or | <a href=\"{{ $('Python Code').item.json.editURL }}\">Edit this process image in the browser </a>\n\n<h1>{{ $('JotForm Trigger').item.json.Name.first }}'s Potential Future State</h1>\n{{ $json.choices[0].message.content }}\n\n<h2>{{ $('JotForm Trigger').item.json.Name.first }} lets continue this conversation!</h2>\n<a href=\"https://outlook.office.com/bookwithme/user/62393a412fea458fbf5858e371ee84e0@concentrix.com/meetingtype/SVRwCe7HMUGxuT6WGxi68g2?anonymous&ep=mLinkFromTile\">My Calendar Availability</a>\n<p><img src=\"https://avatars.githubusercontent.com/u/36846872?v=4\" width=\"200px\"></p>\n\nDavid Soden<br>\nYour AI Specialest\n(EST) Greater Metro Atlanta Area <br>\n+1 (478) 449-4600<br>\n\n<a href=\"http://www.davidsoden.com\">DavidSoden.Com</a><br><br>\n\n\n\n",
        "options": {
          "appendAttribution": false,
          "bccEmail": "david.soden@concentrix.com"
        }
      },
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1960,
        440
      ],
      "id": "fb304cbe-e19e-4463-9bde-34fe1ebcccb0",
      "name": "Send Email to submitter",
      "notesInFlow": true,
      "webhookId": "0ac673f7-bdcf-4fab-a8c4-68f1b5b0404e",
      "credentials": {
        "smtp": {
          "id": "t9G8NB8vME51bZmK",
          "name": "SMTP-SEND-GRID"
        }
      },
      "notes": "Send an informational e-mail to the user"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer  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"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n    \"model\": \"gpt-4o-mini\",\n    \"messages\": [ \n      { \n        \"role\": \"system\", \n        \"content\": \"Generate a mermaidchart.com of type flowchart from the transcript provided. Do not any additional text, ONLY the proper mermaidchart.com code that I can paste into the live editor\" \n      },\n      { \n        \"role\": \"user\", \n        \"content\":  \"Here is what I am working on this year that’s important? {{ $json.fields.ThisYear }} And what I am focusing on in the next 90 days. {{ $json.fields.Next90Days }} My significant challenges, pain, or problems this year. {{ $json.fields.Pain }}\" \n      }\n    ], \n    \"temperature\": 0.4, \n    \"stream\": false\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        600,
        540
      ],
      "id": "2acc7fe3-e48c-4160-908e-ddbe313c6911",
      "name": "Agentic-AI (Open AI)",
      "notesInFlow": true,
      "notes": "This agents job is to translate the written process into mermaid code to be use later"
    },
    {
      "parameters": {
        "language": "python",
        "pythonCode": "import base64\nimport json\nimport zlib\nimport re\n\ndef js_string_to_byte(data):\n    return bytes(data, 'utf-8')\n\ndef js_btoa(data):\n    return base64.b64encode(data).decode('utf-8')\n\ndef pako_deflate(data):\n    compress = zlib.compressobj(9, zlib.DEFLATED, 15, 8, zlib.Z_DEFAULT_STRATEGY)\n    compressed_data = compress.compress(data)\n    compressed_data += compress.flush()\n    return compressed_data\n\ndef genPakoEditLink(graphMarkdown: str):\n    jGraph = {\n        \"code\": graphMarkdown,\n        \"mermaid\": {\"theme\": \"default\"}\n    }\n    byteStr = js_string_to_byte(json.dumps(jGraph))\n    deflated = pako_deflate(byteStr)\n    dEncode = js_btoa(deflated)\n    edit_link = 'http://mermaid.live/edit#pako:' + dEncode\n    return edit_link\n\n# ✅ Extract input from `fields`\njson_data = items[0].get(\"json\", {}).get(\"fields\", {})\n\n# ✅ Extract \"ImageURL\" (modify if needed)\nimage_url = json_data.get(\"ImageURL\", \"\")\n\n# ✅ Validate input\nif not image_url:\n    return [{\"json\": {\"error\": \"Missing ImageURL\", \"received_data\": json_data}}]\n\n# ✅ Extract the Base64 part from the URL\nmatch = re.search(r\"/img/([A-Za-z0-9+/=]+)$\", image_url)\nif not match:\n    return [{\"json\": {\"error\": \"Invalid ImageURL format\", \"received_url\": image_url}}]\n\nencoded_str = match.group(1)\n\n# ✅ Decode Base64 input properly\ntry:\n    flowchart_text = base64.b64decode(encoded_str).decode('utf-8').strip()\nexcept Exception as e:\n    return [{\"json\": {\"error\": f\"Base64 decoding failed: {str(e)}\", \"extracted_base64\": encoded_str}}]\n\n# ✅ Generate the Mermaid Live edit link\nedit_link = genPakoEditLink(flowchart_text)\n\n# ✅ Return output in the correct format for n8n\nreturn [{\"json\": {\"editURL\": edit_link}}]\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1380,
        340
      ],
      "id": "c0e1bec2-07f4-47cb-8700-629a8f4fc907",
      "name": "Python Code",
      "notesInFlow": true,
      "notes": "Custom Code needed to process a complex encoding parsing issue"
    },
    {
      "parameters": {
        "operation": "upsert",
        "base": {
          "__rl": true,
          "value": "appmN39sJ9cv5ixQc",
          "mode": "list",
          "cachedResultName": "n8n Base",
          "cachedResultUrl": "https://airtable.com/appmN39sJ9cv5ixQc"
        },
        "table": {
          "__rl": true,
          "value": "tblGwPwGCul7JVuFI",
          "mode": "list",
          "cachedResultName": "Demo Table",
          "cachedResultUrl": "https://airtable.com/appmN39sJ9cv5ixQc/tblGwPwGCul7JVuFI"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "id": "={{ $('Airtable Create').item.json.id }}",
            "ImageURL": "={{ $json['Process URL'] }}"
          },
          "matchingColumns": [
            "id"
          ],
          "schema": [
            {
              "id": "id",
              "displayName": "id",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "readOnly": true,
              "removed": false
            },
            {
              "id": "Name",
              "displayName": "Name",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Email",
              "displayName": "Email",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Your Process",
              "displayName": "Your Process",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "ImageURL",
              "displayName": "ImageURL",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2.1,
      "position": [
        1120,
        540
      ],
      "id": "a806d0ff-10c7-468c-9051-26f5bd3446b6",
      "name": "Airtable Append",
      "notesInFlow": true,
      "credentials": {
        "airtableTokenApi": {
          "id": "n8w9Pew7X9gyP08N",
          "name": "Airtable Personal Access Token account"
        }
      },
      "notes": "Circle back and append the 1st insert with the known Image encoded URL"
    },
    {
      "parameters": {
        "operation": "create",
        "base": {
          "__rl": true,
          "value": "appmN39sJ9cv5ixQc",
          "mode": "list",
          "cachedResultName": "n8n Base",
          "cachedResultUrl": "https://airtable.com/appmN39sJ9cv5ixQc"
        },
        "table": {
          "__rl": true,
          "value": "tblGwPwGCul7JVuFI",
          "mode": "list",
          "cachedResultName": "Demo Table",
          "cachedResultUrl": "https://airtable.com/appmN39sJ9cv5ixQc/tblGwPwGCul7JVuFI"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Name": "={{ $json.Name.first }} {{ $json.Name.last }}",
            "Email": "={{ $json.Email }}",
            "ThisYear": "={{ $json['1.\tWhat are you working on this year that’s important?'] }}",
            "Next90Days": "={{ $json['2.\tWhat are you focusing on in the next 90 days?'] }}",
            "Pain": "={{ $json['3.\tWhat are your most significant challenges or problems this year?'] }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Name",
              "displayName": "Name",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Email",
              "displayName": "Email",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "ThisYear",
              "displayName": "ThisYear",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Next90Days",
              "displayName": "Next90Days",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Pain",
              "displayName": "Pain",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "ImageURL",
              "displayName": "ImageURL",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2.1,
      "position": [
        400,
        320
      ],
      "id": "9574a73e-8ac4-44ed-aae2-55b73885486d",
      "name": "Airtable Create",
      "notesInFlow": true,
      "credentials": {
        "airtableTokenApi": {
          "id": "n8w9Pew7X9gyP08N",
          "name": "Airtable Personal Access Token account"
        }
      },
      "notes": "This is our database"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer  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"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n    \"model\": \"gpt-4o-mini\",\n    \"messages\": [ \n      { \n        \"role\": \"system\", \n        \"content\": \"You are a business consultant that is responsiable for Driving Operational Excellence. Tou do this by focusing on Workflow Agentic AI, new or existing. Outcome? Real company transformations at task level. {{ $('JotForm Trigger').item.json.Name.first }} will provide you a mermaid flow chart. Look for some low hanging fruit and suggest task level changes to edit or add new Agentic Workflow automations for {{ $('JotForm Trigger').item.json.Name.first }}. this would be a good place to start to have conversations on. Do NOT mention the word Mermaid. Make sure you format your output as HTML and DO NOT use Markdown formatting\" \n      },\n      { \n        \"role\": \"user\", \n        \"content\": \"Here is the chart {{ $('Agentic-AI (Open AI)').item.json.choices[0].message.content.replaceAll('```', '').replace(/(\\r\\n|\\n|\\r)/g, '. ') }}\"\n      }\n    ], \n    \"temperature\": 0.4, \n    \"stream\": false\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1660,
        560
      ],
      "id": "b8349da0-dfab-4823-a515-2b481cf923de",
      "name": "Next Steps (Open AI)",
      "notesInFlow": true,
      "notes": "This agents job is to translate the written process into mermaid code to be use later"
    },
    {
      "parameters": {
        "form": "250733821610045"
      },
      "type": "n8n-nodes-base.jotFormTrigger",
      "typeVersion": 1,
      "position": [
        120,
        440
      ],
      "id": "c03508a3-1db8-4348-ab9e-ca1b1311181f",
      "name": "JotForm Trigger",
      "webhookId": "19942d71-3f4c-4916-a587-73fd4b450f04",
      "credentials": {
        "jotFormApi": {
          "id": "bVK7YiPsnYIUrjNh",
          "name": "JotForm account"
        }
      }
    },
    {
      "parameters": {
        "content": "![](https://www.davidsoden.com/wp-content/uploads/2019/10/Logo2.png)\n# DS - Demo\nUse any front end form that has a Trigger or ability to post to a webhook or a supported database with a supported on insert trigger.\n\nThere is even a built in native form.",
        "height": 760,
        "width": 2180,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        40
      ],
      "typeVersion": 1,
      "id": "dd57c75d-66b7-482e-bfb9-38e9e7c1c799",
      "name": "Sticky Note"
    }
  ],
  "pinData": {},
  "connections": {
    "Process Response and encode image url": {
      "main": [
        [
          {
            "node": "Airtable Append",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agentic-AI (Open AI)": {
      "main": [
        [
          {
            "node": "Process Response and encode image url",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Python Code": {
      "main": [
        [
          {
            "node": "Next Steps (Open AI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Airtable Append": {
      "main": [
        [
          {
            "node": "Python Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Airtable Create": {
      "main": [
        [
          {
            "node": "Agentic-AI (Open AI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Next Steps (Open AI)": {
      "main": [
        [
          {
            "node": "Send Email to submitter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "JotForm Trigger": {
      "main": [
        [
          {
            "node": "Airtable Create",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "55b9b121-fe11-45d0-ba22-8c1e62c6903a",
  "meta": {
    "instanceId": "26112711d1e602538e53f9bd5e1222f080991c0315f0a70671e9e769f2503e86"
  },
  "id": "M4xNYHrIkhfg1w6F",
  "tags": []
}