Documentation

Bot post-message API

If you have any special AI bots, you can integrate them via API.

Overview

We provide a WebSocket (Socket.io) API for adding AI bots to a chat.

When creating a connection, you need to provide a Bearer token obtained from the Admin panel.

This token is required to establish a connection to our service.

Example

const socket = io('wss://bot.watchers.io/', {
  transports: ['websocket'],
  upgrade: false,
  auth: {
    bearer: 'Bearer token from Admin panel'
  }
});

After the connection is established successfully, you can use the commands below.

external/listen

You can listen to all messages from certain rooms via roomID.

Params

ParameterTypeRequiredDescription
roomIdstringYesRoom id of room you want to listen messages
apiKeystringYesAPI key of your project, obtained from Admin panel → Settings → APIKey

Example

const socket = io('wss://bot.watchers.io/', {
  transports: ['websocket'],
  upgrade: false,
  auth: {
    bearer: 'Bearer token from Admin panel'
  }
});

socket.on("connect", () => {

	//Start listening message from room
  socket.emit("external/listen", { "test", "apiKey"}, (response) => {
    console.log(response);
  });

  //Messsages handler
  socket.on('message', (value) => {
    console.log(value)
  })
})

On message response object

{
  "project": "test",
  "roomId": "144444",
  "message": {
    "id": 102,
    "text": "test"
  },
  "userId": "123"
}

external/send

You can send messages from the bot the via “external/send” command

Params

ParameterTypeRequiredDescription
roomIdstringYesRoom id of room where you want to listen to messages
apiKeystringYesAPI key of your project, obtained from Admin panel → Settings → APIKey
userIdstringYesBot ID from Admin panel
textstringYesMessage text

Example

const socket = io('wss://bot.watchers.io/', {
  transports: ['websocket'],
  upgrade: false,
  auth: {
    bearer: 'Bearer token from Admin panel'
  }
});

socket.emit("external/send", { roomId, apiKey, userId, text: messageText }, (error) => {
  console.log(error); 
});