Generate unique sessionId key if parameter is blank and pass from window buffer memory to webhook response

Hi, I am transitioning from and have fallen at one of the first hurdles.

I just want to generate a Session ID if one does not exist in the incoming webhook and then extract it to use again and pass it to the webhook response for use on the next run for that user.

At this point my incoming webhook contains:

  "sessionId": "",
  "contactMessage": "Hi"

Then, if sessionId is blank, generate one, and use it in the Window Memory Buffer using something like:

{{(+new Date).toString(36).slice(-5) + Math.random().toString(36).substr(2, 5)}}

Then I just want to pass that back to the webhook response:

  "sessionId": "{{ $('Window Buffer Memory').params["sessionKey"] }}",
  "agentMessage": "{{ $json.output }}"

Hope that makes sense, grateful for any help!

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @Jon_Boi_EGB,

Try the below… So we check to see if the sessionId is set if it is we use an Edit Fields node to create a standard data structure, If it isn’t we have the same Edit Fields but it generates the sessionID. We then use a No Op node to give us a common reference point later so we can use $('Data').first().item.keyname and it will give us the data from whichever Edit Fields node triggered it.

1 Like