Skip to main content

AI Chat

The AI Chat Agent is the n8n workflow behind AI Chat in your app. It answers shoppers, remembers each conversation and calls the AI Chat Add-ons as tools.

This feature is available for Lifetime, Ultra plan, Professional or Extended license.

FluxBuilder gives you the template that matches your app's platform:

PlatformTemplateTools already connected
WooCommerce, Dokan, WCFMAI Chat Agent - WooCommerceProduct Sub-Agent, Order Sub-Agent, Knowledge Sub-Agent [RAG], Human Handoff, Get current date and time
ShopifyAI Chat Agent - ShopifySame as WooCommerce
Other platformsAI Chat AgentKnowledge Sub-Agent [RAG], Human Handoff, Get current date and time

Requirements​

WhatUsed for
n8n (self-hosted recommended, or n8n Cloud)Runs the agent
OpenAI API keyRuns the chat model
Postgres database (Supabase works)Stores the chat memory

1. Download and import the workflow​

  1. In FluxBuilder, go to Features > AI Chat.

  2. Click DOWNLOAD WORKFLOW.

  3. In n8n, open Workflows > Create > Import from File and pick the downloaded JSON.

2. Set the credentials​

NodeCredential
OpenAI Chat Model, Chat Model FallbackOpenAI
Postgres Chat Memory, Update User ID to Chat Histories, Create Chat History TablePostgres (Supabase Connect > Session pooler values)
Chat API, Chat Stream API, Web Widget Stream API, Generate Ttitle API, Health Check API, Open WebUIHeader Auth, name x-api-key

Some nodes are not connected, such as MongoDB Chat Memory, Redis Chat Memory and the MCP Client nodes. They need no credential, and you can delete them.

Create one Header Auth credential and use it in all six webhooks. Its value is your secret key. You will paste the same value in FluxBuilder in step 5.

tip

Both model nodes come with a sample model. Pick a model your OpenAI account can use. Chat Model Fallback answers when the main model fails, so you can pick a cheaper or different model there.

3. Create the chat history table​

The agent saves each message in the Postgres table n8n_chat_histories, and links it to the signed-in shopper. Create the table once:

  1. Open the node Create Chat History Table.
  2. Click Execute step.

The node runs this SQL. You can also run it in Supabase SQL Editor:

create table if not exists n8n_chat_histories (
id serial primary key,
session_id varchar(255) not null,
message jsonb not null
);

alter table n8n_chat_histories
add column if not exists created_at timestamptz default now(),
add column if not exists user_id varchar;

alter table n8n_chat_histories enable row level security;

Running it again is safe. If n8n already created the table, the SQL only adds the two missing columns.

tip

Row Level Security stops the public anon key from reading your chats. n8n is not affected when its Postgres credential uses the table owner, such as postgres on Supabase.

4. Connect the add-ons​

Each add-on is a separate workflow. The agent calls it through a tool node. Import the add-on first, then point the tool node to it:

Tool nodeAdd-on workflowGuide
Product Sub-AgentAI Product Sub-AgentAI Product Sub-Agent
Order Sub-AgentAI Order Sub-AgentAI Order Sub-Agent
Knowledge Sub-Agent AI Document Search
Knowledge Sub-AgentAI Knowledge Sub-Agent (Notion)AI Knowledge Sub-Agent
Human HandoffHuman HandoffHuman Handoff
  1. Open the tool node.
  2. In Workflow, select the add-on workflow you imported.

The tool nodes come linked to FluxBuilder's own workflows, which you cannot reach. Select your own workflow in each one you keep, and delete the tool nodes of add-ons you do not use.

tip

Knowledge Sub-Agent (Notion) is not connected to the agent by default. To use it, connect it to the agent's Tool input. You can use it together with Knowledge Sub-Agent [RAG] or instead of it.

5. Publish and set up FluxBuilder​

  1. In n8n, save the workflow and click Publish.

  2. In FluxBuilder, go to Features > Chat GPT and fill in:

    • URL: your n8n address, for example https://your-n8n.example.com. Do not add /webhook.
    • API Key: the Header Auth value from step 2.
  3. Go to Features > AI Chat to set the Avatar, Agent Name, Welcome Message and Chat Background Image.

  4. Go to Features > Smart Chat, add a chat item and pick the app chatGPT.

Finally, Build a new version of your app, or update the config of your current build.

Test in n8n​

The node When chat message received gives you a chat page to test the agent without the app. Click Open chat in the workflow editor.

The app sends your store details with each message. The test chat does not, so:

  • The agent uses the sample store written in its system message.
  • Product and order questions may get no answer, because the sub-agents do not know your platform. Test those from the app.
tip

The test chat is public, so anyone with its URL can use your OpenAI credits. After testing, open When chat message received and turn off Make Chat Publicly Available.

Webhooks​

All webhooks need the header x-api-key.

PathUsed by
POST /webhook/v1/chatThe app
POST /webhook/v1/chat/streamThe app, with streaming answers
POST /webhook/v1/generate_titleThe app, to name each chat
POST /webhook/v1/widget/chat/streamWeb-Embedding Chat on your website
GET /webhook/v1/healthChecking that the agent is online
POST /webhook/v1/open-webuiOpen WebUI, if you use it

Check the connection with:

curl "<https://your-n8n.example.com/webhook/v1/health>" \
-H "x-api-key: your-secret-value"

Troubleshooting​

ProblemFix
The app shows an error and never answersCheck URL and API Key in Features > Chat GPT, and that the workflow is published
Authorization data is wrong!The API Key in FluxBuilder is not the same as the Header Auth value
The model is not foundPick a model your OpenAI account can use in both model nodes
The agent never uses an add-onThe tool node still points to FluxBuilder's workflow. Select your own one
The agent forgets earlier messagesCheck the Postgres credential on Postgres Chat Memory
column "user_id" does not existRun the SQL in step 3
chatGPT is not in the Smart Chat listYour plan does not include AI Chat