Rasa REST Custom Responses

So currently, in my food ordering app, I have some metadata that stores the state of the order in a list slot. I want POST requests that I make to Rasa to also contain this data.

Currently, the response is just

{‘recipient_id’: ‘test_user’, ‘text’: ‘hello’}

but I want to be able to see

{‘recipient_id’: ‘test_user’, ‘text’: ‘hello’, ‘order’: [burger, fries, coke], ‘metadata’: ‘placeholder’}

in the data of the response.

How can I accomplish this with Rasa? Note that ‘order’ and ‘metadata’ are slots in the Rasa domain.

Okay, I found this tutorial, but the response that Rasa returns still only has the text instead of including the meta data for some reason??

Hi , i’m looking for similar use-case , hope you can find the solution for it too

Okay, I figured it out. Basically, you need to do a very specific format to the yaml file.In my case, I wanted to respond with:

  utter_after_ordering:
  - custom:
      text: "{voice}"
      order: "{order}"

and in the custom code, I have

text = "I've added cheeseburger to your order"
order = ['cheeseburger']
dispatcher.utter_message(template="utter_after_ordering", voice=text, order=order)

and from there, I use python requests to make a post request to the REST api:

data = { "sender": "rasa", "message": message}
data = json.dumps(data)
rasa_api_endpint = "http://localhost:5005/webhooks/rest/webhook"
res = requests.post(url = rasa_api_endpint, data = data).json()['custom']
text, order = res['text'], ast.literal_eval(res['order'])

which allows me to get order back as a list of items (works even for a list of dictionaries as well). Would be cool if someone could tell me how to potentially have the order be in natively as a json rather than a string dictionary, but this works for now

2 Likes