Websocket connection

TonCut for Automation is a Websocket server. So, what you need is just connect to it and maintain the connection.

When connecting just make sure you are using correct protocol (ws: or wss:), hostname/IP and port number. For development purposes you will probably use ws://localhost:8080, which is the default.

In the next sections you can read more about commands and events used by the API.


The Websocket API does not have any authorization mechanisms, so you should take care of it yourself to ensure that access to the API is properly secured.


Check out the examples we have prepared. You can find them in the directory where TonCut for Automation was installed, in the Examples subdirectory. There you will find sample code for different programming languages.


Connecting to WebSocket API

let socket = null;

function onOpen(event) {
  // Now you can get status, job list and job info.

function onClose(event) {
  console.log('Connection closed!');

  // Wait 1s and retry.
  setTimeout(connect, 1000);

function onError(event) {
  console.log('Connection error: ', event);

function onMessage(event) {
  data = JSON.parse(event.data);

  if (data.id) {
    // It must be a command response.
    // You need to keep requests in a map to match them here.
  } else {
    // It must be an event.

function connect() {
  socket = new WebSocket('ws://localhost:8080');
  socket.addEventListener('open', onOpen);
  socket.addEventListener('close', onClose);
  socket.addEventListener('error', onError);
  socket.addEventListener('message', onMessage);