Quick Overview
This workflow powers an @n8n/chat website widget that answers visitor questions using an n8n Data Table knowledge base via OpenAI, keeps per-session memory, captures leads to Google Sheets only with consent, emails you via Gmail, and logs unanswered questions for follow-up.
How it works
- Receives a new message from the @n8n/chat widget trigger.
- Cleans and validates the visitor input, returning a prompt if the message is empty.
- Uses an OpenAI-powered agent with session memory to search the n8n Data Table knowledge_base and generate a structured, grounded reply.
- If the visitor has explicitly consented and provided a name and valid email, appends the lead details to a Google Sheets “Leads” tab and sends a Gmail notification.
- If the answer is supported, returns the agent’s reply to the chat widget.
- If the answer is not supported, logs the question and missing information to the n8n Data Table unanswered_questions and returns a fallback response offering human follow-up.
Setup
- Add OpenAI credentials (or n8n AI Gateway) for the chat model used by the agent.
- Create n8n Data Tables named knowledge_base and unanswered_questions and ensure they contain the expected string columns (topic/details/last_verified_date and session_id/question/missing_info/asked_at).
- Connect Google Sheets OAuth credentials, set the target spreadsheet in the Google Sheets node, and create a “Leads” sheet with the mapped columns.
- Connect Gmail OAuth credentials and replace the placeholder recipient email address in the Gmail node.
- Configure the Chat Widget Trigger allowed origins and publish the workflow, then embed the @n8n/chat widget on your site using the production chat URL.