This repository has now been archived as of 16/12/2021. This repository has not been maintained since May 2020
This project was created as the deliverable of my final project at Aston University, and as such, please do not contribute to this project.
This project concerns the development of a chatbot to aid the University clearing admissions process. This repository provides the webhook used by the chatbot to obtain data from the PostgreSQL database and the course information management system which allows administrators to upload and delete courses, as well as remove available spaces from courses.
Author: Sailesh Patel (160034811)
Project Supervisor: Dr Sylvia Wong
Note: The instructions have been written using and presuming the use of a Macbook running MacOS due to developmental constraints
You will also need to have a Google Account to access Dialogflow, and a Heroku account to access Heroku.
Links to relevant installation instructions have been included. These instructions require you have the following software on your computer:
Note: These instructions rely on your terminal.
Note: The PostgreSQL instructions from Heroku as opposed to PostgreSQL - this is because the Heroku instructions teach you how to configure the local database so the project can use it
The instructions related to PostgreSQL can be found in more detail at https://devcenter.heroku.com/articles/heroku-postgresql#local-setup
- Clone the repository into your local machine
- Using the command line (or terminal), navigate to the location where you have cloned the repository and run the command
npm install
to install all the dependencies the project requires - Before executing the program, use the following commands to create the relevant enums and tables required in your PostgreSQL database. Open the PostgreSQL program and click the database with your username to open the command line interface
CREATE TYPE public.degree_awards AS ENUM
('Foundation', 'Degree Apprenticeship', 'BSc', 'BA', 'BEng', 'MBA', 'MBChB', 'LLB', 'PhD', 'MA', 'MSc', 'MPhil', 'MRes', 'MArts', 'MComp', 'MEng', 'MMath', 'MPhys', 'MSci', 'LLM');
CREATE TYPE public.undergrad_or_postgrad AS ENUM
('Undergraduate', 'Postgraduate');
CREATE TABLE public.courses
(
ucas_code character varying(4),
description character varying(10000),
contact_details character varying(5000),
entry_requirements character varying(5000),
website character varying(5000),
course_name character varying(5000),
tuition_fees character varying(5000),
course_spaces integer NOT NULL,
course_type degree_awards NOT NULL,
undergraduate_or_postgraduate undergrad_or_postgrad NOT NULL,
CONSTRAINT courses_pkey PRIMARY KEY (ucas_code)
);
CREATE TABLE public.modules
(
module_code character varying(6) NOT NULL,
ucas_code character varying(4) NOT NULL,
module_title character varying(100) NOT NULL,
module_description character varying(10000) NOT NULL,
optional boolean NOT NULL,
credits integer NOT NULL,
CONSTRAINT modules_pkey PRIMARY KEY (module_code),
CONSTRAINT modules_ucas_code_fkey FOREIGN KEY (ucas_code)
REFERENCES public.courses (ucas_code) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
);
CREATE TABLE public.students
(
student_id SERIAL,
ucas_code character varying(4),
first_name character varying(60),
last_name character varying(60),
date_of_birth date,
gender character varying(10),
email_address character varying(40),
mobile_number character varying(20),
previously_applied boolean,
registered_with_ucas boolean,
ucas_number integer,
nationality_type character varying(50),
five_gcses_or_not boolean,
highest_english_qualification bytea,
highest_mathematical_qualification bytea,
highest_qualification bytea,
agent_help boolean,
agent_completed boolean,
agent character varying(400),
application_outcome character varying(400),
ucas_status character varying(400),
agent_email character varying(40),
CONSTRAINT students_pkey PRIMARY KEY (student_id),
CONSTRAINT students_ucas_code_fkey FOREIGN KEY (ucas_code)
REFERENCES courses (ucas_code) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE CASCADE
);
- After running this commands in your PostgreSQL database, run the command
npm start
and you should be able to access the course database management system atlocalhost:3000
Now we will deploy our webhook and database management system to Heroku
- Open your terminal and navigate to the directory
- Run
npm install
to ensure all the dependencies are install - Log into Heroku and create a new app. Set the region to Europe and do not set a pipeline.
- After creating the app, you will see a series of instructions in the 'Deploy' tab to deploy the app using Heroku Git. Follow these instructions to deploy the webhook.
- Navigate to the web link for your new Heroku app - it should look like this
https://[YOUR_APP_NAME].herokuapp.com/
- You should now see the Home page. Go back to your app dashboard in Heroku.
- Click on the Resource tab. In the Add-ons search bar, type in
Heroku Postgres
- You should provision the add-on to your app
- In your terminal, run the following command
heroku pg:psql
to open your Heroku Postgres database using the Heroku CLI - Copy and paste the SQL commands from the previous section in the order they are presented i.e. degree award enum first. Exit after copying and pasting the SQL commands by entering
\q
- Open your Heroku app in the browser - go to
https://[YOUR_APP_NAME].herokuapp.com/
and try and add a course to see if your database has been added - We will now log into Dialogflow to set up the chatbot.
- Create a new Dialogflow agent
- Click on the cog next to the agent name to access the settings
- Open the
Export and Import
tab - Click
Restore as ZIP
- this will remove all existing intents and entities - Upload the file named
Clearing-Bot.zip
- Once you have done this, click on
Fulfillment
on the left hand side of the screen - Change the link from
https://chatbot-fyp-webhook.herokuapp.com/getcourse
tohttps://[YOUR_APP_NAME].herokuapp.com/getcourse
and and click save at the bottom of the page - Click on the
Integrations
on the left hand side of the screen - Scroll down and find
Dialogflow Messenger
. Click the tab on the card to turn it on. - Copy the script tag to your clipboard
- Open
views\index.pug
in a text editor - Replace the existing script tag shown below in
index.pug
with the script tag you copied from Dialogflow
<script src="https://www.gstatic.com/dialogflow-console/fast/messenger/bootstrap.js?v=1"></script>
<df-messenger intent="WELCOME" chat-title="Clearing-Bot" agent-id="3246b9f6-7370-45fc-90f3-05fcf7895761" language-code="en"></df-messenger>
- Make sure that the
<df-messenger>
opening tag is all on one line as in the example above - In your terminal, type
git add -p
and add the change you have made - In your terminal, type
git commit -m "add my dialogflow messenger"
- In your terminal, type
git push heroku master
- You have now completed your deployment.
- You may wish to add some courses to your chatbot. Go to the 'Add Course Programme' page to add a course