How to Add Welcome message in RASA X?

Fontend means the interface the user will use to talk the the bot, like a web widget or a mobile application.

You can’t start with a message from the bot in Rasa X; you will have to do that in your application. There are two ways:

  1. In that application, you will have a send() function for sure, to send the user message to the Rasa server when the user clicks on the “send” button.

    You will just need to call this function on startup, which means when the user opens the webpage or the mobile application.

    Let’s say in your domain, the phrase “Hey there, I am a bot. How can I assist you?” is called utter_greet, and in the stories, it is a response to the greet intent.

    So you can send a message with the greet intent, like “Hello” on startup, as I just said, so when the bot recieves it it will reply “Hey there, I am a bot. How can I assist you?”.

  2. You will also have a display_message() function which you will use to display the message received by the bot.

    You can also call this function on startup, to display the message directly without sending anything first.

There are multiple frontends you can use:

All of them have a feature to do what mentioned above, except the Rasa Android app (I think).


A small JavaScript code example for solution 1:

$(document).ready(() => {
  send("Hello")
})

function send(message) {
  $.ajax({
    url: rasa_server_url,
    type: "POST",
    contentType: "application/json",
    data: JSON.stringify({ message, sender: sender_id }),
    success(botResponse, status) {
      setBotResponse(botResponse);
    },
    error(xhr, textStatus) {
      setBotResponse('Error');
    },
  });
}

And for solution 2:

$(document).ready(() => {
  display_message("Hey there, I am a bot. How can I assist you?")
})

function display_message(message) {
  $(`<p class="botMsg">${message}</p>`).appendTo(".chats").hide().fadeIn(500);
}
3 Likes