πŸ’¬ Detect at-risk gym clients with Supabase, Gemini, Slack, Gmail, and Sheets

⚑ 19 views Β· πŸ’¬ Lead Nurturing & AI Sales Agents

Description

Quick overview

This workflow runs on a daily schedule to detect at-risk gym clients using Supabase activity data, drafts a re-engagement email with Google Gemini, notifies coaches in Slack, emails clients via Gmail, and logs and syncs alert state to Supabase and Google Sheets.

How it works

  1. Runs daily on a schedule trigger.
  2. Loads active clients plus the last 14 days of check-ins and last 21 days of weekly form submissions from Supabase.
  3. Merges the datasets per client and calculates engagement metrics (days since last check-in/form, weekly check-in count, missed activities), a risk score/type, and escalation/cooldown timing.
  4. Filters to high-risk clients and blocks alerts if the client is still inside the duplicate-alert cooldown window.
  5. Builds a personalized prompt and uses Google Gemini to generate a short JSON email draft (subject and body), then formats a coach-facing Slack summary.
  6. Sends a Slack alert to the coach channel and a Gmail message to the client, then logs the risk event to a Supabase table and appends the same record to a Google Sheets log.
  7. Updates the client’s alert state and escalation fields in Supabase and syncs those fields back to a Google Sheets client master sheet.

Setup

  1. Add Supabase credentials and ensure the clients, checkins, weekly_forms, and risk_events tables and required columns (including status, expected check-ins/forms, coach/contact fields, and last alert timestamps) exist.
  2. Add Google Gemini (PaLM) API credentials and confirm the model node is allowed to call models/gemini-2.5-flash.
  3. Add Slack credentials and set the target channel ID for coach alerts.
  4. Add Gmail OAuth credentials for the sending mailbox.
  5. Add Google Sheets credentials and update the spreadsheet ID and sheet names/columns for Clients_Master and Risk_Alert_Log to match your document.
  6. Set the schedule trigger time and, if needed, adjust the lookback windows (14 days for check-ins, 21 days for forms) and cooldown duration (3 days) in the workflow logic.

Additional info

Add Ons

This workflow can be extended with several useful enhancements:

Use Case Examples

This workflow supports several practical use cases, and there can be many more depending on the business process around it:

Troubleshooting Guide

IssuePossible CauseSolution
No clients move past the triggerSupabase credentials are invalid or the clients table has no active recordsCheck the Supabase connection and confirm active rows exist in the clients table.
Merge output looks incompleteOne of the three source nodes is returning no records or a filter is too restrictiveTest each Supabase read node separately and review the date filters for checkins and weekly_forms.
No clients pass the risk filterThe risk score logic does not produce records that meet the current thresholdReview the JavaScript in Calculate Client Risk Metrics and test with sample data that should clearly qualify.
Clients are skipped unexpectedlyThe cooldown logic is blocking them because alert_allowed_now is falseCheck last_alert_sent_at values and confirm the cooldown rule in the Code node matches your intended timing.
Gemini output fails to parseThe model response is not valid JSON or contains extra formattingTighten the prompt, keep the JSON only instruction, and inspect the Parse Draft Response node output.
Slack messages are not sentSlack credentials, channel selection, or app permissions are incorrectReconnect Slack credentials, verify the target channel, and confirm the app can post messages.
Gmail emails are not sentGmail OAuth is disconnected or sender permissions are incompleteReauthenticate Gmail credentials and send a direct test email from the node.
Google Sheets append or update failsSheet name, spreadsheet ID, or mapped columns do not match the actual fileReopen the Sheets nodes and confirm the selected spreadsheet, tab, and column mapping are correct.
Supabase update does not change client statusThe update filter does not match the intended client rowConfirm that client_id values match exactly between the workflow output and the clients table.

Need Help

If you need help importing this workflow, connecting credentials, adjusting the risk logic, refining the Gemini prompt or extending the workflow with additional channels and dashboards, support from an experienced n8n team can make the setup faster and more reliable. WeblineIndia can help with workflow deployment, custom business rules, reporting extensions and similar automation solutions tailored to gym operations, coaching workflows and retention systems.

πŸ”— Nodes Used

Google Sheets, Slack, Gmail, Supabase, Schedule Trigger, Google Gemini

πŸ“₯ Import

Download workflow.json and import into n8n: Workflow menu β†’ Import from File

πŸ“– Importing guide Β· πŸ”‘ Credential setup