{
  "name": "Threadwire: save incoming WhatsApp messages to Google Sheets",
  "nodes": [
    {
      "parameters": {
        "content": "## Save incoming WhatsApp messages to a sheet\n1. Make a Google Sheet with the columns **Time**, **Instance**, **Phone**, **Message** and **Type** in the first row, and choose it in *Add a row*.\n2. Activate this workflow and copy the **Production URL** of *Threadwire event*.\n3. In your Threadwire panel, under **Developers → Webhooks** (admins only), set that as your webhook URL. Leave the events there as they are: *Someone wrote* already keeps only `message.received`. The events are one list for your whole account, so un-ticking the others would switch them off for every other system too.\n\n**Lock the address:** on the same page set an **Authentication header** (a name and a secret value of yours), and in *Threadwire event* set Authentication to **Header Auth** with that name and value. n8n then refuses anyone else who posts to it.",
        "width": 520,
        "height": 400
      },
      "id": "5c9c5ebd-0cba-500d-87f7-790e0e356e3d",
      "name": "How it works",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -60,
        -440
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "threadwire-to-sheets",
        "responseMode": "onReceived",
        "options": {}
      },
      "id": "0ca095df-9fc3-5022-bd32-bc1f8b6efdc6",
      "name": "Threadwire event",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        0
      ],
      "webhookId": "68a5ec05-e0bd-5368-9581-d035ddc64272"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "3326f8a9-1cf7-5731-92ec-85b5b96cf461",
              "leftValue": "={{ $json.body.type }}",
              "rightValue": "message.received",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "7a939f53-4d72-5f81-8996-6ea5fec450f8",
      "name": "Someone wrote",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "31f0a7bf-1aa9-5c76-868a-81b3523305e2",
              "name": "Time",
              "value": "={{ $json.body.data.created_at }}",
              "type": "string"
            },
            {
              "id": "dfab4fe4-0cbc-5b68-aad6-0ea191b008b1",
              "name": "Instance",
              "value": "={{ $json.body.data.instance_id }}",
              "type": "string"
            },
            {
              "id": "e53570a4-999f-5e3b-9732-cb558ab60c52",
              "name": "Phone",
              "value": "={{ $json.body.data.phone ? '+' + $json.body.data.phone : '' }}",
              "type": "string"
            },
            {
              "id": "0aa5d80b-43ac-5006-bbc1-3ef22574c2fb",
              "name": "Message",
              "value": "={{ $json.body.data.body ?? '' }}",
              "type": "string"
            },
            {
              "id": "ce06de43-f945-5a31-b1d8-a09b7c2a1a8a",
              "name": "Type",
              "value": "={{ $json.body.data.type }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "89b61e5f-8878-59ca-9215-90e0cee20a2c",
      "name": "Pick the columns",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        460,
        -20
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "sheetName": {
          "__rl": true,
          "value": "",
          "mode": "list"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": []
        },
        "options": {}
      },
      "id": "7275d177-6c63-57d5-90f8-10dbc922d940",
      "name": "Add a row",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        680,
        -20
      ]
    }
  ],
  "connections": {
    "Threadwire event": {
      "main": [
        [
          {
            "node": "Someone wrote",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Someone wrote": {
      "main": [
        [
          {
            "node": "Pick the columns",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Pick the columns": {
      "main": [
        [
          {
            "node": "Add a row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
