{
  "name": "WhatSync: group message alert (WhatSync node)",
  "nodes": [
    {
      "parameters": {
        "events": [
          "message.received"
        ],
        "filters": {
          "chatType": "group"
        }
      },
      "name": "WhatsApp event",
      "type": "n8n-nodes-whatsync.whatSyncTrigger",
      "typeVersion": 1,
      "position": [
        220,
        0
      ],
      "id": "9e0b1f9a-09a9-4ba4-a9b8-11d12bfdfc9c",
      "webhookId": "98653524-bb81-4a38-acc0-142e31c2e7bf",
      "credentials": {
        "whatSyncApi": {
          "id": "WHATSYNC_NODE_CREDENTIAL",
          "name": "WhatSync API"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "fd6d7546-de46-4a4c-a30f-03b89e5ef555",
              "name": "whatsyncUrl",
              "value": "https://whatsync.app",
              "type": "string"
            },
            {
              "id": "06e34b19-3946-43cf-a332-851557025a81",
              "name": "alertUrl",
              "value": "https://hooks.slack.com/services/REPLACE/WITH/YOURS",
              "type": "string"
            },
            {
              "id": "6b5945b0-1a63-49f5-aee5-b8ad5dea9d35",
              "name": "groupId",
              "value": "",
              "type": "string"
            },
            {
              "id": "358d9e0f-ca1c-417b-ade6-5f864e03d61f",
              "name": "replyText",
              "value": "Received",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        440,
        0
      ],
      "id": "d7e2d317-cdf1-450d-a077-6e563832447e",
      "notes": "groupId: one group's id from list_groups (ends in @g.us), or empty for every saved group. replyText: empty to post nothing in the group."
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "cc3a56df-492c-41ef-ade8-b950dee325c3",
              "leftValue": "={{ $json.type }}",
              "rightValue": "message.received",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "9aabe5e9-4b1b-4924-a487-2b3e41b8947a",
              "leftValue": "={{ $json.data.message.chat_type }}",
              "rightValue": "group",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "aa457989-b08c-4485-a115-6e833ecadd1a",
              "leftValue": "={{ $json.data.message.from_me }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            },
            {
              "id": "59bbd24f-fea4-453a-ad69-0b702547a5fa",
              "leftValue": "={{ $json.data.message.text }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            },
            {
              "id": "c9a20371-4262-48f2-ac7a-72fb07b8f153",
              "leftValue": "={{ !$json.groupId || $json.data.message.group.id === $json.groupId }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "name": "From the group?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        660,
        0
      ],
      "id": "eca69068-2df4-4d81-a3f2-13c073367bdf"
    },
    {
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "logic": "removeItemsWithAlreadySeenKeyValues",
        "dedupeValue": "={{ $json.id }}",
        "options": {
          "scope": "workflow",
          "historySize": 10000
        }
      },
      "name": "Skip repeats",
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        880,
        0
      ],
      "id": "6aec3923-432a-4931-a24a-fa09ea489df9",
      "notes": "Remembers the last 10,000 event ids across runs and drops an event it has already seen."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Settings').first().json.alertUrl }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: '[' + ($json.data.message.group.name || 'WhatsApp group') + '] ' + ($json.data.message.from.name || '+' + $json.data.message.from.phone) + ': ' + $json.data.message.text }) }}",
        "options": {
          "timeout": 15000
        }
      },
      "name": "Tell the team",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1100,
        -120
      ],
      "id": "27c20480-f576-4824-a618-4f56fd9c6414",
      "notes": "Works as is with a Slack incoming webhook. Swap this node for Email, Telegram or anything else that reaches a person."
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "622cc993-5875-4586-a02c-14decae13a1a",
              "leftValue": "={{ $json.replyText }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "name": "Reply in the group?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1100,
        100
      ],
      "id": "5b4646a5-c7b9-43dc-aa54-d0df6c57c120"
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "PICK_THE_SAFE_SEND_WORKFLOW",
          "mode": "list",
          "cachedResultName": "WhatSync: safe send"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {
            "tool": "send_group_message",
            "body": "={{ { \"jid\": $json.data.message.group.id, \"text\": $json.replyText + ': \"' + $json.data.message.text.replace(/\\s+/g, ' ').slice(0, 80) + '\"' } }}",
            "idempotencyKey": "={{ $json.id }}"
          },
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true,
          "schema": [
            {
              "id": "tool",
              "displayName": "tool",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            },
            {
              "id": "body",
              "displayName": "body",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "object"
            },
            {
              "id": "idempotencyKey",
              "displayName": "idempotencyKey",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "canBeUsedToMatch": true,
              "type": "string"
            }
          ]
        },
        "mode": "each",
        "options": {
          "waitForSubWorkflow": true
        }
      },
      "name": "Send group reply",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "position": [
        1320,
        100
      ],
      "id": "b9fc0c5f-eeb8-455d-a599-90b14636eaa3"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "631bf3e6-5092-480f-ae40-d4308cc54716",
              "leftValue": "={{ $json.ok }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "name": "Reply failed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1540,
        100
      ],
      "id": "7246bf22-af64-4e54-ac35-89787668cb4a"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Settings').first().json.alertUrl }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: 'A WhatsApp group reply did NOT go out (' + $json.outcome + ', ' + $json.code + '). ' + ($json.message || '') + ($json.outcome === 'unknown' ? ' It may have been sent. Check WhatsApp before sending it by hand.' : '') }) }}",
        "options": {
          "timeout": 15000
        }
      },
      "name": "Alert: reply not sent",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1760,
        100
      ],
      "id": "129993de-a3be-410c-ab0f-bf0d1a090b76",
      "notes": "Works as is with a Slack incoming webhook. Swap this node for Email, Telegram or anything else that reaches a person."
    },
    {
      "parameters": {
        "content": "## WhatsApp group message: tell the team and answer \"Received\"\nWhen someone posts in a group, the team gets the message in Slack or email and the group gets a short \"Received\" that quotes the message.\n\n**Set up**\n1. Import **WhatSync: safe send** first and publish it. Pick it in **Send group reply**.\n2. Pick your **WhatSync API** credential in **WhatsApp event**.\n3. Fill in **Settings**: alert URL, and the group id if you want one group only.\n4. Publish. The trigger adds the webhook in WhatSync for you.\n\nThe reply quotes the message because WhatSync refuses the same text to the same group twice within an hour.\nGuide: https://whatsync.app/docs/guides/group-message-alert",
        "height": 290,
        "width": 600,
        "color": 4
      },
      "name": "Read me",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        0,
        -370
      ],
      "id": "f265a16c-591b-4496-abfc-5802e33d7dbe"
    }
  ],
  "connections": {
    "WhatsApp event": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "From the group?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "From the group?": {
      "main": [
        [
          {
            "node": "Skip repeats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Skip repeats": {
      "main": [
        [
          {
            "node": "Tell the team",
            "type": "main",
            "index": 0
          },
          {
            "node": "Reply in the group?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply in the group?": {
      "main": [
        [
          {
            "node": "Send group reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send group reply": {
      "main": [
        [
          {
            "node": "Reply failed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Reply failed?": {
      "main": [
        [
          {
            "node": "Alert: reply not sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
