Development of a musicotherapy chatbot with Chatfuel

How to easily create a chatbot to improve your emotions using Chatfuel

Christelle Rossier
Empathic Labs
4 min readMar 17, 2021

--

The aim of this project is to create a chatbot to serve as a therapist available to any individual. First of all, the bot will ask the user how he feels, the origin of this mood and how he would like to change or strengthen his emotional state. The user will also have to inform the bot about his musical tastes. In the end, the user is offered music that is supposed to improve his emotional state. For more information about the psychological part of this project, you will find an article about it here:

For our part, we are going to dedicate ourselves to the development of the chatbot using the tool Chatfuel.

Example of a conversation with Bobby

What’s Chatfuel and how to use it?

Chatfuel is an independent company that offers a service for creating chatbots in an easy way, without having to write code. Bots created with Chatfuel can then be deployed on Facebook Messenger. The concept is based on a block system. Each block contains a flow of messages that will be sent by the bot and gives the possibility to join another block. In our case, the bot will ask the user about his emotional state and give him several possibilities of answers. According to his answer, the user will be directed to another block where questions will be adapted to his situation. Chatfuel also allows us to save users' answers in so-called attributes, enabling us to analyze them later.

Chatfuel also gives the possibility to use artificial intelligence. In our case it is used at the beginning of the conversation: the bot is able to understand sentences similar to “Salut”, “Bonjour” or “À quoi sert-tu?” and will answer them by redirecting the user to the appropriate block.

JSON API

However, blocks alone are sometimes not enough to make the bot intelligent and usable. One notable example is calculations or comparing data. That’s why Chatfuel offers the possibility to integrate code from a third-party system.

In our case, the JSON API function uses Javascript code located on a Glitch server to process the data entered by the user. The JSON API is first used to determine the emotion or emotional state of the user. During the conversation, the bot will suggest a list of feelings and behaviours to the person performing the therapy and the user will have to choose the ones that correspond to him or her. The code on the glitch server will then select the emotion for which the most of the user’s answers correspond.

View on Chatfuel of the “joyful” feeling proposal and recording of the user’s answer

Then, depending on the user’s musical preferences, emotional state and the way he wants to change this state, suitable music will be chosen. The data concerning all the music to be chosen is stored in a JSON file. Once the appropriate music has been selected, the code returns the corresponding mp3 file and the user can directly listen to the music.

The JSON API block takes as argument the different choices of the user and will return the mp3 file of the adapted music.

Data Analysis and Future of the project

As the final goal of this project is the analysis of the collected data (the bot asks for the first name of the user at the beginning of the conversation, this information is not stored in order to respect confidentiality), all the attributes that have been recorded are finally exported in a google sheet document. It is thus possible to have an overview of the responses of all users.

On the basis of all these responses, an analysis will be conducted to determine the effectiveness of the music in changing or reinforcing an emotional state.

If you feel like testing the effect of music on your emotions, you can test the chatbot using the link below. Say hello and the bot will introduce itself and begin the experiment.

For the time being, the experiment is still in progress, and future results will be shared.

Note: Bobby is currently experiencing a problem with the new Facebook’s Messenger policies as the Facebook page he is connected to is based in Europe. Some features of Chatfuel are therefore no longer available to European bots. Sending audio or video is one of them. Thus, for the moment, the music at the end of the conversion won’t be send. If you want to know more about these new policies, the article below talks about them in more detail.

Thanks to Cécile Grand who led the project and Karl Daher who supervised it.

Photo by Jason Rosewell on Unsplash

--

--