{
  "name": "Contact Form to CRM + Slack Alert",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "contact-form",
        "options": {
          "responseMode": "onReceived",
          "responseData": "allEntries"
        }
      },
      "id": "webhook-trigger",
      "name": "Receive Form Submission",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [220, 300],
      "webhookId": "contact-form-webhook"
    },
    {
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "firstName",
              "name": "firstName",
              "value": "={{ $json.body.firstName || $json.body.first_name || $json.body.name?.split(' ')[0] || '' }}",
              "type": "string"
            },
            {
              "id": "lastName",
              "name": "lastName",
              "value": "={{ $json.body.lastName || $json.body.last_name || $json.body.name?.split(' ').slice(1).join(' ') || '' }}",
              "type": "string"
            },
            {
              "id": "email",
              "name": "email",
              "value": "={{ $json.body.email }}",
              "type": "string"
            },
            {
              "id": "phone",
              "name": "phone",
              "value": "={{ $json.body.phone || $json.body.telephone || '' }}",
              "type": "string"
            },
            {
              "id": "message",
              "name": "message",
              "value": "={{ $json.body.message || $json.body.inquiry || $json.body.comments || '' }}",
              "type": "string"
            },
            {
              "id": "source",
              "name": "source",
              "value": "={{ $json.body.source || 'Website Contact Form' }}",
              "type": "string"
            },
            {
              "id": "submittedAt",
              "name": "submittedAt",
              "value": "={{ $now.toISO() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "normalize-data",
      "name": "Normalize Form Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [440, 300]
    },
    {
      "parameters": {
        "resource": "contact",
        "operation": "upsert",
        "email": "={{ $json.email }}",
        "additionalFields": {
          "firstName": "={{ $json.firstName }}",
          "lastName": "={{ $json.lastName }}",
          "phone": "={{ $json.phone }}",
          "company": "",
          "customPropertiesUi": {
            "customPropertiesValues": [
              {
                "property": "message",
                "value": "={{ $json.message }}"
              },
              {
                "property": "hs_lead_status",
                "value": "NEW"
              }
            ]
          }
        },
        "options": {}
      },
      "id": "hubspot-contact",
      "name": "Create/Update Contact in HubSpot",
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2,
      "position": [660, 220],
      "credentials": {
        "hubspotApi": {
          "id": "YOUR_HUBSPOT_CREDENTIAL_ID",
          "name": "HubSpot account"
        }
      }
    },
    {
      "parameters": {
        "resource": "message",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "YOUR_SLACK_CHANNEL_ID",
          "mode": "id"
        },
        "messageType": "block",
        "blocksUi": {
          "blocksValues": [
            {
              "type": "header",
              "text": {
                "type": "plain_text",
                "text": "New Contact Form Submission",
                "emoji": true
              }
            },
            {
              "type": "section",
              "fields": [
                {
                  "type": "mrkdwn",
                  "text": "*Name:*\n={{ $('Normalize Form Data').item.json.firstName }} {{ $('Normalize Form Data').item.json.lastName }}"
                },
                {
                  "type": "mrkdwn",
                  "text": "*Email:*\n={{ $('Normalize Form Data').item.json.email }}"
                }
              ]
            },
            {
              "type": "section",
              "fields": [
                {
                  "type": "mrkdwn",
                  "text": "*Phone:*\n={{ $('Normalize Form Data').item.json.phone || 'Not provided' }}"
                },
                {
                  "type": "mrkdwn",
                  "text": "*Received:*\n={{ $('Normalize Form Data').item.json.submittedAt }}"
                }
              ]
            },
            {
              "type": "divider"
            },
            {
              "type": "section",
              "text": {
                "type": "mrkdwn",
                "text": "*Message:*\n={{ $('Normalize Form Data').item.json.message || 'No message provided' }}"
              }
            },
            {
              "type": "divider"
            },
            {
              "type": "context",
              "elements": [
                {
                  "type": "mrkdwn",
                  "text": "Source: {{ $('Normalize Form Data').item.json.source }} | <{{ $('Create/Update Contact in HubSpot').item.json.properties?.hs_object_id ? 'https://app.hubspot.com/contacts/' + $('Create/Update Contact in HubSpot').item.json.properties?.hs_object_id : '#' }}|View in HubSpot>"
                }
              ]
            }
          ]
        },
        "otherOptions": {
          "unfurl_links": false,
          "unfurl_media": false
        }
      },
      "id": "slack-notification",
      "name": "Send Slack Alert",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [880, 300],
      "credentials": {
        "slackApi": {
          "id": "YOUR_SLACK_CREDENTIAL_ID",
          "name": "Slack account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "status",
              "name": "status",
              "value": "success",
              "type": "string"
            },
            {
              "id": "contact_email",
              "name": "contact_email",
              "value": "={{ $('Normalize Form Data').item.json.email }}",
              "type": "string"
            },
            {
              "id": "contact_name",
              "name": "contact_name",
              "value": "={{ $('Normalize Form Data').item.json.firstName }} {{ $('Normalize Form Data').item.json.lastName }}",
              "type": "string"
            },
            {
              "id": "hubspot_created",
              "name": "hubspot_created",
              "value": true,
              "type": "boolean"
            },
            {
              "id": "slack_notified",
              "name": "slack_notified",
              "value": true,
              "type": "boolean"
            }
          ]
        },
        "options": {}
      },
      "id": "set-output",
      "name": "Set Success Output",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [1100, 300]
    },
    {
      "parameters": {
        "resource": "message",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "YOUR_SLACK_CHANNEL_ID",
          "mode": "id"
        },
        "text": "Failed to add contact to HubSpot: {{ $('Normalize Form Data').item.json.email }}. Error: {{ $json.message || 'Unknown error' }}",
        "otherOptions": {}
      },
      "id": "slack-error",
      "name": "Notify Error on Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [880, 480],
      "credentials": {
        "slackApi": {
          "id": "YOUR_SLACK_CREDENTIAL_ID",
          "name": "Slack account"
        }
      }
    }
  ],
  "connections": {
    "Receive Form Submission": {
      "main": [
        [
          {
            "node": "Normalize Form Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Form Data": {
      "main": [
        [
          {
            "node": "Create/Update Contact in HubSpot",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create/Update Contact in HubSpot": {
      "main": [
        [
          {
            "node": "Send Slack Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Slack Alert": {
      "main": [
        [
          {
            "node": "Set Success Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "errorWorkflow": ""
  },
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": false,
    "instanceId": "uzunu-automation-templates"
  },
  "pinData": {},
  "versionId": "1",
  "triggerCount": 1,
  "tags": [
    {
      "name": "lead-management",
      "id": "lead-management"
    },
    {
      "name": "notifications",
      "id": "notifications"
    },
    {
      "name": "crm",
      "id": "crm"
    },
    {
      "name": "slack",
      "id": "slack"
    }
  ]
}
