Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

Info

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

Info

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

    to have

    the following format: whatsapp:<telephone number>.

    Code Block
    "TwilioNumber": "whatsapp:+447862143841",
  2. TwilioAccountSid: can be found in the Twilio console dashboard

    ,

    in the

    ‘Account info’

    'Account info' section.

  3. TwilioAuthToken: can be found in the Twilio console dashboard

    ,

    in the

    ‘Account info’

    'Account info' section.

  4. TwilioValidationURL: this URL

    hast

    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

    the

    port 3979 of the server where the chatbot is hosted.

    Code Block
    "TwilioValidationUrl": "http://<host>:3979/api/twilio",
    Image Removed
  5. Moodle.AuthToken: authentication token

    ,

    used to consume

    Moodle’s

    Moodle's API.

  6. Moodle.MoodleAPI.BaseUrl: Moodle instance URL for all API calls.

    Code Block
    "BaseUrl": "https://<host>/webservice/rest/server.php?moodlewsrestformat=json",

Info

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 You will also find a folder named 'DBTables' in the same directory as the configuration file, you will also find a folder named ‘DBTables’. It is called like that this because all the .json files it contains were originally tables from a database the chatbot no longer hasuses, so 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 modifying the Message parameter with the text you prefer is possible.

Keep in mind, you also have to change the welcome message for the other languages. The parameter ‘LanguageISOCode’ 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 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 a Docker image and container

After configuring the chatbot, navigate to the code root folder. The file ‘Dockerfile'Dockerfile.txt’ txt' contains all the metadata to create the image.

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

    Code Block
    docker build -t chatbot -f Dockerfile.txt .
  2. After successfully building the image is successfully built, run the following command to start the container.

    Code Block
    docker run -p 3979:80 chatbot -d

...

  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. In order for Twilio to be able 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'ngrok_composer.yml’ yml' in the same directory where ngrok.exe is located.

  5. Copy the following text into ngrok_composer.yml

    Code Block
    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 . If this is not true, there is no need to add adding a tunnel for this port is unnecessary.

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

...

  1. After the configuration is donecomplete, proceed to run the code using the ‘DialogBot’ 'DialogBot' startup profile. If it was successfully compiled, you You should see the following screen in the browser if it was successfully compiled.

...

Test the Moodle Chatbot App

...