Spanish Total.js
English
Documentation For AI agents
Contents

Message reference

The properties and methods of a message in the server code.

.md GitHub
On this page

A message carries data from an output of one node to an input of another. instance.message receives it, usually as $:

instance.message = function($) {
    var data = $.data;
    $.send('output', data);
};

Every message must be sent on or ended. See Inputs, outputs and messages.

API

property

$.data

The data of the message.
property

$.input

The id of the input on which the message arrived.
property

$.output

The id of the output from which the message came.
property

$.fromid

The id of the node that sent the message.
property

$.fromcomponent

The id of the component of the node that sent the message.
property

$.toid

The id of the node that received the message.
property

$.repo

An object that travels with the message from node to node.

A node stores values in it, and the nodes after it read them.

Keep a value
$.repo.orderid = 1001;
$.send('output');
property

$.refs

References shared by all copies of the message.

The Route component stores the HTTP request in $.refs.controller, and the Response component answers through it.

property

$.instance

The node that received the message.
property

$.main

The FlowStream.
property

$.error

The error stored by $.throw().
method

$.send(output, [data])

Sends the message to the nodes connected to an output.
ParameterTypeDescription
output String The id of the output.
data? Object New data for the message.

Returns Number The number of nodes that received the message.

Without data, the message keeps its data. With null as output, it goes to every output that has a connection. When no node receives it, the message ends.

Send new data
$.send('output', { name: 'Jane' });
method

$.destroy()

Ends the message.

Call it for every message that you do not send on. $.end() does the same.

method

$.throw(error)

Reports an error to the designer and stores it in $.error.
ParameterTypeDescription
error String The error message.

It does not end the message.

Report and end
$.throw('Demo error');
$.destroy();
method

$.replace(text, [data])

Fills in variables, and other keys from the message.
ParameterTypeDescription
text String The text with keys in braces.
data? Object Values to use instead of the message.

Returns String The text with the values.

Works like instance.replace(), but keys that are not variables are read from the message, for example {data.name}. $.variables() does the same.

method

$.rewrite(data)

Replaces the data of the message.
ParameterTypeDescription
data Object The new data.

Returns Object The message.

method

$.status(data, [delay])

Sends a status of the node that received the message.

The same as instance.status().

method

$.on(name, callback)

Listens to an event of the message.
ParameterTypeDescription
name String The event, for example end.
callback Function The function to call.

The end event runs when the message and all the copies sent from it have ended. $.once() listens once and $.off() stops listening.

Know when the flow is finished
$.on('end', function() {
	instance.status('finished');
});
$.send('output');
Made in Europe