Quick Overview
This workflow receives leave requests via a webhook, validates them against employee and historical request data in Google Sheets, runs an AI check through the Groq API, then emails the manager for approval and updates Google Sheets and the employee via Gmail.
How it works
- Receives a leave request submission via a webhook.
- Extracts the request fields (email, start date, end date, and reason) and reads employee and existing leave-request records from Google Sheets.
- Calculates working days, checks the requester exists, enforces same-year leave dates, and validates the request against remaining balance and overlapping team leave.
- Returns an immediate JSON error response to the webhook caller if validation fails, or returns a JSON success response if it passes.
- Sends the request details to the Groq chat completions API to flag empty/abusive/inconsistent reasons and produce a short AI note.
- Appends the request as “Pending” to the Requests sheet in Google Sheets and emails the manager via Gmail with an approval link and context (balance, AI note, and teammates off).
- If the manager approves, updates the request status to “Approved” in Google Sheets and emails the employee an approval confirmation; otherwise, updates the status to “Rejected” and emails the employee a rejection notice.
Setup
- Configure the webhook endpoint (path:
leave-request, method: POST) in your leave request form/app and send the fields Email, Start, End, and Reason in the request body.
- Connect Google Sheets OAuth2 credentials and update the spreadsheet and sheet tabs to match your Employees and Requests structure (including columns like Email, Name, ManagerEmail, AnnualAllowance, StartDate, EndDate, Days, Status, and AI_Note).
- Add an HTTP Header Auth credential for the Groq API (Authorization bearer token) and confirm the model/endpoint settings used in the HTTP request.
- Connect Gmail OAuth2 credentials and confirm the sender account and email templates for manager approval and employee notifications.