Skip to content
This repository was archived by the owner on May 24, 2021. It is now read-only.

Getting started.

HoloPanio edited this page Apr 2, 2021 · 3 revisions

Getting Started

Dogehouse.js is a powerful implementation of the DogeHouse API that was designed to make creating bots and contacting the DogeHouse API as simple as ever. Through the collective effort of the DogeGarden team, we can provide you with the ability to create anything you would like to use on Dogehouse. Today, you will learn how the library works and what you can do to get started using the library.

How does it work?

When you start working with the dogehouse.js library, you will notice that to take full advantage of it, you would need to connect to the DogeHouse API which will allow you to begin sending and receiving data to and from DogeHouse. The DogeHouse API runs on a WebSocket connection, so when requests are sent to the DogeHouse API, they're being sent through the DogeHouse Socket connection setup when you started your application.

Setting Up Your Workspace

Now that you understand how the library works, it's time for you to setup your workspace. To start off you will need to create a folder for your project to be made in, once you've done that it's time to actually start setting things up.

First you want to set up your package.json file which you can do by simply running npm init -y, and that will automatically setup your npm package file. Once you've got your package file setup, you need to install your dependencies.

To install the necessary dependencies, you can run the following command within the project directory which will automatically setup the packages in the folder node_modules.

npm i dogehouse.js dotenv --save

Now that you have your dependencies installed, you can begin creating your application. First you need to create a file called app.js, which is the file that you will be writing your actual code. Once you've created that file, you will also need to create a file called .env, which is where you will be storing your DogeHouse authentication token and refresh token as environment variables.

Getting Your Tokens

Now that you've set up your workspace, it's time to get your authentication token, and your refresh token. These tokens are the values that allow our library to communicate with the DogeHouse API. Now, I would like you to pay close attention because getting your tokens can be a confusing process if you don't know what you're doing.

First, you're going to want to get a new account setup. Now, you might be asking yourself, "Why do I need to get a new account?", but it is actually quite simple. Because DogeHouse is a voice platform, it requires a WebSocket connection to stay open at all times, but you cannot have two of these web socket connections open at the same time, even if you aren't in a room, therefore you will need to create a new account so that you can perform all of your actions under this new account as appose to giving up your ability to use your main account whilst you are working on your bot.

Once you've created your new account, you will need to get the tokens for these accounts. In order to get these tokens, you will need to open up your browser and go to https://dogehouse.tv/ and login to your dedicated bot account. Once you've logged into this account, I would like you to press f12 on your keyboard which will open Inspect Element on your screen.

Now that you have inspect element open, please navigate to the Application tab at the top of your screen. Once you're there, you will see a sidebar with a few different categories. You will want to collapse the local storage tab under Storage. Once you've collapsed it, you will want to click on the tab that says https://dogehouse.tv which will open up a table with all of your local storage for DogeHouse.

After opening up your local storage, you will want to find the values to the right of @toum/token and @toum/refresh-token. These are the tokens that will allow the DogeHouse API to authenticate you. Once you've obtained these tokens, it's time to head back over to your workspace where you will be placing them in your .env file. To do this, you will want to place the following block of code into your .env file.

DOGEHOUSE_TOKEN=<token>
DOGEHOUSE_REFRESH_TOKEN=<refresh-token>

Once you've place the following block of code into your .env file, you will want to simply replace <token> with the value from @toum/token, and <refresh-token> with the value from @toum/refresh-token.

Creating Your First App

Now that you've got your workspace setup and your tokens defined, you can now begin creating the actual application itself. The first thing you're going to want to do is declare your enviornment configuration file. To do this, you will simply place the following line of code at the top of of your app.js file.

require('dotenv').config();

Now that you've imported your .env file, it's time to define your dogehouse.js Client. To do this you are going to import the Client from the dogehouse.js library and create a new instance of it.

const { Client, EVENT } = require('dogehouse.js');
const app = new Client();

Once you've imported the library and initialized the client, you can finally connect your application to the DogeHouse API. First we are going to create some variables to reference when calling our tokens. Then will will call the connect method which will take our tokens and use them to authenticate the client with the DogeHouse API. Once connected you will also want to join a room which will be shown below.

const token = process.env.DOGEHOUSE_TOKEN;
const refreshToken = process.env.DOGEHOUSE_REFRESH_TOKEN;

app.connect(token, refreshToken).then(c => {
    console.log('Connected!');
    app.rooms.join('YOUR ROOM ID');
});

Now that you've successfully connected your bot to the DogeHouse API, you can now create an Event Listener to listen for new chat messages. This event listener will allow you to listen for new chat messages in the room that you're in so that you can easily pull messages as they come up. This event's job will simply be to log the messages to console to show the power that this has.

app.on(EVENT.NEW_CHAT_MESSAGE, async (message) => {
    console.log(`${await message.author.username}: ${message.content}`);
});

Once you run this, you will be connected to the DogeHouse that you defined and you will also begin seeing chat messages from the room that you joined in your terminal.

Complete Source Code

require('dotenv').config();

const { Client, EVENT } = require('dogehouse.js');
const app = new Client();

const token = process.env.DOGEHOUSE_TOKEN;
const refreshToken = process.env.DOGEHOUSE_REFRESH_TOKEN;

app.connect(token, refreshToken).then(c => {
    console.log('Connected!');
    app.rooms.join('YOUR ROOM ID');
});

app.on(EVENT.NEW_CHAT_MESSAGE, async (message) => {
    console.log(`${await message.author.username}: ${message.content}`);
});

Conclusion

Now that you have successfully created your first DogeHouse Bot using the dogehouse.js library, I would like to urge you to use this library responsibly so that we can maintain a respectful enviornment on the DogeHouse Platform

Last Updated: Apr 2, 2021 @ 2:33PM CT