n8n WhatsApp AI 智能體記憶:應使用哪個 Session ID,避免所有用戶共用記憶
n8n WhatsApp AI agent memory: which Session ID to use (and the one that merges every user)
這篇教學建議,n8n WhatsApp AI 智能體的記憶 Session ID 應使用發訊者的 WhatsApp ID,讓不同聯絡人的對話記憶分開。可用 contacts[0].wa_id 或 messages[0].from;metadata.phone_number_id 是商家號碼,若用作鍵,所有聯絡人便會共用記憶。
Disclosure: I work on MemorySync (I'm Mohammed, the founder). I drafted this page with AI assistance and checked it against the source thread and the official docs listed under Sources on Oct 28, 2026. I read the threads and docs; I didn't run a WhatsApp workflow for this page.
The question
In the n8n forum thread "Simple memory issue" (Feb 3, 2026), a beginner building a WhatsApp companion bot got this on the Simple Memory node:
No session ID found
Expected to find the session ID in an input field called 'sessionId' (this is what the chat trigger node outputs). To use something else, change the 'Session ID' parameter
The only reply said that with a WhatsApp Trigger "you should reference a Session ID" and pointed to a screenshot. The thread closed automatically after 90 days with no accepted answer. An earlier thread, "Connect Simple Memory to WhatsApp Trigger error", shows the same failure and two different keys, and only one of them is right for a bot that talks to many people.
Status (checked Oct 28, 2026): both threads are closed (auto-closed 90 days after the last reply), neither has a marked solution.
Why it happens
Per n8n's Simple Memory common issues page, the sessionId is normally read from the On Chat Message trigger, and if you're not using that trigger "you'll need to manage sessions manually." The WhatsApp Trigger doesn't output a sessionId field, so the default "Connected Chat Trigger Node" setting finds nothing.
The fix: key memory on the sender
In Simple Memory (or Postgres/Redis Chat Memory), set Session ID to Define below and use the sender's WhatsApp ID. This is the expression the original poster in the second thread confirmed worked:
{{ $('WhatsApp Trigger').item.json.contacts[0].wa_id }}
Per Meta's webhook payload reference, contacts[].wa_id is the customer's WhatsApp ID and messages[].from is the sender, so {{ $('WhatsApp Trigger').item.json.messages[0].from }} identifies the same person.
The trap: metadata.phone_number_id
The other suggestion in that thread was {{ $node["WhatsApp Trigger"].json.metadata.phone_number_id }}. It clears the error, but per Meta's reference metadata.phone_number_id identifies your business number, not the person writing to it. Every contact then shares one session, so the bot mixes up what different people told it. For a companion bot that's the worst failure: it "remembers" one user's details in another user's chat.
n8n's docs make the same point about static keys: a fixed key like my_test_session is fine for testing, but set up real session management before publishing.
Checklist
-
Session ID = sender (
contacts[0].wa_idormessages[0].from), notmetadata.*. -
Agent prompt = the message text, for example
{{ $('WhatsApp Trigger').item.json.messages[0].text.body }}. Non-text messages (images, audio, status updates) won't havetext.body, so filter or branch onmessages[0].typefirst. - Test with two phones. If the second number sees anything from the first, the key is shared.
- Plan for restarts. Simple Memory lives in the n8n process. For memory that survives restarts, use Postgres or Redis Chat Memory with the same Session ID expression.
- Several memory nodes? n8n's docs say all Simple Memory nodes share one memory instance by default unless you set different session IDs.
If you're on the Chat Trigger instead of WhatsApp, the same error is covered in n8n AI Agent memory per user.
Common questions
Why does it work in the editor but not from WhatsApp?
Usually because the test used a pinned or static session value. Live WhatsApp executions only carry what the trigger outputs, so the Session ID must be an expression on the trigger's data.
Should I use the phone number as the key?
wa_id is the stable per-contact identifier WhatsApp gives you, which is what memory needs. It is also personal data, so treat the memory table accordingly.
Does the bot remember facts across weeks, or only the last messages?
Chat Memory nodes keep a window of recent messages for that session. Remembering durable facts about a person (name, preferences) beyond that window needs a separate long-term memory step.
If you want long-term memory per contact
The MemorySync n8n guide documents a MemorySync Chat Memory sub-node for the AI Agent's Memory port, with a Session ID (your conversation key) and an End User ID (the person chatting). Every MemorySync operation is scoped by End User ID, and the guide says to use the same value across Add, Search and Recall. For WhatsApp, the same wa_id expression can fill both fields. MemorySync extracts durable facts from the user's turns, and those facts are shared with every other MemorySync surface for that user. It's community nodes from npm, so per the guide it needs a self-hosted n8n instance for now (n8n Cloud verification is in progress). I haven't tested it with the WhatsApp Trigger. Read the guide first. To see save and recall in your browser, try the MemorySync playground.
Sources
- community.n8n.io/t/simple-memory-issue/259690 (closed, no accepted answer; read 2026-10-28)
- community.n8n.io/t/connect-simple-memory-to-whatsapp-trigger-error/160944 (closed; read 2026-10-28)
- n8n docs: Simple Memory node common issues
- Meta for Developers: WhatsApp Cloud API webhooks notification payload reference
- MemorySync docs: docs.memorysync.io/guides/n8n
來源:DEV Community · dev.to