Chatbot App Deployment
There are two ways that you can deploy the Moodle Chatbot App
Deploy as a docker container
Install in a Linux/Windows server
In both cases, you must edit the chatbot configuration file, which we cover first.
For the chatbot to work, the Moodle Chatbot Plugin must be installed.
Editing the 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.
You will need to acquire an activate a WhatsApp number with Twilio, a messaging provider.
TwilioNumber: chatbot telephone number. Users have to write a message to this number to start the conversation. All numbers need 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 has to be the same one you use as the webhook URL for incoming messages on Twilio (read why here). Remember, the webhook URL has to point to 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.
You will also find a folder named 'DBTables' in the same directory as the configuration file. It is called this because all the .json files it contains were originally tables from a database the chatbot no longer uses, so it is a deprecated feature. You will find an object representing the message, and modifying the Message parameter with the text you prefer is possible.
Remember that you must also change the other languages' welcome message. The parameter 'LanguageISOCode' determines for which language the message is for.
Option 1: Deploy using Docker
Due to the chatbot many configuration options, a Docker image is not currently available. However, in this section, you can find all the steps to build the Docker image and run the chatbot app as a Docker container.
Create a 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.
After successfully building the image, run the following command to start the container.
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.
For Twilio 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
Open the ngrok.exe file and run the following command.
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 complete, run the code using the 'DialogBot' startup profile. You should see the following screen in the browser if it was successfully compiled.
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.