Echo

Connect robots and web panel with real-time messages

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.

Websocket

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;

  await echo.log('rnd = ', Math.random().toFixed(6), ' --- ok'); // send string
  await echo.objekt({a: 1, b: 'some string', is_active: false}); // send object
  await echo.error(new Error('Intentional error !')); // send error
  await 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

async log(str1, [str2, ...])

Sends comma separated strings to the web panel and prints it in the terminal. It acts like console.log().
await echo.log('first message', '2nd message', 3);

async objekt(obj)

Sends object to the web panel and prints it in the terminal.
await echo.objekt({x: 'something', y: 345});

async error(err)

Sends error to the web panel and prints it in the terminal.
await echo.error(new Error('Intentional err !!!'));

async 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.
await echo.image('iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==');

async input(inp)

Send input which should be listened with the listen() method.
inp - text in front of the input field (label)
await echo.input('company'));

async listen()

Listen for the first message from the web panel or API.
await echo.input('company'));

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;

  await echo.log('rnd = ', Math.random().toFixed(6), ' --- ok'); // send string
  await echo.objekt({a: 1, b: 'some string', is_active: false}); // send object
  await echo.error(new Error('Intentional error !')); // send error

  return input;
};

long echo mesages

long echo messages


short echo mesages

short echo messages