Message Object

What is the Message Object?

In a Contextual Flow, the Message Object is a versatile container that holds all data and properties being processed, as they traverse through a flow.

  • Read: Nodes can access the current properties of the message object, such as msg.payload.

  • Modify: Nodes can change the contents of the message object.

  • Extend: Nodes can add new properties to the message object, enriching the data structure.

Typically starting with an msg.payload property, which contains the primary data from an input node, the message object can be enriched with additional properties such as msg.topic, msg.myCustomProperty, or any other custom attributes as needed. This flexibility allows for the creation of dynamic and responsive flows, where the message object evolves in real-time, carrying with it all the necessary information required by subsequent nodes. The comprehensive structure of the message object is key to the powerful and modular nature of software built using Contextual.

Where does the content of the Message Object come from?

The content of the message object is determined by the source of the data being sent to the flow, so varies widely. In Contextual, it is common for the message object to contain...

  • JSON with all details from a create, update, delete, or other action for a Record of an Object Type

  • JSON with the formatted output of a...

Movement of the Message Object in a Flow

  1. Starts at an Input Node: The journey of the message object begins at an input node, such as an Event Start, HTTP In node, or any other input source. This node receives data and creates a message object, typically containing a payload property (msg.payload) with the initial data.

  2. Travels Through Processing Nodes: The message object moves along the wires in the flow to various processing nodes. Each node can read, modify, or extend the properties of the message object.

    • Example: A function node can add a timestamp to the message object by including a line like msg.timestamp = Date.now();.

  3. Conditional Routing and Transformation: Nodes like switch nodes or change nodes can conditionally route or transform the message object.

    • Example: A switch node might route messages to different outputs based on the value of msg.payload.severity.

  4. Extending the Message Object: Nodes can add new properties to the message object beyond msg.payload. This allows for a richer and more complex data structure to be built as the message progresses through the flow.

    • Example: An HTTP Post node might interact with an external system using an API call, and add the resulting response to a new msg.apiResponse property.

  5. End at an Output Node: Finally, the message object reaches an output node, such as an HTTP Response node, MQTT Out node, or a database node. This node sends the modified message object to an external system.

Last updated