This guide will walk you through the process of setting up your LiveEdu chat bot and customizing it for your needs.
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.
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
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:
Fill in the “credentials.js” file with the following:
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
{ "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.
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.
module.exports = [{ types: ['message'], regex: /hello/, action: function( chat, stanza ) { chat.replyTo( stanza.user.username, 'Welcome to the stream!' ); } }]
This plugin will reply “Welcome to the stream!” if someone types “hello” or “hi!”
{ "plugins": { "notifications": true, "api-triggers": true, "lctv-bot-welcome-plugin": true }, }
Let’s store the welcome message in “setup/custom/settings.json” file:
{ "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:
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.
We’re thrilled to announce an exciting opportunity for you to win not one but two…
Acquiring practical skills is crucial for career advancement and personal growth. Education Ecosystem stands out…
Artificial Intelligence (AI) has been making significant strides in various industries, and the software development…
Another week to bring you the top yield platforms for three of the most prominent…
If you hold a large volume of LEDU tokens above 1 million units and wish…
It’s another week and like always we have to explore the top yield platforms for…