{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Forward Slack Channel Messages to WhatsApp with MoltFlow",
  "tags": [
    {
      "name": "whatsapp"
    },
    {
      "name": "slack"
    },
    {
      "name": "notifications"
    },
    {
      "name": "moltflow"
    },
    {
      "name": "team"
    }
  ],
  "nodes": [
    {
      "id": "k1000001-0000-4000-0b00-000000000010",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        -300
      ],
      "parameters": {
        "color": 4,
        "width": 400,
        "height": 300,
        "content": "## Slack \u2192 WhatsApp Forwarder\nForward important Slack messages to WhatsApp so you never miss critical updates, powered by [MoltFlow](https://molt.waiflow.app).\n\n**How it works:**\n1. Slack sends a webhook when a message is posted in a channel\n2. The message text and sender are extracted\n3. A formatted message is forwarded to your WhatsApp number\n4. Stay on top of Slack without checking the app"
      },
      "typeVersion": 1
    },
    {
      "id": "k1000001-0000-4000-0b00-000000000011",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        -300
      ],
      "parameters": {
        "color": 5,
        "width": 400,
        "height": 260,
        "content": "## Setup (5 min)\n1. Create a [MoltFlow account](https://molt.waiflow.app) and connect WhatsApp\n2. Activate this workflow \u2014 copy the webhook URL\n3. In Slack \u2192 Apps \u2192 Incoming Webhooks (or use Slack API), configure an outgoing webhook to this n8n URL\n4. Set `YOUR_SESSION_ID` and `YOUR_PHONE` in the Format Message node\n5. Add MoltFlow API Key: Header Auth \u2192 `X-API-Key`\n\n**Tip:** Filter by channel or keywords in the code node"
      },
      "typeVersion": 1
    },
    {
      "id": "k1000001-0000-4000-0b00-000000000001",
      "name": "Slack Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        0,
        0
      ],
      "parameters": {
        "path": "slack-forward",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "k1000001-0000-4000-0b00-000000000002",
      "name": "Format Message",
      "type": "n8n-nodes-base.code",
      "position": [
        220,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const SESSION_ID = 'YOUR_SESSION_ID';\nconst MY_PHONE = 'YOUR_PHONE';\n\nconst body = $input.first().json.body || $input.first().json;\n\nif (body.challenge) {\n  return [{ json: { challenge: body.challenge } }];\n}\n\nconst event = body.event || body;\nconst text = event.text || event.message || '';\nconst user = event.user_name || event.user || 'Someone';\nconst channel = event.channel_name || event.channel || 'a channel';\n\nif (!text) {\n  return [{ json: { skip: true, reason: 'Empty message' } }];\n}\n\nconst message = `*Slack \u2014 #${channel}*\\n${user}: ${text}`;\n\nreturn [{\n  json: {\n    session_id: SESSION_ID,\n    chat_id: MY_PHONE + '@c.us',\n    message: message,\n    channel: channel,\n    sender: user,\n    skip: false\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "k1000001-0000-4000-0b00-000000000003",
      "name": "Valid?",
      "type": "n8n-nodes-base.if",
      "position": [
        440,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "not-skip",
              "operator": {
                "type": "boolean",
                "operation": "equals"
              },
              "leftValue": "={{ $json.skip }}",
              "rightValue": false
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "k1000001-0000-4000-0b00-000000000004",
      "name": "Send to WhatsApp",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        660,
        -100
      ],
      "parameters": {
        "url": "https://apiv2.waiflow.app/api/v2/messages/send",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ JSON.stringify({ session_id: $json.session_id, chat_id: $json.chat_id, message: $json.message }) }}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "k1000001-0000-4000-0b00-000000000005",
      "name": "Log",
      "type": "n8n-nodes-base.code",
      "position": [
        880,
        -100
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const data = $('Format Message').first().json;\nreturn [{ json: { status: 'forwarded', channel: data.channel, from: data.sender } }];"
      },
      "typeVersion": 2
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "Valid?": {
      "main": [
        [
          {
            "node": "Send to WhatsApp",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Slack Webhook": {
      "main": [
        [
          {
            "node": "Format Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Message": {
      "main": [
        [
          {
            "node": "Valid?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send to WhatsApp": {
      "main": [
        [
          {
            "node": "Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}