How to prompt user first with a welcome message initially

Hi, I wanted the bot to welcome the user at the start of every session or basically trigger a particular intent at the start of every session

Right now the bot does not welcomes or does anything until user types a message

Even I have the same requirement. I should Welcome user before user types a Hi.

I looked up, found this How to make bot reply first before user? - #3 by skjainmiah

but mostly people are saying that its specific to channels triggering initial intents, So i looked up more and found out that there is a default action known as action_session_start which we can override and send a message we want but I just couldnt override the action for some reason, it never gets overriden

my rasa version is 2.1.2 and sdk 2.1.2

Aside from ActionSessionStart, you can send the greet intent (or any other one of course) secretly from the user in your frontend (the interface the user will use to talk to the bot, like a web widget or a mobile application). This way, it will seem like the bot is the one that started the conversation.


You will surely have a send(message) function to send the user messages via API. Upon startup of your application, you will just need to automatically send a hidden message or payload as if it’s from the user, which will trigger the action.

For example, if utter_greet is the answer to the intent greet, you could execute send("Hello") or send("/greet") on startup.


In more detail, there are two ways to do this:

  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, 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, so when the bot receives it, it will reply “Hey there, 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 was mentioned above, except the Rasa Android app (I think), not sure about Rasataurants and Rasa iOS/Android.


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");
}
3 Likes

That is just an amazing reply! And amazing resources! Thank you sooooo much man! Starred and followed on github!

1 Like

Glad to be of help! :grinning_face_with_smiling_eyes: