Nodes:
name: WhatsApp Trigger
type: n8n-nodes-base.whatsAppTrigger
parameters: updates: messages
name: OpenAI Chat Model
type: @n8n/n8n-nodes-langchain.lmChatOpenAi
parameters: model: gpt-4o-2024-08-06
name: Window Buffer Memory
type: @n8n/n8n-nodes-langchain.memoryBufferWindow
parameters: sessionKey: =whatsapp-75-{{ $json.messages[0].from }}
sessionIdType: customKey
name: Vector Store Tool
type: @n8n/n8n-nodes-langchain.toolVectorStore
parameters: name: query_product_brochure
description: Call this tool to query the product brochure. Valid for the year 2024.
name: Embeddings OpenAI
type: @n8n/n8n-nodes-langchain.embeddingsOpenAi
parameters: model: text-embedding-3-small
name: OpenAI Chat Model1
type: @n8n/n8n-nodes-langchain.lmChatOpenAi
parameters: model: gpt-4o-2024-08-06
name: When clicking ‘Test workflow’
type: n8n-nodes-base.manualTrigger
name: Embeddings OpenAI1
type: @n8n/n8n-nodes-langchain.embeddingsOpenAi
parameters: model: text-embedding-3-small
name: Default Data Loader
type: @n8n/n8n-nodes-langchain.documentDefaultDataLoader
parameters: jsonData: ={{ $('Extract from File').item.json.text }}
jsonMode: expressionData
name: Recursive Character Text Splitter
type: @n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter
parameters: chunkSize: 2000
name: Extract from File
type: n8n-nodes-base.extractFromFile
parameters: operation: pdf
name: get Product Brochure
type: n8n-nodes-base.httpRequest
parameters: url: https://usa.yamaha.com/files/download/brochure/1/1474881/Yamaha-Powered-Loudspeakers-brochure-2024-en-web.pdf
name: Reply To User
type: n8n-nodes-base.whatsApp
parameters: textBody: ={{ $json.output }}
operation: send
phoneNumberId: 477115632141067
additionalFields: previewUrl: no
recipientPhoneNumber: ={{ $('WhatsApp Trigger').item.json.messages[0].from }}
name: Reply To User1
type: n8n-nodes-base.whatsApp
parameters: textBody: =I'm unable to process non-text messages. Please send only text messages. Thanks!
operation: send
phoneNumberId: 477115632141067
additionalFields: previewUrl: no
recipientPhoneNumber: ={{ $('WhatsApp Trigger').item.json.messages[0].from }}
name: Product Catalogue
type: @n8n/n8n-nodes-langchain.vectorStoreInMemory
parameters: memoryKey: whatsapp-75
name: Sticky Note
type: n8n-nodes-base.stickyNote
parameters: color: 7
width: 640.4375
height: 434.6875
content: ## 1. Download Product Brochure PDF
[Read more about the HTTP Request Tool](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.httprequest)

Import your marketing PDF document to build your vector store. This will be used as the knowledgebase by the Sales AI Agent.

For this demonstration, we'll use the HTTP request node to import the YAMAHA POWERED LOUDSPEAKERS 2024 brochure ([Source](https://usa.yamaha.com/files/download/brochure/1/1474881/Yamaha-Powered-Loudspeakers-brochure-2024-en-web.pdf)) and an Extract from File node to extract the text contents. 
name: Sticky Note1
type: n8n-nodes-base.stickyNote
parameters: color: 7
width: 614.6875
height: 731.1875
content: ## 2. Create Product Brochure Vector Store
[Read more about the In-Memory Vector Store](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstoreinmemory/)

Vector stores are powerful databases which serve the purpose of matching a user's questions to relevant parts of a document. By creating a vector store of our product catalog, we'll allow users to query using natural language.

To keep things simple, we'll use the **In-memory Vector Store** which comes built-in to n8n and doesn't require a separate service. For production deployments, I'd recommend replacing the in-memory vector store with either [Qdrant](https://qdrant.tech) or [Pinecone](https://pinecone.io).
name: Create Product Catalogue
type: @n8n/n8n-nodes-langchain.vectorStoreInMemory
parameters: mode: insert
memoryKey: whatsapp-75
clearStore: yes
name: Sticky Note2
type: n8n-nodes-base.stickyNote
parameters: color: 7
width: 546.6875
height: 484.1875
content: ## 3. Use the WhatsApp Trigger
[Learn more about the WhatsApp Trigger](https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.whatsapptrigger/)

The WhatsApp Trigger allows you to receive incoming WhatsApp messages from customers. It requires a bit of setup so remember to follow the documentation carefully! Once ready however, it's quite easy to build powerful workflows which are easily accessible to users.

Note that WhatsApp can send many message types such as audio and video so in this demonstration, we'll filter them out and just accept the text messages.
name: Sticky Note3
type: n8n-nodes-base.stickyNote
parameters: width: 338
height: 92
content: ### Want to handle all message types?
Check out my other WhatsApp template in my creator page! https://n8n.io/creators/jimleuk/
name: Sticky Note4
type: n8n-nodes-base.stickyNote
parameters: color: 7
width: 337.6875
height: 311.1875
content: ### 3a. Handle Unsupported Message Types
For non-text messages, we'll just reply with a simple message to inform the sender.
name: Sticky Note5
type: n8n-nodes-base.stickyNote
parameters: color: 7
width: 746.6875
height: 929.1875
content: ## 4. Sales AI Agent Responds To Customers
[Learn more about using AI Agents](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/)

