How to pass extra parameters in in handle_text in rasa?

I am creating a chatbot using RASA and Flask

I have a strange requirement where for the same question I have to configure 2 different responses based on request.

In request there is a key customer it can be 1 or 0.

Say I have a question:

what is refund policy?

If the question is asked by customer(where key value is 1)

it will return You will get refund in 3 days

else it will return You will get refund in 7 days

So I am stuck how to pass this customer value in handle_text which is generating response for my Question.

Is there a way to do this in Rasa?

My Code:

from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.utils importEndpointConfig
from flask import FLASK, request
import json

nlu_interpreter = RasaNLUInterpreter(NLU_MODEL)
action_endpoint = EndpointConfig(url=ACTION_ENDPOINT) 
agent = Agent.load(DIALOG_MODEL, interpreter=nlu_interpreter, action_endpoint=action_endpoint)

@app.route("/chatbot", methods=["POST"])
def bot():
    data = json.loads(request.data)
    msg = data["msg"]  # the question by user
    customer = data["customer"]
    response = agent.handle_text(msg, sender_id=data["user_id"])

    return json.dumps(response[0]["text"])

you could create a boolean slot for customer and predict different utter template

But how can I pass that slot in agent.handle_text(msg, sender_id=data["user_id"]) to be used in action_class ?

If Iā€™m not wrong I need to set it somewhere as I am not setting it in ActionClass. I am recieving it through request made on Flask web service.

you donā€™t need to pass to handle_text method if you use slots functionality of rasa: Slots

Sorry but I am not still clear with this because I am not recieving customer value in data['message']. I am receiving it in data['customer']. In this case how can I set slot? One thing I am sure I canā€™t set it in stories. So I am looking for if I can access this in ActionClass

please take a look at the docs: Actions, you can set a slot in custom action by returning appropriate event

I donā€™t want to set inside the ActionClass. I already know if customer value is 0 or 1 from the request that I recieved. I just want to access it inside the Action Class

there is an example how to get value of slot cuisine in the code snippet in the docs. And there is a description on how to use parameters: Actions

I checked that example but the cuisine slot was set using entity which is acquired from text itself. eg. show me a Mexican restaurant

In this value of cuisine is set to Mexican. I think this is not what I need as I recieved value of customer in different key not from text.

regardless how you set it, if the information is stored as a slot in the tracker, you can get it from the tracker using tracker.get_skot(...) method

I believe what Akshay is asking for is

{
  "sender-id":"Akshay",
  "message": "what is refund policy"
  "customer": 1
}

How can we make RASA to accept an additional input parameter ā€˜customerā€™? I also need the same functionality.

My functionality is to know whether the customer is a admin or employee.

So, I need my bot to accept the parameters:

{
      "sender-id":"Akshay",
      "message": "what is refund policy"
      "customer": "admin" || "employee" 
 }

Should we be editing the input channel ? Also Please help me out with this post:

1 Like

my suggestion is to add one more event to set a corresponding slot in rasa

weā€™re answering all forum posts as fast as we can, please wait for the answer for your other post

yes @suryavamsi62 This is exactly what I am trying to implement.

Hi @sociopath00, @suryavamsi62, please have a look at the docs on adding metadata information to user messages: Custom Connectors. I hope that helps!

1 Like

Thanks ricwo. Got the idea and implemented the meta data in custom input channel.

Okay. Just out of curiosity asked about the other post.

Can you help me out here? I am struggling to implement custom connector

@sociopath00, please also check out the related topic Link up Custom input Channel with a custom Output Channel, where we go into some details of the implementation. I hope that helps!

Hi @Ghostvv, i want to send extra values to rasa actions.py using webhooks from web page, using ajax. how can I achieve this. i added another key values but not working.

for example JSON.stringify({ message: message, sender: user_id })

JSON.stringify({ message: message, sender: user_id, project_id: 23 })