AI Customer Support Chatbot with Elasticsearch Knowledge Base
Overview
This workflow transforms a webhook endpoint into an intelligent customer support chatbot. It receives a customer question, searches a knowledge base stored in Elasticsearch, and generates a helpful, context-aware reply using OpenAI's GPT-4. The bot is designed to reduce human workload by answering common queries instantly, and gracefully escalates to a human agent when the answer is not found. It's ideal for embedding into a website, messaging app, or any frontend that can send HTTP POST requests.
Node-by-Node Breakdown
-
Chatbot Webhook (Frontend Trigger) — Type:
Webhook(No auth)- Listens for POST requests at the path
/support-chatbot. The webhook ID iscustomer-support-chat. This is the entry point where your frontend sends the customer's question as JSON body (e.g.,{"question": "How do I reset my password?"}).
- Listens for POST requests at the path
-
Extract Customer Query — Type:
Function(No auth)- Extracts
questionfrom the incoming JSON body using a simple JavaScript code snippet:const question = $json.body.question; return [{ json: { question } }];. This prepares the query for the next steps.
- Extracts
-
Search Knowledge Base (Elasticsearch) — Type:
Elasticsearch(Requires Elasticsearch credentials – basic auth / API key)- Performs a search on the
support-kbindex using the extracted question as the query. Thequeryparameter is set to={{$json.question}}. It returns matching documents from the knowledge base.
- Performs a search on the
-
Generate AI Response with GPT-4 — Type:
OpenAI(API Key auth)- Uses the
gpt-4model to generate a response. The system message instructs the assistant to use the provided knowledge base content and to politely escalate if the answer is not found. The user message combines the customer question and the top knowledge base result ({{$json.hits.hits[0]._source.content}}).
- Uses the
-
Format Chatbot Reply — Type:
Function(No auth)- Extracts the final reply from the OpenAI response:
return [{ json: { reply: $json.choices[0].message.content } }];. This ensures the output is properly structured.
- Extracts the final reply from the OpenAI response:
-
Return Chatbot Reply — Type:
Respond to Webhook(No auth)- Sends the formatted reply back to the caller (the frontend) as a JSON response.
Setup Instructions
- Elasticsearch: You need a running Elasticsearch instance (cloud or self-hosted) with an index named
support-kb. Populate it with documents containing your knowledge base articles (e.g., each document should have acontentfield). Configure the Elasticsearch node in n8n with your host, port, and authentication credentials (API key or username/password). - OpenAI: Obtain an API key from OpenAI. Add it as a credential in n8n (type: OpenAI API).
- Webhook URL: After activating the workflow, n8n will generate a unique webhook URL (e.g.,
https://your-n8n-host/webhook/support-chatbot). Use this URL in your frontend (website, chatbot widget, etc.) to send POST requests. - Activate the workflow: Toggle the workflow to active in n8n for the webhook to start listening.
Use Cases & Adaptations
- Customer Support Portal: Embed the webhook URL in a live chat widget on your website to answer FAQs instantly.
- Slack or Discord Bot: Replace the webhook trigger with a Slack/Discord trigger and adjust the response format to send messages back to the channel.
- Multiple Knowledge Bases: Modify the Elasticsearch query to search across multiple indices or filter by category.
- Fallback to Human: Customize the GPT-4 system message to trigger a notification (e.g., email or Slack message) when the answer is not found.
- Model Upgrade: Swap
gpt-4forgpt-3.5-turboto reduce cost or use a custom fine-tuned model. - Language Support: Add a language detection step before the query to route to different knowledge bases or translate the response.
Workflow JSON
{
"name": "ai-chatbot-customer-support-kb",
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "support-chatbot"
},
"id": "1",
"name": "Chatbot Webhook (Frontend Trigger)",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
100,
300
],
"webhookId": "customer-support-chat"
},
{
"parameters": {
"functionCode": "const question = $json.body.question;\nreturn [{ json: { question } }];"
},
"id": "2",
"name": "Extract Customer Query",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
300,
300
]
},
{
"parameters": {
"operation": "search",
"index": "support-kb",
"query": "={{$json.question}}"
},
"id": "3",
"name": "Search Knowledge Base (Elasticsearch)",
"type": "n8n-nodes-base.elasticSearch",
"typeVersion": 1,
"position": [
500,
300
],
"credentials": {
"elasticSearchApi": {
"id": "elasticsearch_credential",
"name": "ElasticSearch"
}
// ... truncated (copy to see full JSON)How to Import This Workflow
- 1Copy the workflow JSON above using the Copy Workflow JSON button.
- 2Open your n8n instance and go to Workflows.
- 3Click Import from JSON and paste the copied workflow.
Don't have an n8n instance? Start your free trial at n8nautomation.cloud
Related Templates
WhatsApp AI RAG Chatbot with Google Drive & Qdrant
WhatsApp AI RAG Chatbot with Google Drive & Qdrant High-Level Summary This workflow creates a powerful AI-powered customer support chatbot for WhatsApp Business that uses Retrieval-Augmented Generation (RAG). It listens for incoming WhatsApp messages, checks if they contain text, and responds using an AI agent backed by a knowledge base stored in Qdrant (a vector database). The knowledge base is automatically built from documents stored in a Google Drive folder — making it easy to update your product manuals, FAQs, or support guides without touching the workflow. This is ideal for businesses that want to provide 24/7 intelligent customer support on WhatsApp with up-to-date information. Step-by-Step Node Breakdown Setup Phase (Run Once to Initialize) When clicking 'Test workflow' (Manual Trigger — No auth) — This node is used to manually trigger the setup process. When clicked, it starts two parallel paths: creating the Qdrant collection and refreshing it. Create collection (HTTP Request — Header Auth) — Sends a POST request to to create a new collection in Qdrant. The header parameters include . You need to replace with your Qdrant instance URL and with your desired collection name. Refresh collection (HTTP Request — Header Auth) — Sends a POST request to with an empty filter to delete all existing points (documents) in the collection. This ensures a clean slate before re-uploading documents. Get folder (Google Drive — OAuth2) — Uses Google Drive API to list files in a specific folder. The folder ID is set to (you should change this to your actual folder ID). It filters by as the drive location. Download Files (Google Drive — OAuth2) — For each file returned by the previous node, this downloads the file using its ID. The options include Google File Conversion to convert Google Docs to plain text format. Qdrant Vector Store (Qdrant — API Key auth) — This node inserts documents into the Qdrant vector store. It uses the collection name specified (replace with your actual collection name). It receives documents from the Default Data Loader and embeddings from the Embeddings OpenAI node. Embeddings OpenAI (OpenAI — API Key auth) — Generates vector embeddings for the documents using OpenAI's embedding models. These embeddings are fed into the Qdrant Vector Store node. Default Data Loader (Document Loader — No auth) — Converts binary data (the downloaded files) into document format suitable for vector storage. Token Splitter (Text Splitter — No auth) — Splits documents into smaller chunks of 300 tokens with 30 token overlap. This helps the AI retrieve more relevant context. Runtime Phase (Handles Incoming Messages) Verify (Webhook — No auth) — This webhook receives GET requests from Meta (Facebook) to verify your webhook URL. It responds with the challenge code sent by Meta. The webhook path is auto-generated. Respond to Webhook (Respond to Webhook — No auth) — Connected to the Verify node, this sends back the value from the query parameters to complete the verification handshake with Meta. Respond (Webhook — No auth) — This webhook receives POST requests from Meta containing incoming WhatsApp messages and status updates. It uses the same path as the Verify webhook but only accepts POST requests. is Message? (IF — No auth) — Checks if the incoming webhook payload contains a message object at . If it exists (true branch), the message is processed by the AI Agent. If not (false branch), it means it's a status update or other non-message event. Only message (WhatsApp — API Key auth) — If the incoming payload is not a text message (e.g., image, video), this node sends a reply saying "You can only send text messages". It uses the phone number ID (you must replace this with your own WhatsApp Business phone number ID) and extracts the recipient's WhatsApp ID from the webhook payload. AI Agent (AI Agent — No auth) — This is the core intelligence of the workflow. It uses a conversational agent with a detailed system prompt instructing it to act as an electronics store assistant. The agent receives the user's text message from the webhook payload. It uses the OpenAI Chat Model for language generation and the Window Buffer Memory for conversation context. The agent retrieves relevant documents from the Qdrant vector store to answer questions accurately. OpenAI Chat Model (OpenAI — API Key auth) — Configured to use model. This powers the AI Agent's language understanding and generation capabilities. Window Buffer Memory (Memory Buffer Window — No auth) — Maintains conversation history so the AI can reference previous messages in the same conversation session. Send (WhatsApp — API Key auth) — Sends the AI-generated response back to the user on WhatsApp. It uses the same phone number ID and extracts the recipient's WhatsApp ID from the original webhook payload. Setup Instructions To use this workflow, you'll need the following accounts and credentials: WhatsApp Business Account — You need a Meta for Developers account with a WhatsApp Business app. Get your Phone Number ID and WhatsApp Business API credentials from the Meta Developer Portal. OpenAI Account — Sign up at platform.openai.com and create an API key with access to GPT-4o-mini and embedding models. Qdrant Instance — You need a running Qdrant instance (cloud or self-hosted). Get the Qdrant URL and API key from your Qdrant dashboard. Google Drive — You need a Google Cloud project with the Google Drive API enabled. Create OAuth2 credentials and authorize access to the folder containing your knowledge base documents. Meta Webhook Setup — In your Meta for Developers app, add a new webhook product. Set the Callback URL to your n8n webhook URL (the one from the Verify/Respond nodes). The Verify Token can be anything you choose. Important Configuration Steps: Replace with your actual Qdrant instance URL (e.g., ) Replace with your desired collection name (e.g., ) Replace with your actual WhatsApp Business phone number ID Update the Google Drive folder ID from to your actual folder ID Configure the webhook nodes: Verify should use GET method, Respond should use POST method Use Cases and Variations Primary Use Case: An electronics store providing 24/7 automated customer support via WhatsApp with accurate product information from their documentation. Adaptation Ideas: Different Industries: Change the system prompt in the AI Agent to serve other industries like healthcare, legal, or hospitality Multiple Document Sources: Add more document loaders (e.g., Notion, Confluence, website scraping) to expand the knowledge base Multi-language Support: The AI can handle multiple languages — just ensure your documents cover the needed languages Human Handoff: Add a condition to escalate complex queries to human agents via email or Slack Rich Media Responses: Modify the Send node to include images, buttons, or lists using WhatsApp's interactive message features Analytics: Add a database node to log all conversations for analysis and improvement Scheduled Updates: Add a Schedule Trigger to periodically refresh the knowledge base from Google Drive
HR & IT Helpdesk Chatbot with Audio Transcription on Telegram
Overview This workflow builds a fully functional HR & IT helpdesk chatbot that operates through Telegram. It ingests internal policy documents (e.g., employee handbooks, IT FAQs), creates a searchable knowledge base using vector embeddings stored in PostgreSQL, and then answers employee questions via text or voice messages. The chatbot uses Retrieval-Augmented Generation (RAG) to provide accurate, context-aware responses based on your company's specific policies. This is particularly useful for organizations that want to automate common HR and IT inquiries, reduce the burden on support teams, and provide 24/7 self-service to employees. The inclusion of voice message transcription makes it accessible for users who prefer speaking over typing. Workflow Steps Phase 1: Knowledge Base Ingestion (Run Once or on Update) When clicking 'Test workflow' (Manual Trigger — No auth) — This node starts the ingestion process manually. It is intended to be run once when setting up the workflow or whenever the policy documents are updated. HTTP Request (HTTP Request — No auth) — Fetches a PDF file from a public URL (in this example, an employee handbook from an S3 bucket). The URL can be changed to point to any PDF hosted online or on a shared drive. Extract from File (Extract from File — No auth) — Parses the downloaded PDF and extracts its text content. The operation is set to "pdf" to handle PDF documents. Recursive Character Text Splitter (Text Splitter — No auth) — Splits the extracted text into smaller chunks of 2000 characters each. This is necessary for creating meaningful vector embeddings and for efficient retrieval. Default Data Loader (Document Loader — No auth) — Converts the text chunks into document objects that can be stored in the vector store. It takes the text from the Extract from File node using the expression . Embeddings OpenAI (Embeddings — OpenAI API Key auth) — Generates vector embeddings for each text chunk using OpenAI's embedding models. These embeddings represent the semantic meaning of the text. Create HR Policies (PostgreSQL PGVector Store — Database credentials auth) — Inserts the document chunks and their embeddings into a PostgreSQL database with pgvector extension. This creates the searchable knowledge base. Phase 2: Chatbot Runtime Telegram Trigger (Telegram Trigger — Telegram Bot Token auth) — Listens for incoming messages on a Telegram bot. It captures all messages (text, voice, etc.) sent to the bot. Verify Message Type (Switch — No auth) — Routes messages based on their type: - Text messages (containing ) → sent to the AI agent - Voice messages (containing ) → sent for transcription - Other types → sent to a fallback response Edit Fields (Set — No auth) — For text messages, extracts the text content and passes it to the AI agent. Uses the expression . Telegram1 (Telegram — Telegram Bot Token auth) — For voice messages, downloads the audio file from Telegram using the from the incoming message. OpenAI (OpenAI — OpenAI API Key auth) — Transcribes the downloaded voice message into text using OpenAI's Whisper transcription API. The operation is set to "transcribe" and the binary property is set to "data". Unsupported Message Type (Telegram — Telegram Bot Token auth) — Sends a fallback message "I'm not able to process this message type." for unsupported message types (e.g., stickers, locations). AI Agent (AI Agent — No auth) — The core conversational agent. It receives the user's text (either directly or transcribed from voice) and generates a response. The system message is set to "You are a helpful assistant for HR and employee policies". OpenAI Chat Model (Chat Model — OpenAI API Key auth) — The language model powering the AI agent. It generates natural language responses based on the context and retrieved information. Postgres Chat Memory (Memory — Database credentials auth) — Maintains conversation history per user, using the Telegram chat ID as the session key. This allows the chatbot to remember context across multiple messages. Answer questions with a vector store (Vector Store Tool — No auth) — A tool that the AI agent uses to query the knowledge base. It is configured with the name "hremployeepolicies" and description "data for HR and employee policies". Postgres PGVector Store (Vector Store — Database credentials auth) — The actual vector store connection that retrieves relevant document chunks based on the user's query. OpenAI Chat Model1 (Chat Model — OpenAI API Key auth) — A second language model instance used specifically by the vector store tool for re-ranking or summarizing retrieved results. Embeddings OpenAI1 (Embeddings — OpenAI API Key auth) — A second embeddings instance used by the vector store tool to embed the user's query for similarity search. Telegram (Telegram — Telegram Bot Token auth) — Sends the AI agent's response back to the user in the same Telegram chat. Uses the expression for the response text. Setup Instructions Prerequisites OpenAI Account: You need an OpenAI API key with access to: - GPT-4 or GPT-3.5 for chat completion - text-embedding-ada-002 for embeddings - Whisper for audio transcription Telegram Bot: Create a bot via @BotFather on Telegram and obtain the bot token. PostgreSQL Database: A PostgreSQL database with the pgvector extension installed. You can use: - A local PostgreSQL instance - A cloud provider like Supabase, Aiven, or AWS RDS Configuration Steps Set up credentials in n8n: - OpenAI API: Add your OpenAI API key as a credential - Telegram Bot: Add your bot token as a credential - PostgreSQL: Add your database connection details (host, port, database name, user, password) Update the PDF URL: In the HTTP Request node, change the URL to point to your own policy documents (e.g., company handbook, IT policies, FAQs). Run the ingestion: Click "Test Workflow" on the When clicking 'Test workflow' node to populate the vector store with your documents. Set the webhook: Activate the workflow and set the Telegram webhook URL to your n8n instance's webhook URL (provided by the Telegram Trigger node). Test the chatbot: Send a text or voice message to your Telegram bot and verify it responds with relevant information from your policies. Use Cases and Variations Primary Use Cases HR Helpdesk: Answer questions about leave policies, benefits, payroll, company culture, and onboarding procedures. IT Support Desk: Provide troubleshooting steps for common IT issues, password reset instructions, software access requests, and hardware policies. Employee Onboarding: New hires can ask questions about company policies, team structures, and first-day procedures. Possible Variations Multiple Document Sources: Instead of a single PDF, use multiple HTTP Request nodes or connect to Google Drive, SharePoint, or Confluence to ingest documents from various sources. Different Channels: Replace the Telegram trigger with Slack, Microsoft Teams, or a web chat widget to deploy the chatbot on other platforms. Multi-language Support: Configure the OpenAI model to respond in multiple languages based on user preference or detected language. Human Handoff: Add a condition to escalate complex queries to a human agent via email or a ticketing system. Feedback Loop: Add a mechanism for users to rate responses and use that feedback to improve the knowledge base. Scheduled Re-indexing: Add a Cron trigger to periodically re-ingest documents to keep the knowledge base up to date.
Receive and Reply to Messages Across WhatsApp, Instagram, and Facebook Messenger with Fiwano
Overview This workflow provides a unified integration for receiving and replying to messages from WhatsApp, Instagram Direct Messages, and Facebook Messenger using the Fiwano platform. It demonstrates how to handle incoming messages from all three Meta-owned messaging channels through a single trigger and action node set, eliminating the need to build separate integrations for each platform. The workflow is ideal for customer support, lead response, or any scenario where you need to manage multi-channel messaging from one n8n instance. Workflow Steps Fiwano Trigger (API Key auth) — This node listens for incoming messages from all connected channels (WhatsApp, Instagram, Facebook Messenger). It uses the parameter to automatically register the workflow for every active channel in your Fiwano account. The trigger fires on "Message Received" events and provides a normalized payload regardless of which channel the message came from. Example — route by message type (No auth) — This is an IF node that checks the field from the incoming message. It routes messages into two branches: one for text messages (where equals "text") and another for all other message types (images, audio, video, documents, etc.). This demonstrates how to implement different reply logic based on message content type. Example — send text reply (API Key auth) — This Fiwano Send node replies to text messages. It uses the following parameters: - : Taken from the incoming message's field to ensure the reply goes back through the same channel - : Set to the sender's ID from - : A template that echoes the user's message: Example — send attachment reply (API Key auth) — This second Fiwano Send node handles replies to non-text messages (attachments). Its parameters: - : Same as above, using - : Same as above, using - : Acknowledges the attachment type: Setup Instructions Prerequisites A Fiwano account (sign up at fiwano.com) At least one connected messaging channel (WhatsApp Business API, Instagram Professional account, or Facebook Page connected to Messenger) n8n instance (self-hosted or cloud) with public accessibility for webhook triggers Installation Steps Install the n8n-nodes-fiwano community package in your n8n editor (verified package available in the n8n community nodes registry) Create a Fiwano API credential in n8n with your API key from the Fiwano portal (Recommended) Set a Webhook Secret on the credential for signature verification Connect your messaging channels through the Fiwano portal or their channel-connection API Save and activate the workflow — the trigger will auto-register for all active channels Use Cases and Variations Primary Use Cases Customer Support: Route incoming messages to a helpdesk or ticketing system based on message content or sender Lead Response: Automatically reply to inquiries from ads or business pages with personalized messages Notification System: Forward messages to Slack, email, or other internal tools Adaptation Ideas Replace the simple IF router with a more complex decision tree using Switch nodes or AI classification Add a database lookup (e.g., Airtable, Google Sheets) to check if the sender is an existing customer Integrate with OpenAI or other AI services to generate intelligent replies Add logging to a spreadsheet or database for analytics Implement different response templates for each channel type using the field Add human handoff logic when the AI or automated response cannot handle the query Important Notes The normalized payload from Fiwano includes: , (whatsapp/instagram/messenger), , , , , and (for attachments) You typically don't need to branch by channel type unless your business logic requires channel-specific behavior n8n must be publicly reachable for the webhook trigger to receive messages from Fiwano