Store Data as User Context

Problem

You need to save a value that a user gave you as context that can be used by other bots.

Solution

Use the context node to set a variable in the users context.

Example

Save user name

[{"id":"e7f9ac15.f89fa8","type":"start","z":"36a987e3.d6314","name":"Start","x":160,"y":240,"wires":[["caca105a.6f2a8"]]},{"id":"caca105a.6f2a8","type":"dialogue","z":"36a987e3.d6314","name":"What is your name?","message":"What is your name?","messageType":"str","displayTimer":1.5,"enableDisplay":false,"x":360,"y":240,"wires":[["280f02b4.516836"]]},{"id":"280f02b4.516836","type":"input","z":"36a987e3.d6314","name":"get name","x":560,"y":240,"wires":[["59d7df2f.898b4"]]},{"id":"59d7df2f.898b4","type":"change","z":"36a987e3.d6314","name":"","rules":[{"t":"set","p":"payload.user.name","pt":"msg","to":"payload.user.message","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":280,"wires":[["e9abd223.02a65"]]},{"id":"abf6cd38.6e3088","type":"dialogue","z":"36a987e3.d6314","name":"","message":"Hi there $name!","messageType":"str","displayTimer":1.5,"enableDisplay":false,"x":960,"y":260,"wires":[[]]},{"id":"e9abd223.02a65","type":"setContext","z":"36a987e3.d6314","name":"","contextsToSet":[{"key":"name","valueType":"msg","value":"payload.user.name"}],"x":590,"y":320,"wires":[["abf6cd38.6e3088"]]}]

Discussion

User context lives at msg.payload.context. The context node can be use to set a basic variable.

For more advanced objects use a Change Node.

e.g. msg.payload.context.userdata.name, and msg.payload.context.userdata.email will result in

context {
  "userdata" : {
    "name": "value",
    "email": "value"
  }
}