{
  "name": "Automation of leave Message In Slack",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "e7528a4c-64f3-47f6-bead-7c13542b5522",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -20,
        -140
      ],
      "id": "33703d84-f365-477c-8400-22ad30ecd3b8",
      "name": "Webhook",
      "webhookId": "e7528a4c-64f3-47f6-bead-7c13542b5522"
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "C0996UAUG7Q",
          "mode": "list",
          "cachedResultName": "newww"
        },
        "text": "={{ $json.Message }}",
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        660,
        300
      ],
      "id": "68744f6f-0ac2-4d8f-bc49-4d2072e8b920",
      "name": "Slack1",
      "webhookId": "8c2b1ca4-d461-4a2f-a471-8abc0df1cc66",
      "credentials": {
        "slackApi": {
          "id": "Or0jGrk9y9IiMnYI",
          "name": "CT TEST"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        40,
        340
      ],
      "id": "52378972-74b4-4ac0-adf7-4ffb7a642070",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "13yojVQbhCR31vdg9BJw1maXLFMmdadlpfzo6GW8oXCk",
          "mode": "list",
          "cachedResultName": "Leave Notification",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13yojVQbhCR31vdg9BJw1maXLFMmdadlpfzo6GW8oXCk/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13yojVQbhCR31vdg9BJw1maXLFMmdadlpfzo6GW8oXCk/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Employee Name": "={{ $json.body.name }}",
            "Message": "=📢 {{ $json.body.name }} is on leave {{ $json.body.leave_date.toDate().format('yyyy-MM-dd') }} ({{ $json.body.leave_type }}). Please reach out to them once they’re back for any pending communication.",
            "Created At": "={{ $now.format('yyyy-MM-dd') }}",
            "Leave Date": "={{ $json.body.leave_date.toDateTime().format('yyyy-MM-dd') }}",
            "Is Sent": "false",
            "Schedule Date": "={{ new Date(new Date($json.body.leave_date).setDate(new Date($json.body.leave_date).getDate() - 1)).toISOString().split('T')[0] }}\n"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Sr. No.",
              "displayName": "Sr. No.",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Employee Name",
              "displayName": "Employee Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Message",
              "displayName": "Message",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Created At",
              "displayName": "Created At",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Schedule Date",
              "displayName": "Schedule Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Leave Date",
              "displayName": "Leave Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Is Sent",
              "displayName": "Is Sent",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        180,
        -140
      ],
      "id": "0a81b32b-afc7-43bd-8e80-34eec742dfab",
      "name": "Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "eG4gA0ZHKHJvLk3h",
          "name": "AJIT"
        }
      }
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "13yojVQbhCR31vdg9BJw1maXLFMmdadlpfzo6GW8oXCk",
          "mode": "list",
          "cachedResultName": "Leave Notification",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13yojVQbhCR31vdg9BJw1maXLFMmdadlpfzo6GW8oXCk/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13yojVQbhCR31vdg9BJw1maXLFMmdadlpfzo6GW8oXCk/edit#gid=0"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "Is Sent",
              "lookupValue": "false"
            },
            {
              "lookupColumn": "Schedule Date",
              "lookupValue": "={{ $now.format('yyyy-MM-dd') }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        220,
        340
      ],
      "id": "46be0f0c-dd5e-47d4-9136-b308cbc920f9",
      "name": "Google Sheets1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "eG4gA0ZHKHJvLk3h",
          "name": "AJIT"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "13yojVQbhCR31vdg9BJw1maXLFMmdadlpfzo6GW8oXCk",
          "mode": "list",
          "cachedResultName": "Leave Notification",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13yojVQbhCR31vdg9BJw1maXLFMmdadlpfzo6GW8oXCk/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13yojVQbhCR31vdg9BJw1maXLFMmdadlpfzo6GW8oXCk/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "row_number": "={{ $('Loop Over Items').item.json.row_number }}",
            "Is Sent": "true"
          },
          "matchingColumns": [
            "row_number"
          ],
          "schema": [
            {
              "id": "Sr. No.",
              "displayName": "Sr. No.",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Employee Name",
              "displayName": "Employee Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Message",
              "displayName": "Message",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Created At",
              "displayName": "Created At",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Leave Date",
              "displayName": "Leave Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Schedule Date",
              "displayName": "Schedule Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Is Sent",
              "displayName": "Is Sent",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        840,
        360
      ],
      "id": "7f8975f1-9d4d-42cb-a849-725fe841f7c5",
      "name": "Google Sheets2",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "eG4gA0ZHKHJvLk3h",
          "name": "AJIT"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        440,
        340
      ],
      "id": "5c17c2f9-3ded-424f-aa5c-48c207af1db8",
      "name": "Loop Over Items"
    },
    {
      "parameters": {
        "content": "## Workflow Overview\n\nThis workflow handles leave notifications:\n\n1.  **Webhook Trigger**: Appends new leave requests to Google Sheets.\n2.  **Scheduled Trigger**: Periodically checks for pending notifications in Google Sheets.\n3.  **Loop Over Items**: Processes each pending notification.\n4.  **Slack Integration**: Sends leave notifications to Slack.\n5.  **Google Sheets Update**: Marks notifications as sent in Google Sheets.\n\nEnsure all credentials are set up correctly for Google Sheets and Slack.",
        "height": 320,
        "width": 500
      },
      "position": [
        -660,
        -100
      ],
      "type": "n8n-nodes-base.stickyNote",
      "name": "Workflow Explanation",
      "id": "generated-cc7972c8-0374-4973-ba18-968d2e860a5b"
    },
    {
      "parameters": {
        "content": "### Webhook & Data Saving To Sheet\n\n\n- **Webhook**: Initiates the workflow when new leave data is received.\n- **Google Sheets**: Appends the incoming leave request data to the 'Leave Notification' spreadsheet, including employee name, message, creation date, leave date, and sets 'Is Sent' to false initially.",
        "height": 360,
        "width": 410,
        "color": 4
      },
      "name": "Webhook & Ingestion",
      "position": [
        -60,
        -340
      ],
      "type": "n8n-nodes-base.stickyNote",
      "id": "generated-a441b719-f0b1-41d3-8836-2b4965e172cd"
    },
    {
      "parameters": {
        "content": "### Scheduled Notification Check\n\n- **Schedule Trigger**: Runs daily at 9AM to check for leave notifications.\n- **Google Sheets1**: Reads data from the 'Leave Notification' spreadsheet, filtering for records where 'Is Sent' is 'false' and 'Schedule Date' matches the current date.",
        "height": 360,
        "width": 450,
        "color": 5
      },
      "position": [
        -80,
        160
      ],
      "name": "Scheduled Read & Filter",
      "type": "n8n-nodes-base.stickyNote",
      "id": "generated-63149889-60a3-44f0-9c3f-6c3a360e7ae3"
    },
    {
      "parameters": {
        "content": "### Process Notifications\n\n- **Loop Over Items**: Processes each pending leave notification retrieved from Google Sheets individually to ensure separate handling for each entry.",
        "height": 480,
        "width": 200,
        "color": 6
      },
      "type": "n8n-nodes-base.stickyNote",
      "name": "Batch Processing",
      "position": [
        380,
        40
      ],
      "id": "generated-1ef1ea57-7ad0-4cc9-ae60-05d2a89c8917"
    },
    {
      "parameters": {
        "content": "### Send Slack Notification\n\n- **Slack1**: Uses the processed data to send a formatted leave notification message to the specified Slack channel.",
        "height": 480,
        "width": 200,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "name": "Slack Messaging",
      "position": [
        600,
        40
      ],
      "id": "generated-48732555-4a5f-464b-8019-8deccc56556c"
    },
    {
      "parameters": {
        "content": "### Mark as Sent\n\n- **Google Sheets2**: Updates the 'Is Sent' column to 'true' for the corresponding row in the 'Leave Notification' spreadsheet, ensuring notifications are not sent multiple times.",
        "height": 480,
        "width": 180,
        "color": 7
      },
      "name": "Update Sheet Status",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        820,
        40
      ],
      "id": "generated-4b503b14-8385-4d63-b938-c0aeb9e0ceaa"
    }
  ],
  "pinData": {},
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack1": {
      "main": [
        [
          {
            "node": "Google Sheets2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets2": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Slack1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "60a3a966-2e2a-4d97-a229-c7eea8c529cc",
  "meta": {
    "instanceId": "efafddee18311adedbf2c57999fc58fea621aaaa17e22321d4e54dfbe25b7bd5"
  },
  "id": "rqfWId6S5Z1b97ky",
  "tags": []
}