Requests to nandbox Bot API are sent as JSON objects over a WebSocket session. In order to connect to the server, you need to obtain an authentication token first.

Bot Server WebSocket URL format

wss://<nandboxBotServer>:<port>/nandbox/api/
The first request over the WebSocket method must be an authentication request.
Examples of an authentication request.
Examples of an authentication request.
json
{ "method": "TOKEN_AUTH", "rem": "true", "token": "90091784056528980:0:odIgBOQZ4lVpqSIuxpQlGzmse3hwsS" }
java
public static final String TOKEN = "90091784169275314:0:h8UbS2NPBocFGQ58U2yheNBp3LUQe1"; public class MyFirstBot { public static void main(String[] args) throws Exception { NandboxClient client = NandboxClient.get(); client.connect(TOKEN, new Nandbox.Callback() { Nandbox.Api api = null; @Override public void onConnect(Api api) { // it will go here if the bot connected to server successfuly System.out.println("Authenticated"); this.api = api; } @Override public void onReceive(IncomingMessage incomingMsg) { // it will go here if the bot received any message } // implement other nandbox.Callback() as per your bot need . }); } }
javascript
// put your provided token const TOKEN = "<PUT_YOUR_PROVIDED_TOKEN>"; const config = { URI: "<PUT_YOUR_PROVIDED_URI>", DownloadServer: "<PUT_YOUR_PROVIDED_DOWNLOAD_SERVER_URL>", UploadServer: "<PUT_YOUR_PROVIDED_UPLOAD_SERVER_URL>" } var client = NandBoxClient.get(config); var nandbox = new NandBox(); var nCallBack = nandbox.Callback; var api = null; nCallBack.onConnect = (_api) => { // it will go here if the bot connected to the server successfully api = _api; console.log("Authenticated"); sendBotMenuWithNavigationButton(Nand.BOT_ID); } client.connect(TOKEN, nCallBack);
python
CONFIG_FILE = "/config.json" f = open(CONFIG_FILE) config = json.load(f) f.close() client = NandboxClient.get(config) nandbox = Nandbox() napi = nandbox.Api() class nCallBack(nandbox.Callback): def on_connect(self, api): global napi napi = api print("Authenticated") callBack = nCallBack() client.connect(config['Token'], callBack)
After the bot is successfully authenticated, it can send further responses.
After the bot is successfully authenticated, it can send further responses.
json
{ "method": "TOKEN_AUTH_OK", "name": "Hello World”, Bot", "ID": "90091784056528980", "reference": 15269906159119, "date": 1533216558322 }