(This is from my experience of messing around with attempting to get it working today)
You're probably going to want to know how to use Javascript, specifically AJAX and Websocket event handling, if you want to be able to upload the data you pull from the API. Also you'll need to know how to deal with .JSON responses (Which is what the API will return with).
Deepbot itself acts as the websocket server so you won't need to worry about setting up a websocket server yourself although it would probably be good practice to do so in the learning process because it is an interesting technology. I am only going to show you how to actually pull data from the server and show it in an alert. What you do from there is up to you but these steps should at least get you started
Step 1) Find your API keyTo stop random people from being able to access your bot's info there is an API key which is unique to you available so only you can access this, essentially, local API. You can find this by going to
Config tab -> Master Settings -> Scroll down to where it says API Secret
Copy this key for later
Step 2) Open the WebSocket connectionAssuming you've made your HTML page (Doesn't have to be fancy, just something basic) and that you have kept deepbot open you'll now need to open the websocket connection. To do this is actually pretty simple due to the WebSocket API being included in the HTML5 specification (Which included Javascript I believe). The Deepbot websocket server runs on port 3337 on your localhost (or 127.0.0.1 if localhost doesn't work). A typical websocket connection begins with ws:// and the full format usually goes
ws://host:port/
Knowing this, the following javascript code will allow you to open the websocket connection
var ws = new WebSocket('ws://localhost:3337');
Now that you have the variable set up it's time to deal with the incoming responses. The events we're interested in are the onopen and onmessage events. Listening for these is actually pretty easy. The following Javascript code will allow you to deal with these events
ws.onopen = function() {
//Code Will Go Here
};
ws.onmessage = function(e) {
//code will go here
};
Step 3) Allow API AccessStill have that API Secret from step 1? You're going to need it here. WebSockets are bi-direction meaning they can send data both ways. We have a function available to us that allows us to send data to the server simply called send. Once this data is sent it will then (when it pulls the data we need) fire the onmessage event (Which in this example we are just going to fire a browser alert containing the information).
In the
Deepbot API you will notice the bits in bold. This is the data that you will send when you fit it to your needs. Some are simple and others have multiple parameters you can change. Give it a read to try and wrap your head around it. Anyway, we can only send data when we know that the websocket is open, otherwise your browser will throw an error. Place the following in the onopen function that you coded in step 2 replacing the last bit with the key you copied earlier.
ws.send('api|register|YOURSECRETKEYFROMSTEP1');
Now that we've done that, we need to deal with the message that gets returned. Usually you would put this into a variable and deal with it accordingly but for this example will simply just make an alert appear with the data sent back to us. To do alerts in javascript simply do the following;
alert(e.data);
Step 4) See it workingSave the page you've created and run it on a web browser that supports websockets. I used Chrome but any modern browsers should support the standard. Once you've opened it hopefully very soon you should see a popup containing the following
{
"function": "register",
"param": "register",
"msg": "success"
}
If you see this, congratulations. You successfully connected to your Deepbot Websocket API and can now do other stuff detailed at
https://github.com/DeepBot-API/client-websocket. You will need to ensure that the first message you always send is the data in Step 3) as this sets up future calls that you will make to the server.
Hopefully that should have given a slight insight to get you started on your way. Here is an extremely useful link to learn about WebSockets
http://www.tutorialspoint.com/html5/html5_websocket.htmOh, and here's the HTML/Javascript in full in case you just want to try it out yourself
<html>
<head>
</head>
<body>
<script>
var ws = new WebSocket('ws://localhost:3337/');
ws.onopen = function() {
ws.send('api|register|YOURSECRETKEYFROMSTEP1');
};
ws.onmessage = function(e) {
alert(e.data);
};
</script>
</body>
</html>
Note: This was actually a learning process for me as I hadn't actually dealt with WebSockets before. Even if you don't find this useful it was an excellent exercise for me to see how easy it actually is when you get your head around it.