Getting Started

This page will help you get started with Dlivetv-api. You'll be up and running in a jiffy!

Installation

Before we can jump in to the code, we first need to make sure our environment is ready to run the code. To do this, follow these steps and you'll be ready to dive in to the code before you know it!

Installing Node.js

To get started, we require Node.js, Node.js is the engine that our code will run on, it turns our code in to a working application. You can download Node.js from Nodejs.org
Once downloaded, run the installer and follow the on-screen instructions to finish installing Node.

Setting up your project

Awesome! So now that we have Node.js installed, it's time to set up our project... To get started, we'll create a new folder on our PC and name it what ever we wish the bot to be named. For this example we'll be calling it HelloWorldBot but feel free to use your imagination!

Image showing the folder HelloWorldBot being created

Now that we've created the folder, we'll enter it and open a command prompt or powershell, this can be done by holding SHIFT and right clicking in the folder, you should see an option to 'open command window here'.
Image showing the Open command window here option

You'll see a black or blue box appear, this is your console. In the console, type: npm init this will tell nodes package manager to initialize the project in the current directory. You'll be asked a few questions like what you wish to name the project, feel free to answer however you like.

image showing command prompt `npm init` command

Now that our project is all set up, we need to add the API to our project. This is also done from the console. Simply type: npm install dlivetv-api and the API will be saved in your project.

Finished all that? Nice! We're now ready to jump in to the code...

Let's get coding!

So you're ready to code, eh? Let's take a look at a simple Hello, World! example.
This example will response to anyone in LKD70's channel who sends a message of "hello" with the typical Hello, World! response.

Create a file named index.js in your project folder and paste the below code in the file.

Don't forget to replace the string YOUR_REALLY_LONG_KEY with your auth key.
Not sure where to find your auth key? Check out the Finding your authKey documentation

Also, change YOUR_DLIVE_USERNAME to your Dlive displayName, for example mine is LKD70.

const Dlive = require('dlivetv-api');

const key = 'YOUR_REALLY_LONG_KEY';

const bot = new Dlive(key);

console.log('Starting bot...');

bot.on('ChatText', msg => {
  if (msg.content === 'hello') {
    bot.sendMessage('Hello, World!').then(console.log).catch(console.log);
  }
});

Testing your code

The time has come, your project is ready to be tested. To begin, we'll open up the console again in the project folder. We'll then start the bot by typing: node index.js. If all went well, we should see a message saying Starting bot... in our console.

We can now test out the functionality, head over to your channel and send a message saying 'hello'. (Please note, it's not advised to run the bot from your main account, as sending messages too close together will result in errors)

If all went well, we should see an ID appear in our console, that's the ID of the message we just sent, the message should appear in your channels chat.

What now?

Well done! you've got this far, you're now equipped to go forth and create your own great projects!

Don't forget to check out the Events and Methods documentation to really see what this API can do!
Not sure what to make next? Maybe some examples will inspire you!