{
  "name": "Incoming WhatsApp (WbizTool) -> Pipedrive note",
  "nodes": [
    {
      "id": "45d3ac59-5475-4b33-9ad6-1087a6f049f7",
      "name": "Webhook from WbizTool",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "webhookId": "d2cd1a8b-903d-406a-a260-4e339c0c3df4",
      "parameters": {
        "httpMethod": "POST",
        "path": "wbiztool-pipedrive-notes",
        "responseMode": "onReceived",
        "options": {}
      }
    },
    {
      "id": "3ae61d31-5297-48a8-8e5f-a294155c6596",
      "name": "A person's incoming message?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        240,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "445c5ded-6986-4825-9625-7a956e40f789",
              "leftValue": "={{ $json.body.event }}",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "rightValue": "message_received"
            },
            {
              "id": "1d3c4b08-0168-401a-94e0-ab613cef3fcf",
              "leftValue": "={{ $json.body.contact.is_group }}",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              },
              "rightValue": ""
            },
            {
              "id": "7b38dae9-099e-4dec-a8d6-6c2e6b1e493d",
              "leftValue": "={{ $json.body.contact.phone_hidden }}",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              },
              "rightValue": ""
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "73c1ede3-88f4-4b00-936a-941503b53dad",
      "name": "Search the person by phone",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        480,
        -100
      ],
      "alwaysOutputData": true,
      "parameters": {
        "authentication": "apiToken",
        "resource": "person",
        "operation": "search",
        "term": "={{ $json.body.contact.phone }}",
        "exactMatch": false,
        "returnAll": false,
        "limit": 1,
        "additionalFields": {
          "fields": [
            "phone"
          ]
        }
      }
    },
    {
      "id": "3708be47-1deb-4995-882c-34cca6a6aefc",
      "name": "Person found?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        720,
        -100
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "ad87e855-9c94-465f-8b25-a3796943cb9e",
              "leftValue": "={{ $json.id }}",
              "operator": {
                "type": "number",
                "operation": "exists",
                "singleValue": true
              },
              "rightValue": ""
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "4857a8cf-f707-4e3d-b5f8-9a97e9b92c7c",
      "name": "Add the note",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        960,
        -200
      ],
      "parameters": {
        "authentication": "apiToken",
        "resource": "note",
        "operation": "create",
        "content": "=WhatsApp from {{ $('Webhook from WbizTool').first().json.body.contact.name || $('Webhook from WbizTool').first().json.body.contact.phone }} (+{{ $('Webhook from WbizTool').first().json.body.contact.phone }}), {{ $('Webhook from WbizTool').first().json.body.message.timestamp }}:<br>{{ $('Webhook from WbizTool').first().json.body.message.content }}",
        "additionalFields": {
          "person_id": "={{ $json.id }}"
        }
      }
    },
    {
      "id": "167377f3-655a-47fb-bad8-978bdf2cd220",
      "name": "Create the person",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        960,
        0
      ],
      "parameters": {
        "authentication": "apiToken",
        "resource": "person",
        "operation": "create",
        "name": "={{ $('Webhook from WbizTool').first().json.body.contact.name || $('Webhook from WbizTool').first().json.body.contact.phone }}",
        "additionalFields": {
          "phones": {
            "phoneProperties": [
              {
                "value": "=+{{ $('Webhook from WbizTool').first().json.body.contact.phone }}",
                "primary": true,
                "label": "mobile"
              }
            ]
          }
        }
      }
    },
    {
      "id": "4f1f8cdb-110a-404e-97b3-8018e7f67553",
      "name": "Add the note to the new person",
      "type": "n8n-nodes-base.pipedrive",
      "typeVersion": 2,
      "position": [
        1200,
        0
      ],
      "parameters": {
        "authentication": "apiToken",
        "resource": "note",
        "operation": "create",
        "content": "=WhatsApp from {{ $('Webhook from WbizTool').first().json.body.contact.name || $('Webhook from WbizTool').first().json.body.contact.phone }} (+{{ $('Webhook from WbizTool').first().json.body.contact.phone }}), {{ $('Webhook from WbizTool').first().json.body.message.timestamp }}:<br>{{ $('Webhook from WbizTool').first().json.body.message.content }}",
        "additionalFields": {
          "person_id": "={{ $json.id }}"
        }
      }
    }
  ],
  "connections": {
    "Webhook from WbizTool": {
      "main": [
        [
          {
            "node": "A person's incoming message?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "A person's incoming message?": {
      "main": [
        [
          {
            "node": "Search the person by phone",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Search the person by phone": {
      "main": [
        [
          {
            "node": "Person found?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Person found?": {
      "main": [
        [
          {
            "node": "Add the note",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create the person",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create the person": {
      "main": [
        [
          {
            "node": "Add the note to the new person",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "tags": [],
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
