sociopath00
(Akshay Nevrekar)
October 1, 2019, 8:41am
1
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"])
Ghostvv
(Vladimir Vlasov)
October 1, 2019, 12:13pm
2
you could create a boolean slot for customer
and predict different utter template
sociopath00
(Akshay Nevrekar)
October 1, 2019, 1:33pm
3
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.
Ghostvv
(Vladimir Vlasov)
October 1, 2019, 2:44pm
4
you donāt need to pass to handle_text
method if you use slots functionality of rasa: Slots
sociopath00
(Akshay Nevrekar)
October 3, 2019, 5:30am
5
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
Ghostvv
(Vladimir Vlasov)
October 7, 2019, 8:46am
6
please take a look at the docs: Actions , you can set a slot in custom action by returning appropriate event
sociopath00
(Akshay Nevrekar)
October 7, 2019, 9:08am
7
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
Ghostvv
(Vladimir Vlasov)
October 7, 2019, 9:27am
8
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
sociopath00
(Akshay Nevrekar)
October 7, 2019, 9:52am
9
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.
Ghostvv
(Vladimir Vlasov)
October 7, 2019, 12:13pm
10
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:
I have created a custom Input channel known as ādesktopā.
I have got the http url as ālocalhost:50055/webhooks/desktop/webhookā.
The url is also working fine.
My issue is that in the following domain file specification, I am not getting the output āHi desktop userā every time. The output is a random one between the two text messages.
utter_greet:
- text: 'Hey there'
- text: 'Hi desktop user'
channel: "desktop"
Does rasa look for input or output channel in the domain file and if it looks ā¦
1 Like
Ghostvv
(Vladimir Vlasov)
October 7, 2019, 1:42pm
12
my suggestion is to add one more event to set a corresponding slot in rasa
Ghostvv
(Vladimir Vlasov)
October 7, 2019, 1:43pm
13
weāre answering all forum posts as fast as we can, please wait for the answer for your other post
sociopath00
(Akshay Nevrekar)
October 7, 2019, 4:18pm
14
yes @suryavamsi62 This is exactly what I am trying to implement.
ricwo
(ricwo)
October 8, 2019, 10:43am
15
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.
sociopath00
(Akshay Nevrekar)
October 15, 2019, 8:08am
18
Can you help me out here? I am struggling to implement custom connector
ricwo
(ricwo)
October 16, 2019, 7:21am
19
@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!
siva_g
(sivanandh)
June 5, 2020, 9:24am
20
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 })