Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

« Previous Version 13 Current »

There are two ways that you can deploy the Moodle Chatbot App

  1. Deploy as a docker container

  2. 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.

  1. 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",
  2. TwilioAccountSid: can be found in the Twilio console dashboard in the 'Account info' section.

  3. TwilioAuthToken: can be found in the Twilio console dashboard in the 'Account info' section.

  4. 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",
  5. Moodle.AuthToken: authentication token used to consume Moodle's API.

  6. 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's 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.

  1. Run the following command to create the Docker image.

    docker build -t chatbot -f Dockerfile.txt .
  2. After successfully building the image, 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.

  1. 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.

  2. 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.

  3. 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.

  4. Download Ngrok and create a file named 'ngrok_composer.yml' in the same directory where ngrok.exe is located.

  5. 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, adding a tunnel for this port is unnecessary.

  1. Open the ngrok.exe file and run the following command.

ngrok start --config=ngrok_composer.yml --all
  1. 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.

  1. 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.

To see in detail the chatbot flow and all the interactions users will have, please go to Moodle Chatbot App Interactions.

  • No labels