I’m currently setting up a PostgreSQL Chat Memory node in n8n to store user conversations, but I’m struggling to properly include and save the user_id alongside each chat session. What I’m trying to achieve:
Each chat message should be stored in PostgreSQL with a session ID and user ID.
The user_id is included in the JSON payload sent to n8n.
I need to ensure that the PostgreSQL Chat Memory node correctly maps and stores the user_id in my database.
Even though I can see userId in the incoming JSON and in my Debug Panel, the PostgreSQL Chat Memory node does not seem to store it in my database. I don’t see an option to directly map user_id in the node settings.
My Questions:
How can I properly map the user_id so that it gets saved in PostgreSQL?
Does the PostgreSQL Chat Memory node support storing additional fields like user_id?
If not, is there a recommended workaround to ensure that every chat message is linked to the correct user?
Any help or insights would be greatly appreciated! Thanks in advance.
Storing the userId like that is probably not valid via the postgres chat memory node. According to the Postgres Chat Memory node documentation:
… the node is primarily designed to store chat history, and it doesn’t mention capabilities for storing additional user-specific data.
A potential workaround you can try is to use the metadata field:
You can include additional information in the metadata. This example is for the Chat Trigger node but a similar approach might work for the PostgreSQL Chat Memory node.
You could try modifying your Code node to include the user_id in the metadata:
However as you can see in the image, after updating the PostgreSQL Chat Memory node, I can’t find an option to map or store the metadata field in the database. There doesn’t seem to be built-in support for metadata in this node.
I also checked my database (n8n_chat_histories), but the metadata field is not present or automatically stored. I even tried manually adding a metadata column in my table, but the PostgreSQL Chat Memory node doesn’t seem to recognize or save it.
Could you clarify how exactly the metadata should be stored and retrieved in the PostgreSQL Chat Memory node? Or is there another workaround to ensure the userId is properly saved with each chat message?