This comprehensive n8n workflow enables you to build a powerful customer support bot on WhatsApp for businesses. Thanks to the Google Gemini Chat Model and integration with Google Docs used as your company's knowledge base, your bot can provide accurate and fast answers to customer inquiries. Additionally, it logs conversation history to Google Sheets and manages WhatsApp’s 24-hour response window. 🚀👩💼
Key Features:
WhatsApp Trigger: Instantly captures incoming WhatsApp messages and starts the workflow.
Knowledge Base Integration (Google Docs): Provides context to the AI model by reading your company's knowledge base stored in Google Docs.
Smart Responses (Google Gemini): With integration of the Google Gemini Chat Model (via the Google Gemini Chat Model node), the bot generates natural and contextual responses to customer inquiries. It acts as a "customer assistant for TechFlow Software Company" and behaves like a human.
Conversation Memory (Simple Memory): Uses Langchain’s Simple Memory node to maintain context across sessions, enabling the bot to have more coherent and meaningful conversations.
Automatic Message Cleanup: Cleans up formatting markers (bold, italic, etc.) and unnecessary content in AI-generated responses to ensure clean and readable WhatsApp messages.
Conversation Logging (Google Sheets): Logs every customer interaction (user, message, bot response, and timestamp) to a specified Google Sheets file for easy tracking of customer support data.
24-Hour Response Window Handling: Manages WhatsApp’s 24-hour customer service window. If more than 24 hours have passed since the last message, the bot sends a default "time expired" message and stops responding.
Dynamic Prompt Creation: Combines the incoming WhatsApp message, current date, and company data from Google Docs to generate a dynamic prompt for the AI agent.
Workflow Details:
Trigger on Message Received: The when message received (WhatsApp Trigger) node starts the workflow upon receiving a new WhatsApp message.
Knowledge Base Retrieval: The company's knowledge (Google Docs) node pulls relevant information from your company’s Google Docs knowledge base.
Prompt Preparation: The Prepare Prompt node merges the incoming message, current date, and Google Docs content to create a suitable prompt for the AI agent.
AI Response Generation: The AI Agent node uses the Google Gemini Chat Model and Simple Memory to generate the most appropriate response to the user’s question.
Logging the Conversation: The Date & Time node fetches the current timestamp, and the Append or update row in sheet (Google Sheets) node logs the user message, bot response, and timestamp to a Google Sheets file.
24-Hour Window Check: The 24-hour window check node checks whether the message is within WhatsApp’s 24-hour response window.
Conditional Response: The If node checks the time window:
If within 24 hours, it sends the AI response using cleanAnswer and Send AI Agent's Answer.
If not, the Send message node delivers a "time expired" message.
Response Cleanup: The cleanAnswer node cleans up the AI-generated message by removing formatting and adjusting empty lines for better readability on WhatsApp.
Setup:
Import this workflow into your n8n instance.
Configure the required credentials:
when message received: A WhatsApp OAuth account (WhatsApp OAuth account)
Send AI Agent's Answer and Send message: A WhatsApp API account (WhatsApp account)
company's knowledge: A Google Docs OAuth2 account (Google Docs account)
Google Gemini Chat Model: A Google Gemini (PaLM) API account (Google Gemini(PaLM) Api account)
Append or update row in sheet: A Google Sheets OAuth2 account (Google Sheets account)
In the company's knowledge node, update the URL or document ID of the Google Docs file containing your knowledge base.
In the Append or update row in sheet node, configure the ID and sheet name of the Google Sheets file where the chat history will be saved.
Make sure your WhatsApp Business API and webhooks are correctly configured with n8n.
This workflow provides a powerful foundation for delivering fast and efficient customer support. It can be easily extended and customized to meet your specific needs. We look forward to your feedback!