Introduction
Echo is DEX8 helper for sending messages from robot to web panel.
The messages are real-time, websocket messages so when it's used a message in
string, object, error or image base64 format will be sent to web panel.
Tracking real-time events with classic API HTTP responses in most cases is not possible.
That's why we developed Echo library which is very useful because it gives you the ability to track crawler,
scraper or any other automation process in real-time through web panel (web browser) or Linux/win/mac terminal.
Notice:
During task development a task is tested by the command $ dex8 start
.
When this command is used echo messages will not be sent to web panel but only printed in the terminal.
Echo class instance is already injected into the FunctionFlow library, so it can be utilised in a very simple way as is shown in this example:
https://github.com/smikodanic/dex8-examples/blob/master/005echo/main.js
main.js
--------------------------------------------------------
module.exports = async (input, lib) => {
const ff = lib.ff;
const echo = lib.echo;
echo.log('rnd = ', Math.random().toFixed(6), ' --- ok'); // send string
echo.objekt({a: 1, b: 'some string', is_active: false}); // send object
echo.error(new Error('Intentional error !')); // send error
echo.image('iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='); // send base64 image string
return input;
};
Properties
Property | Description | Type | Default |
---|---|---|---|
short |
Prints short messages in the terminal. | boolean | false |
Methods
log(str1, [str2, ...])
Sends comma separated strings to the web panel and prints it in the terminal. It acts likeconsole.log()
.
echo.log('first message', '2nd message', 3);
objekt(obj)
Sends object to the web panel and prints it in the terminal.echo.objekt({x: 'something', y: 345});
error(err)
Sends error to the web panel and prints it in the terminal.echo.error(new Error('Intentional err !!!'));
image(img_b64)
Sends image in base64 (string) format. It's useful for sending screenshots (captcha) to the web panel where user can analyse it.echo.image('iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==');
changeRoom()
Changes socket.io room e.g. event.echo.changeRoom('room_apiRoutes).objekt({uri: '/deployments/modify/5e08907172cdfa212761907d', body: {action: stop}});
Practical Examples
1. Converting long echo messages into short messages (in terminal)
There are two ways to convert long echo messages into short messages:a) use
echo.short = true;
inside the code (as is shown in the example below)
b) use
-s
option in dex8 command, for example: $ dex8 start -s
module.exports = async (input, lib) => {
const ff = lib.ff;
const echo = lib.echo;
echo.short = true;
echo.log('rnd = ', Math.random().toFixed(6), ' --- ok'); // send string
echo.objekt({a: 1, b: 'some string', is_active: false}); // send object
echo.error(new Error('Intentional error !')); // send error
return input;
};
long echo mesages

short echo mesages
