{
  "name": "Turn every incoming WhatsApp message into a CRM lead — and answer it instantly",
  "nodes": [
    {
      "parameters": {
        "content": "## Turn every incoming WhatsApp message into a CRM lead — and answer it instantly\n\nWhat you get: a lead (or a note on the existing contact) in your CRM for every first message, plus an immediate acknowledgement to the customer.\nWhat it replaces: copying phone numbers from your phone into the CRM, and messages that sit unanswered for hours.\nSetup time: about 10 minutes.\n\nNothing your customers write on WhatsApp gets lost outside the CRM again.\n\nWorks with a normal WhatsApp number — no Meta Business account needed.\n\nSetup:\n1. Install the community node: n8n Settings -> Community Nodes -> npm package `n8n-nodes-wasync`.\n2. Create a free WASync account at https://developers.wasync.app/register, connect a WhatsApp number, then create an API key at https://developers.wasync.app/keys.\n3. In n8n, add a new \"WASync API\" credential using that key.\n4. Open the \"Settings\" node at the top of this workflow and fill in your own values. Never commit real portal URLs, tokens, or phone numbers.\n\nDocs: https://docs.wasync.app/docs/guides/n8n?utm_source=n8n&utm_medium=template&utm_campaign=t2",
        "height": 500,
        "width": 1560
      },
      "name": "Read Me First",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -140,
        -580
      ]
    },
    {
      "parameters": {
        "content": "**① Trigger**\nFires on every inbound WhatsApp message.",
        "height": 322,
        "width": 280,
        "color": 7
      },
      "name": "① Trigger",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -140,
        404
      ]
    },
    {
      "parameters": {
        "content": "**② CRM lookup**\nLooks the sender up by phone number and creates a lead\nwhen nobody matches. Known contacts skip straight to the reply.",
        "height": 322,
        "width": 920,
        "color": 7
      },
      "name": "② CRM lookup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        180,
        404
      ]
    },
    {
      "parameters": {
        "content": "**③ Send on WhatsApp**\nEvery first message gets an immediate acknowledgement,\nnew contact or not.",
        "height": 322,
        "width": 280,
        "color": 7
      },
      "name": "③ Send on WhatsApp",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1140,
        404
      ]
    },
    {
      "parameters": {
        "content": "**Settings — fill these in**\nPlaceholders only — replace every value here before you activate the\nworkflow. Nothing else in the workflow needs editing.\nFields: bitrixPortalUrl, bitrixWebhookToken.",
        "height": 344,
        "width": 600,
        "color": 7
      },
      "name": "Settings — fill these in",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -140,
        0
      ]
    },
    {
      "parameters": {
        "events": [
          "message.received"
        ]
      },
      "name": "Receive WhatsApp Message",
      "type": "n8n-nodes-wasync.wasyncTrigger",
      "typeVersion": 1,
      "position": [
        0,
        606
      ],
      "credentials": {
        "wasyncApi": {
          "name": "WASync account"
        }
      }
    },
    {
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "Settings-0",
              "name": "bitrixPortalUrl",
              "value": "https://yourportal.bitrix24.com",
              "type": "string"
            },
            {
              "id": "Settings-1",
              "name": "bitrixWebhookToken",
              "value": "REPLACE_WITH_YOUR_INBOUND_WEBHOOK_TOKEN",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        0,
        224
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{ $('Settings').item.json.bitrixPortalUrl }}/rest/{{ $('Settings').item.json.bitrixWebhookToken }}/crm.contact.list",
        "options": {},
        "sendQuery": true,
        "specifyQuery": "keypair",
        "queryParameters": {
          "parameters": [
            {
              "name": "filter[PHONE]",
              "value": "={{ $('Receive WhatsApp Message').item.json.message.from }}"
            },
            {
              "name": "select[]",
              "value": "ID"
            }
          ]
        }
      },
      "name": "Find Contact in Bitrix24",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        320,
        606
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "Contact Not Found?-cond0",
              "leftValue": "={{ $json.result ? $json.result.length : 0 }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "equal"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "name": "Contact Not Found?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        640,
        606
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Settings').item.json.bitrixPortalUrl }}/rest/{{ $('Settings').item.json.bitrixWebhookToken }}/crm.lead.add",
        "sendBody": true,
        "contentType": "json",
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ fields: { NAME: 'WhatsApp ' + $('Receive WhatsApp Message').item.json.message.from, PHONE: [{ VALUE: $('Receive WhatsApp Message').item.json.message.from, VALUE_TYPE: 'WORK' }], COMMENTS: $('Receive WhatsApp Message').item.json.message.text, SOURCE_ID: 'WHATSAPP' } }) }}",
        "options": {}
      },
      "name": "Create Lead in Bitrix24",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        960,
        606
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "send",
        "connectionId": "={{ $('Receive WhatsApp Message').item.json.connection_id }}",
        "to": "={{ $('Receive WhatsApp Message').item.json.message.from }}",
        "text": "=Thanks, we'll get back to you within 1 hour.",
        "additionalFields": {}
      },
      "name": "Send Auto-Reply on WhatsApp",
      "type": "n8n-nodes-wasync.wasync",
      "typeVersion": 1,
      "position": [
        1280,
        606
      ],
      "credentials": {
        "wasyncApi": {
          "name": "WASync account"
        }
      }
    }
  ],
  "connections": {
    "Receive WhatsApp Message": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Find Contact in Bitrix24",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Contact in Bitrix24": {
      "main": [
        [
          {
            "node": "Contact Not Found?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Contact Not Found?": {
      "main": [
        [
          {
            "node": "Create Lead in Bitrix24",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Auto-Reply on WhatsApp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Lead in Bitrix24": {
      "main": [
        [
          {
            "node": "Send Auto-Reply on WhatsApp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
