Retrieve user context

Problem

You need to retrieve data from the user’s context for use in your existing flow.

Solution

Use the change switch node to check if expected context is there and the change node to make context $referenceable

Example

Save user name

[{"id":"e7f9ac15.f89fa8","type":"start","z":"36a987e3.d6314","name":"Start","x":160,"y":240,"wires":[["8a9e250.5133cd8"]]},{"id":"59d7df2f.898b4","type":"change","z":"36a987e3.d6314","name":"","rules":[{"t":"set","p":"payload.user.name","pt":"msg","to":"payload.context.name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":220,"wires":[["abf6cd38.6e3088"]]},{"id":"abf6cd38.6e3088","type":"dialogue","z":"36a987e3.d6314","name":"","message":"Hi there $name!","messageType":"str","displayTimer":1.5,"enableDisplay":false,"x":760,"y":220,"wires":[[]]},{"id":"8a9e250.5133cd8","type":"switch","z":"36a987e3.d6314","name":"","property":"payload.context.name","propertyType":"msg","rules":[{"t":"nnull"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":240,"wires":[["59d7df2f.898b4"],["f7000c3e.64262"]]},{"id":"f7000c3e.64262","type":"dialogue","z":"36a987e3.d6314","name":"","message":"Hi there!","messageType":"str","displayTimer":1.5,"enableDisplay":false,"x":760,"y":260,"wires":[[]]}]

Discussion

User context lives at msg.payload.context. The change node can be used to set the value here to msg.payload.user.name so that it can be referenced as $name

If msg.payload.context.name is not always available a swith node checking that it is not null can be use to switch up what message is used.