Different response for each users types

My use case is I have different user types and I want rasa to respond differently for each user type with the same intent. I will connect my web application with Rasa APIs, Do I have different Rasas running at the same time, or is there any way to do this? (Each user types is identified from the web application side) Example:

  • UserType1: Hello

  • Response: Hi

  • UserType2: What’s up

  • Response: What’s up man
    . . .

How do you know which type the user belongs to? Okay, you have it defined on the web app as you said, but how can Rasa access it? Via a slot or an external tool like API or database?

Hi, thank you for the response!
I don’t know how do I tell rasa that too, my idea was to put something in front of the message to let rasa detect which type of user is this. something like “/user1/ Hello”.
But my current solution for this is to respond with every type and let my backend server handle them. something like “Hello | What’s up | Hi”

How much do you know about entities and slots? Do you know about payloads like /inform{"type": "type1"}?

Also, did you build the web application, or are able to fully understand the code and customize it?

Asking these questions so I can assess your level to know how much detail to include in answer.

I played with entities and slots but I don’t know about the payloads you mentioned.
Yes, I built the web application myself and I can customize everything!

(I am using http://<host>:<port>/webhooks/callback/webhook to talk with my Rasa)

1 Like

Great :slight_smile:


What are Payloads

First, a payload is a way to force an intent with 0 or many entities. It’s in the form /intent{"entity1": "value1", "entity2": "value2"}.

For example, if you want to greet the bot and give it your name, instead of sending “Hello, my name is Chris”. you can send /greet{"name": "Chris"}.

This is basically what a button does as you can see here, but you can also send it as a message, and therefore via the webhook too.


Sending a Hidden Message to Rasa

Using the payload method, you can send a hidden message from your app to Rasa.

You surely have a function to send a message, and a function to display the user’s message on-screen once sent.

If these two features are actually in the same function, I recommend splitting them so that you can optionally call the display feature or not. Something like this:

function send(message, display = True) {
    sendUserMessage({message: message, sender: sender_id})

    if (display) {
        displayUserMessage(message)
    }
}

Sending a Hidden Payload to Rasa

The same way you can send a message, you can also send a payload.

Usually, the user enters a text message, and clicks on a “send” button. This button should call the above send() function with display = True.

Of course, the user can also send payloads, and you can block this feature on your app (maybe don’t send the user’s message if it starts with / in your button’s event handler).

What you want is only to allow the system itself to send payloads, and of course, you don’t want the user to see this. So, when you do that, call the above send() function with display = False.

This call can be done as soon as you get the user’s type, in whichever method - I won’t go into details here since you built the app and probably know how to retrieve the info you need.

Let’s say the user type is available as soon as the page is loaded. All you’ll have to do then is the following:

$(document).ready(function() {
    const user_type = document.getElementById('user_type').innerText // Or whatever method you use to get this info
    const payload = `/inform{"user_type": "${user_type}"}` // Be careful to enclose the entity value in quotes - It should be a valid JSON
   
    send(payload, False)
})

Of course, you would have to define the inform intent in the NLU and give at least two examples with the type entity, even if this will never be directly set by the user:

nlu:
- intent: inform
  examples: |
    - [type1](user_type)
    - [type2](user_type)
    - [English](language)
    - [french]{"entity": "language", "value": "French"}
    - [eng]{"entity": "language", "value": "English"}

Uttering a Sentence According to a Slot

Conditional Response Variations allow you to utter a sentence based on conditions. These conditions can be slot values!

There is more info in the link I mentioned right now, and don’t hesitate to ask for help, but you will basically do something like this:

responses:
  utter_greet:
    - condition:
        - type: slot
          name: user_type
          value: type1
      text: "Hi, type 1 user!"

    - condition:
        - type: slot
          name: user_type
          value: type 2
      text: "What's up, type 2 user?"

    - text: "Hey! I'm not sure what type of user you are..."
2 Likes

This is really useful and what I was trying to do! Your example is exactly what I want to do.
Thank you so much!

1 Like

Happy to help :slight_smile:

1 Like