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.
Region-specific endpoints
Your WebSocket connection must use the correct regional endpoint depending on where your project was created:
Region | Location | WebSocket URL |
---|---|---|
Europe (default) | Frankfurt, Germany | wss://bot.watchers.io/ |
North America | Los Angeles, CA, USA | wss://bot.us.watchers.io/ |
South America | Santiago, Chile | wss://bot.hk.watchers.io/ |
Asia | Hong Kong | wss://bot.sa.watchers.io/ |
Make sure to use the correct WebSocket URL based on your project’s region. You can check your region in the Admin panel.
Example
// Replace the URL with the correct endpoint based on your region
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
Parameter | Type | Required | Description |
---|---|---|---|
roomId | string | Yes | Room id of room you want to listen messages |
apiKey | string | Yes | API 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
Parameter | Type | Required | Description |
---|---|---|---|
roomId | string | Yes | Room id of room where you want to listen to messages |
apiKey | string | Yes | API key of your project, obtained from Admin panel → Settings → APIKey |
userId | string | Yes | Bot ID from Admin panel |
text | string | Yes | Message 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);
});
Updated about 1 month ago