Quick overview
This workflow adds a reusable compliance layer for outbound SMS/email by checking a Google Sheets opt-out list, appending TCPA opt-out language, and writing an audit log, and it also receives inbound Twilio SMS STOP/UNSTOP messages to maintain the same opt-out list.
How it works
- Receives a compliance-check request from a parent n8n workflow via an Execute Sub-workflow trigger.
- Loads firm settings from n8n Variables, validates the required inputs (channel, recipient, message, template ID), and reads the Opt-Outs tab from Google Sheets.
- Checks whether the recipient phone number or email address is present in the opt-out list.
- If the recipient is opted out, logs the suppression to the Audit Log tab in Google Sheets and returns
{ approved: false, message_out: '' } to the caller.
- If the recipient is not opted out, appends the appropriate SMS or email opt-out disclaimer, logs the approved message to the Audit Log tab in Google Sheets, and returns
{ approved: true, message_out } to the caller.
- Separately, receives inbound SMS via a Twilio webhook, classifies the message as STOP/UNSTOP/other, and updates the Opt-Outs tab by adding the sender on STOP, removing the sender on UNSTOP, or doing nothing for unrelated replies.
Setup
- Create a Google Sheet with two tabs named exactly
Opt-Outs (phone, email, opted_out_at, source) and Audit Log (logged_at, template_id, matter_id, recipient, channel, message_preview, status).
- Add Google Sheets OAuth2 credentials in n8n and ensure they have access to the compliance sheet.
- Set n8n Variables for
OPS1_SHEET_ID (the spreadsheet ID) and FIRM_NAME (used in the email footer).
- In each outbound template workflow, add an Execute Sub-workflow step before sending and use the returned
approved flag and message_out text.
- Activate this workflow and configure your Twilio phone number’s “When a message comes in” webhook URL to point to the workflow’s production webhook endpoint.