n8n's AI agents are powerful nodes which make it incredibly easy to use state-of-the-art AI in your workflows. Not only do they have the ability to remember conversations per individual customer but also tap into resources such as our product catalogue vector store to pull factual information and data for every question.

In this demonstration, we use an AI agent which is directed to help the user navigate the product brochure. A Chat memory subnode is attached to identify and keep track of the customer session. A Vector store tool is added to allow the Agent to tap into the product catalogue knowledgebase we built earlier.
name: Sticky Note6
type: n8n-nodes-base.stickyNote
parameters: color: 7
width: 495.4375
height: 484.1875
content: ## 5. Repond to WhatsApp User
[Learn more about the WhatsApp Node](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.whatsapp/)

The WhatsApp node is the go-to if you want to interact with WhatsApp users. With this node, you can send text, images, audio and video messages as well as use your WhatsApp message templates.

Here, we'll keep it simple by replying with a text message which is the output of the AI agent.
name: Sticky Note7
type: n8n-nodes-base.stickyNote
parameters: width: 401.25
height: 582.6283033962263
content: ## Try It Out!

### This n8n template builds a simple WhatsApp chabot acting as a Sales Agent. The Agent is backed by a product catalog vector store to better answer user's questions.

* This template is in 2 parts: creating the product catalog vector store and building the WhatsApp AI chatbot.
* A product brochure is imported via HTTP request node and its text contents extracted.
* The text contents are then uploaded to the in-memory vector store to build a knowledgebase for the chatbot.
* A WhatsApp trigger is used to capture messages from customers where non-text messages are filtered out.
* The customer's message is sent to the AI Agent which queries the product catalogue using the vector store tool.
* The Agent's response is sent back to the user via the WhatsApp node.

### Need Help?
Join the [Discord](https://discord.com/invite/XPKeKXeB7d) or ask in the [Forum](https://community.n8n.io/)!
name: Handle Message Types
type: n8n-nodes-base.switch
parameters: rules: values: outputKey: Supported
conditions: options: version: 2
caseSensitive: yes
typeValidation: strict
combinator: and
conditions: operator: type: string
operation: equals
leftValue: ={{ $json.messages[0].type }}
rightValue: text
renameOutput: yes
outputKey: Not Supported
conditions: options: version: 2
caseSensitive: yes
typeValidation: strict
combinator: and
conditions: operator: type: string
operation: notEquals
leftValue: ={{ $json.messages[0].type }}
rightValue: text
renameOutput: yes
name: Sticky Note8
type: n8n-nodes-base.stickyNote
parameters: color: 5
width: 345.10906976744184
height: 114.53583720930231
content: ### You only have to run this part once!
Run this step to populate our product catalogue vector. Run again if you want to update the vector store with a new version.
name: Sticky Note9
type: n8n-nodes-base.stickyNote
parameters: color: 5
width: 364.6293255813954
height: 107.02804651162779
content: ### Activate your workflow to use!
To start using the WhatsApp chatbot, you'll need to activate the workflow. If you are self-hosting ensure WhatsApp is able to connect to your server.
name: AI Sales Agent
type: @n8n/n8n-nodes-langchain.agent
parameters: text: ={{ $json.messages[0].text.body }}
options: systemMessage: You are an assistant working for a company who sells Yamaha Powered Loudspeakers and helping the user navigate the product catalog for the year 2024. Your goal is not to facilitate a sale but if the user enquires, direct them to the appropriate website, url or contact information.

Do your best to answer any questions factually. If you don't know the answer or unable to obtain the information from the datastore, then tell the user so.
promptType: define

Connections:
AI Sales Agent: main: node: Reply To User
type: main
WhatsApp Trigger: main: node: Handle Message Types
type: main
Embeddings OpenAI: ai_embedding: node: Product Catalogue
type: ai_embedding
Extract from File: main: node: Create Product Catalogue
type: main
OpenAI Chat Model: ai_languageModel: node: AI Sales Agent
type: ai_languageModel
Product Catalogue: ai_vectorStore: node: Vector Store Tool
type: ai_vectorStore
Vector Store Tool: ai_tool: node: AI Sales Agent
type: ai_tool
Embeddings OpenAI1: ai_embedding: node: Create Product Catalogue
type: ai_embedding
OpenAI Chat Model1: ai_languageModel: node: Vector Store Tool
type: ai_languageModel
Default Data Loader: ai_document: node: Create Product Catalogue
type: ai_document
Handle Message Types: main: node: AI Sales Agent
type: main
node: Reply To User1
type: main
Window Buffer Memory: ai_memory: node: AI Sales Agent
type: ai_memory
get Product Brochure: main: node: Extract from File
type: main
Recursive Character Text Splitter: ai_textSplitter: node: Default Data Loader
type: ai_textSplitter
When clicking ‘Test workflow’: main: node: get Product Brochure
type: main