This guide will walk you through the process of setting up your LiveEdu chat bot and customizing it for your needs.
INSTALL NODE.JS
The base bot we will work with was developed with node.js, so if you don’t have it installed, visit the Node.js official website to download the package for your platform and install it.
We recommend you use the LTS release.
For example, if you are using Windows then download the MSI package and go through the standard setup procedure.
Once the installation has finished, verify it by typing “node -v” in the terminal.
GET BASE BOT
If you are a git user, clone the base bot sources from github with this command:
git clone https://github.com/ArtemiusUA/livecodingtv-bot.git
Or download and unzip the archive:
https://github.com/ArtemiusUA/livecodingtv-bot/archive/master.zip
SETTINGS FOR YOUR LiveEdu ACCOUNT
Navigate to the “setup” directory in the bot’s directory.
Create a folder named “custom” in the “setup” directory.
Create a “credentials.js” file and “settings.json” file in the “custom” directory.
Find your XMPP password on the LCTV page:
- Open your live stream page ( https://www.livecoding.tv/USERNAME ).
- Open Dev Tools (“ctrl+shift+i”) and switch to the Elements tab.
- Search the HTML content for “password”.
- The XMPP password will be a long string in an object containing “jid” and “password”.
Fill in the “credentials.js” file with the following:
1 2 3 4 5 6 7 8 9 10 11 |
var username = 'LCTV_BOT_USERNAME'; var password = 'XMPP_BOT_PASSWORD'; var room = 'LCTV_USER_WHERE_BOT_WILL_BE'; module.exports = { room: username, username: username, jid: username + '@livecoding.tv', password: password, roomJid: room + '@chat.livecoding.tv' }; |
Fill in the “settings.json” file with the following
1 2 3 4 5 6 |
{ "plugins": { "noifications": true, "api-triggers": true } } |
Run “npm install” in terminal, to install dependencies.
Run “node index.js” to start the bot.
If you are on Windows, you will see a firewall prompt to allow network access. Click on the Public Network checkbox and select Allow.
At this point the bot is working and ready to accept standard commands. You can enter the following commands in the chat window to test it:
!status – Returns the user status.
!subject [type subject] – Sets the room‘s subject to {subject}.
!todo – List the current TODOs.
!top [input number] – Displays the top {number} viewers.
CUSTOMIZE BOT’S FUNCTIONALITY
To customize the bot’s functionality for your needs, you can go with plugins. You can find some plugins on github, or create your own.
Let’s go through the plugin development process.
1 . Check if there is a “plugins” directory in the “bots” directory. If not, create it.
- Each plugin lives in its own subdirectory in “plugins”, so you have to create a new directory for your plugin.
- All plugins require “index.js” as an entry point. This file is used by the bot to process incoming messages and react to them. Create an “index.js” file in your “plugins” directory.
- The “index.js” file must export an array of command objects to incoming messages handlers. Each command is checked with regexp against incoming messages, and when a match is found, the actions function of a command is invoked. Example:
1 2 3 4 5 6 7 |
module.exports = [{ types: ['message'], regex: /hello/, action: function( chat, stanza ) { chat.replyTo( stanza.user.username, 'Welcome to the stream!' ); } }] |
- To enable the plugin, update the bot’s settings file ( “setup/custom/settings.json” ) with your plugin:
1 2 3 4 5 6 7 |
{ "plugins": { "notifications": true, "api-triggers": true, "lctv-bot-welcome-plugin": true }, } |
- All plugins have access to these settings, stored in the “setup” directory. Also, plugins can have their own settings, stored in “settings.json” in the “plugins” directory.
Let’s store the welcome message in “setup/custom/settings.json” file:
1 2 3 4 5 6 7 8 9 10 |
{ "plugins": { "notifications": true, "api-triggers": true, "lctv-bot-welcome-plugin": true }, "lctv-bot-welcome-plugin": { "welcome-message": "Welcome to the stream from settings" } } |
And then customize the plugin code by using this setting:
1 2 3 4 5 6 7 8 9 10 |
const Settings = require('../../utils/Settings'); module.exports = [{ types: ['message'], regex: /hello/, action: function( chat, stanza ) { chat.replyTo( stanza.user.username, Settings.getSetting("lctv-bot-welcome-plugin","welcome-message")); } }] |
For further examples, you can check other bot plugins on github, or get the core commands code.