Create selectable field or options by using the data extracted from the Database


I am working on a chatbot project where I have to create a chatbot for hotel booking. I have a query regarding this. Until now, I managed to get the requirements like booking day, type of room, the number of beds needed, and some more information from the users. Based on the information, the database will provide a list of rooms with its descriptions, so that users can see what are the rooms available currently. Now, here I am facing the issue. is it possible that the user can select one of the items(rooms) in the list and initiate the bookings? for a more detailed understanding, I have attached a rough template below. please take a look.

thanks :slight_smile:

You can define a response template with dynamic values for the room number and description and then create a button with the room payload. In your action server code you can iterate through the rooms returned and build the response for each room.

Your response could look like this where you will dynamically fill room_no and description based on what’s returned from the database.

- utter_room_detail:
  - text: "{room_no}: {description}"

Then in your action server you can dynamically fill those values and add the booking button for each room returned by the database:

for room in rooms:
  button = [{"title": "Book Room", "payload": "/book_room" + json.dumps({"room_no": room["room_no"]})}]
  dispatcher.utter_message(response="utter_room_detail", buttons=button, room_no=room["room_no"], description=room["room_description"])

What’s happening here is for each room returned by your database you’re going to utter a response, utter_room_detail with the room number and description. Then you’re adding a button to book the room. That button will have a payload to trigger an intent book_room where you’re including the room_no as a payload that you can parse to determine the room the user wants to book.

Hi Zeusturbo,

By extracting a required data form the data you can store it in json format. You can send this json using utter_custom_json(json_data)

For example: json_data = [] for room in room_collection: json_data.append( { “room_num”: 1, “room_type”: “suite”, “Description”: “Dihjdhfjh” } ) utter_custom_json(json_data)

How to display the above data you can manage on front end side.

@m.vielkind thanks for the reply. yep, it worked. but I’m facing an additional issue in the rasa X. it’s not displaying all the results in the chatbot if it loops through. Please refer to the image below.rasaxq

@Zeusturbo can you confirm this works in the Rasa shell or are the results just not showing in Rasa X?

@m.vielkind I checked in rasa shell and also in telegram, it’s working as I expected. But while I use RASA x, instead of showing all the room list, it displaying only the first room in the list.

@Zeusturbo could you share the snippet of code where you’re generating the response from your action server?