-
Postgres with rasa
- This dirctory contain all files to integrate rasa chatbot with posgtres, and let rasa fetch training data from the DB.
-
Rocketchat with rasa
- This dirctory contain all files to integrate rasa chatbot with Rocketchat, This use Omnichannel and Livechat features.
- FromDataBase
- This directory contain the
JSON
data fetched from the Postgres DB.
- This directory contain the
- data_not_used
- This directory contain the
yml
data that rasa uses by defult to train the bot, but we dont use it here (as we fetch data from DB).
- This directory contain the
- database
- Thid directory contain
sql
file to create theintent
table and add some inital data to it. - models
- This directory will contain the training models data.
- Thid directory contain
- config.yml
- This file contain the configuration for the bot (Custom importer).
- converter.py
- This file contain the conversion script, that convert
Json
data from DB toyml
data.
- This file contain the conversion script, that convert
- custom_importer.py
- This file contain the interface with the DB, converter, and rasa data.
- database_wrapper.py
- This is a wrapper for DB, that contain some methods to fetch, add, edit on the DB.
- docker-compose.yml
- This is the docker compose file, that contain all the services used.
- domain.yml
- This file contain the intents and the responses for the bot.
- db_command.py
- This file handel the database. (add, update, delete, getValue, get)
you must have the following installed to test
- git
- docker
- Make new dir for the project
$ mkdir GluuBot
- Go to the new directory
$ cd GluuBot
- Pull the repo using
$ git pull https://github.com/AbdelwahabAdam/GluuBot.git
- Up the compose
$ docker-compose up -d
- To install Rasa on Ubuntu we should first install a modern python version.
# First we should update apt, just in case.
sudo apt update
# Install python
sudo apt install python3-dev python3
# Once it is installed you should be able to confirm the versions.
python3 --version
pip3 --version
- Now that we have these tools installed we can create a folder for our Rasa project.
# Create and Enter Folders
mkdir rasaprojects
cd rasaprojects
# Next we install python3-pip so that we can install python packages
sudo apt install python3-venv
# We can now create a virtualenv
python3 -m venv ./venv
- With our virtualenv available we can now active it and install Rasa.
# Source the virtualenv
source ./venv/bin/activate
# Install Rasa and Upgrade pip
python -m pip install --upgrade pip rasa
# Our `python` now refers to the python version in the virtualenv.
# From here you should be able to use Rasa
python -m rasa --help
python -m rasa init
- Now we can use
rasa train
andrasa shell
rasa train
will read the training data fromdata
dir anddomain.yml
file, and then the training process starts.rasa shell
will open an interactive session in the shell to chat with the bot.
- Creat a new python file called
custom_importer.py
- copy the content from same file from the git repo
- Open
config.yaml
and add the importer section - The defult importer used with rasa is the
RasaFileImporter
importers:
- name: "RasaFileImporter"
- Add the Custom importer
importers:
- name: "custom_importer.MyImporter"
- NOTE
- you can add the defult importer as well and rasa will combine the both, but Data directory must be there in your project dir.
importers:
- name: "RasaFileImporter"
- name: "custom_importer.MyImporter"
repository: "AbdelwahabAdam/hopa-rasa-demo"
- simply replace the
config.yaml
in the repo with the one generated fromrasa init
.
- Update packages list
$ sudo apt update
- Install postgres
$ apt install postgresql postgresql-contrib
- Check PostgreSQL status
$ service postgresql status
- you should see
active
- you should see
- First call
rasa train
- Then if every thing works well call
rasa shell
to test the bot in the terminal.
You can use this file to manpulate the database.
get
: to get all data in the DBex: python3 db_command.py get
add
: to add a new valuesex: python3 db_command.py add id intent_name ['intent','example'] responce
update
: to update certain valueex: python3 db_command.py update response Bye! id 1
getValue
: to get certain valueex: python3 db_command.py get_Value response id 1
delete
: to delete a row (on id)ex: python3 db_command.py delete 1
RocketChat service can installed using the following command:
sudo snap install rocketchat-server
also, we can Manage the RocketChat service using the following:
systemctl status
snap.rocketchat-server.rocketchat-server.service
The MongoDB that powers the RocketChat server is ran by the
snap.rocketchat-server.rocketchat-mongo.service
we can use all systemctl commands with it.
- bot_rasa
- This directory contain all training data for rasa chatbot.
- docker-compose.yml
- This is the docker compose file, that contain all the services used.
- redirectServer.py
- This file creat a intermediary server that recieve from Rasa App in rocket and send it to rasa server and then revice from rasa server and sent the responce back to Rasa App in rocket.
There are several method to integrate both. the best way using the rasa app from rocketchat market.
-
create a new user.
Setting
>Users
-
This new user must have these 2 roles.
- bot
- livechat-agent
-
enable Omnichannel. -
Administration
>workspace
>setting
>Omnichannel
>Omnichannel enabled
-
Assign new conversations to bot agent. -
Administration
>workspace
>setting
>Omnichannel
>Routing
>Assign new conversations to bot agent
- make sure the bot assign as
Agents
Administration
>Omnichannel
>Agents
- Add new
Department
- add department with the name
general
,enable
it and add the bot user as Agent >> Make sure to pressAdd
- then add email for it and hit
save
- add department with the name
- Download directly from Rocket.Chat marketplace
- Fill neccessary fields in
Setting
- Bot Username (required)
- the bot user name we created.
- Rasa Server Url (required)
- The URL for rasa server, here we will put another url for a python flask server. >> will be demonstrated later.
- ex: http://ip:4000 >> put you device ip, dont put localhost
- Default Handover Department Name (required)
- add
general
that we created before.
- add
- Bot Username (required)
- There is an error in the Rasa App, it sends data that rasa server couldn’t parse
EX:
- data that was sent by rasa app in rocket market >> single quotes
[{'recipient_id': 'default', 'text': 'Hey! How are you?'}]
- using postman to check, this body was parsed successfully >> double quotes
{
"sender": "WMXQiQaQkxeTNLa2G",
"message": "hi"
}
- this body was failed >> single quotes
{
'sender': 'WMXQiQaQkxeTNLa2G',
'message': 'hi'
}
we make a turnaround with python flask to receive it and send it back with double quotes. >> redirectServer.py
- run the docker-compose.
- Follow the steps in
Rocket Chat Setup
. - Follow the steps in
Setup Rocket chat Omnichannel
. - Follow the steps in
Rasa App setup
. - Run
redirectServer.py
server. - open
localhost:3000/livechat
, choose department, then start. - The livechat will start with rasa bot as Agent.
- Any message sent will be send to
rocketchat app
> then it will be sent toFlask server
> then it will be formated and sent back toRocket chat rasa app
again.