There are two ways that you can deploy the Moodle Chatbot App
Deploy as a docker container
Install in a Linux/Windows server
for the chatbot to work, the Moodle Chatbot Plugin must be installed.
Chatbot Configuration File
While on the code root folder, navigate to MoodleBot > appsettings.json. The following are some of the most important parameters to configure.
TwilioNumber: chatbot telephone number. Users have to write a message to this number to start the conversation. All numbers need to have the following format: whatsapp:<telephone number>.
"TwilioNumber": "whatsapp:+447862143841",
TwilioAccountSid: can be found in the Twilio console dashboard, in the ‘Account info’ section.
TwilioAuthToken: can be found in the Twilio console dashboard, in the ‘Account info’ section.
TwilioValidationURL: this URL hast to be the same you use as the webhook URL for incoming messages on Twilio (read why here). Remember, the webhook URL has to point to the port 3979 of the server where the chatbot is hosted.
"TwilioValidationUrl": "http://<host>:3979/api/twilio",
Moodle.AuthToken: authentication token, used to consume Moodle’s API.
Moodle.MoodleAPI.BaseUrl: Moodle instance URL for all API calls.
"BaseUrl": "https://<host>/webservice/rest/server.php?moodlewsrestformat=json",
You will find many more parameters already pre-populated (e.g., ActivityPageSize to configure how many Moodle activities the user will see in a single WhatsApp message), you can leave everything as it is for now.
In the same directory as the configuration file, you will also find a folder named ‘DBTables’. It is called like that because all the .json files it contains were originally tables from a database the chatbot no longer has, it is a deprecated feature.
In these files, you can customize the majority of the chatbot messages. For example, if you wish to change the chatbot welcome message, edit the file ‘BotMessages.json’ and search for the MessageName parameter with the value 'WELCOME_MESSAGE'. You will find an object representing the message, and it is possible to modify the Message parameter with the text you prefer.
Keep in mind, you also have to change the welcome message for the other languages. The parameter ‘LanguageISOCode’ determines for which language the message is for.
Option 1: Deploy using Docker
Due to the many configuration options the chatbot has, a Docker image is not currently available. However, in this section, you can find all the steps on how to build the Docker image yourself and run the chatbot app as a Docker container.
Create Docker image and container
After configuring the chatbot, navigate to the code root folder. The file ‘Dockerfile.txt’ contains all the metadata to create the image.
Run the following command to create the Docker image.
docker build -t chatbot -f Dockerfile.txt .
After the image is successfully built, run the following command to start the container.
docker run -p 3979:80 chatbot -d
This binds port 80 of the container to port 3979 of the host machine.
Option 2: Install on a Windows/Linux Machine
This option works best for a development and testing environment.
Open the chatbot source code using your favorite IDE. We recommend Visual Studio as this was the IDE used during development and the code comes with a .sln file that you can easily open as a VS Solution.
Make sure you have .Net installed on your machine (min version .Net Core 3.1). If you are using Visual Studio, you can get all the required tools for .Net development from the IDE installer.
In order for Twilio to be able to communicate with the chatbot on a local machine, it is necessary to use a tool that exposes your localhost to the internet. For this tutorial, we are going to use Ngrok.
Download Ngrok and create a file named ‘ngrok_composer.yml’ in the same directory where ngrok.exe is located.
Copy the following text into ngrok_composer.yml
version: 2 authtoken: <REPLACE WITH YOUR NGROK TOKEN> tunnels: first: proto: http addr: https://localhost:3979/ second: proto: http addr: 80
It is assumed that a local Moodle instance is running on port 80, if this is not true, there is no need to add a tunnel for this port.
Open ngrok.exe file and run the following command.
ngrok start --config=ngrok_composer.yml --all
You will be presented with two URLs: one for localhost:80 and the other for localhost:3979. Use these URLs to configure the chatbot appsettings.json and the Twilio number webhook.
After the configuration is done, proceed to run the code using the ‘DialogBot’ startup profile. If it was successfully compiled, you should see the following screen in the browser.
Test the Moodle Chatbot App
To confirm the installation was successful, write any message to the chatbot telephone number you configured in the appsettings.json file. The chatbot should answer with a welcome message and start the registration process.
To see in detail the chatbot flow and all the interactions users will have, please go to Moodle Chatbot App Interactions.