WhatsApp Customer Support Agent with Gemini and Google Docs RAG - n8n Workflow

Deploy a powerful n8n workflow for WhatsApp customer support. Uses Google Gemini AI, Google Docs as a knowledge base, and handles the 24-hour window rule. Integrate this n8n template now.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Businesses relying on WhatsApp for customer service who need instant, AI-driven responses.
Developers looking for advanced n8n templates integrating multiple services (WhatsApp, Google, AI).
Users needing a robust n8n workflow solution that manages the 24-hour WhatsApp messaging window efficiently.
Companies wanting to leverage their existing internal documentation (Google Docs) for RAG (Retrieval-Augmented Generation).

Overview

Customer support on platforms like WhatsApp requires rapid responses, but is complicated by the 24-hour messaging window imposed by Meta. This sophisticated n8n workflow addresses these challenges directly.

It functions as a Retrieval-Augmented Generation (RAG) system, pulling comprehensive answers from your internal documentation stored in a Google Docs file. It uses the Google Gemini language model, integrated via a specialized n8n node, to generate high-quality, context-aware responses. Crucially, the n8n workflow includes logic to check if the incoming message falls within the 24-hour service window. If the window has expired, a specific message is sent, preventing errors and ensuring compliance. Every interaction is meticulously logged to a Google Sheets document for historical analysis, making this n8n template a complete and professional solution for automated WhatsApp support.

How it Works

The entire process is initiated by the WhatsApp n8n trigger node.


  1. Trigger and Knowledge Retrieval: The n8n workflow starts when the when message received n8n trigger detects a new inbound WhatsApp message. Immediately, the company's knowledge Google Docs n8n node retrieves the specified support document content.

  2. Prompt Preparation: The Prepare Prompt n8n node structures the input, combining the user's question, today's date, and the entire Google Doc text into a coherent finalPrompt variable, ready for the AI.

  3. AI Processing: The AI Agent n8n node processes the prompt. This agent leverages the Google Gemini Chat Model for reasoning and the Simple Memory n8n node to maintain context throughout the conversation, ensuring continuity for returning users.

  4. Logging: The n8n workflow captures the current time using the Date & Time n8n node and uses the Append or update row in sheet Google Sheets n8n node to log the conversation details (user, message, and AI response).

  5. Window Check: A subsequent code n8n node, 24-hour window check, verifies the message timestamp against the current time to determine if the message is within the 24-hour reply window.

  6. Conditional Routing: The If n8n node directs the flow. If the condition is false (window expired), the Send message n8n node sends a notification about the expired window. If true, the flow continues.

  7. Answer Sanitization: The cleanAnswer code n8n node performs necessary text cleanup, removing Markdown syntax and unwanted preamble text generated by the AI.

  8. Final Delivery: Finally, the Send AI Agent's Answer WhatsApp n8n node delivers the polished response back to the customer.

Installation Guide

To utilize this powerful n8n template, follow these steps after importing the n8n workflow JSON:


  1. WhatsApp Trigger Setup: Configure the when message received n8n trigger node. You must set up a WhatsApp OAuth credential connected to your Meta Business Account and ensure the webhook is correctly registered.

  2. Google Docs Credentials: Provide credentials for the company's knowledge n8n node (Google Docs OAuth2). Update the 'Document URL' parameter to point to your specific knowledge base document.

  3. Google Gemini Credentials: Set up the Google Gemini (PaLM) API credential in the Google Gemini Chat Model n8n node.

  4. Google Sheets Credentials: Configure the Google Sheets OAuth2 credential for the Append or update row in sheet n8n node. You must update the 'Document ID' and 'Sheet Name' to match the log spreadsheet where you want to store the history.

  5. WhatsApp API Credential: Provide the necessary API credentials for the two WhatsApp Send n8n node instances (Send AI Agent's Answer and Send message). Ensure the 'Phone Number ID' is correctly set in both instances. This n8n workflow requires multiple specific credentials to function correctly.

Node Details

when message received (WhatsApp Trigger):
Function: Acts as the starting point, the main n8n trigger for the workflow, activated by incoming WhatsApp messages.
Key Configuration: Watches for 'messages' updates.
company's knowledge (Google Docs):
Function: Retrieves the complete plain text content from a specified Google Doc, serving as the knowledge source for the RAG system.
Key Configuration: Operation 'get'; Document URL is hardcoded to the knowledge document ID.
AI Agent (LangChain Agent):
Function: The core orchestration n8n node. It combines the structured prompt, the Gemini LLM, and chat memory to generate informed responses.
Key Configuration: Uses the LangChain model/tool system. Connected to Google Gemini Chat Model and Simple Memory n8n node.
Append or update row in sheet (Google Sheets):
Function: Logs all critical interaction data (Timestamp, User, Message, Response) to a specified Google Sheet for record-keeping and auditing.
24-hour window check (Code n8n node):
Function: Custom logic to calculate if the time elapsed since the message was received exceeds 24 hours (a WhatsApp restriction).
If (Core Logic Flow Control n8n node):
Function: Directs the flow based on the 24-hour check result, ensuring only compliant messages receive an automated AI response.
cleanAnswer (Code n8n node):
Function: Post-processing step to sanitize the AI output, removing common LLM output artifacts like markdown indicators (, ~) and prompt references, ensuring a clean WhatsApp message.

Related n8n Workflows

Free

Nodes: 11 Nodes
Updated: December 26 2025
View all
Created by

Over the last three months, I've been intensively learning and applying skills in database management and WhatsApp automation. My goal is to create efficient systems that bridge communication and data needs

Featured*