The goal of this simple exercise is to create a very basic chatbot, that is able to answer a few simple questions.
- Clone this repository on a machine that run NodeJS (>= 8.9) and MySQL
- Run
npm install
to install dependencies - Configure the MySQL Database
Install MySQL.
The default database name is clevy-simple-test
, check if it's available. Init the database with the following command:
mysql -u USER -p < setup/mysql-init.sql
# Replace USER by a username allowed to make changes or use root
# use -p if you need a password
Configure your database connection settings in the config/mysql.js file (see the config section).
For MySQL 8 users, you need to allow connections with:
# In the MySQL Client (mysql -u USER -p)
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'
# Exemple if user is root and password is password
node bot.js "are you a bot?"
The bot stores interaction logs in the table interaction-logs
.
Config file in config/mysql.js
// Exemple
module.exports = {
host: '127.0.0.1',
port: 3306,
user: 'root',
password: 'password',
database: 'clevy-simple-test',
};
API Tokens are stored the config
folder.
recast.key
: Recast API
For a simplicity purpose I used files to store token, it would be more secure to use environment variables in production.
The bot answers are located in the config/answers.csv. The first column contains intents, and the second answers.
The program works if no answers are valid, but the bot will never understand a question.
- NodeJS (Tested on >= 8.9)
- Axios
- MySQL (Tested on MySQL 8, should work with lower versions)