How to return a not found message when a particular product match is not found in the csv database?

The bot is fetching a smartphone from a .csv database matching multiple user preferences. I need to return the user a not found message if atleast one of the criterias are not met. Request someone to help!

Here is the selected part from the actions.py file where i need to implement the above said logic:

if category == 'phone':
    output = df[(df['category'] == 'phone') & (df['price'] <= price) & (df['battery_mah'] >= battery) & (df['storage'] >= storage) & (df['back_camera_megapixel'] >= camera)]
             
    for url in output['product_url']:
        dispatcher.utter_message(text=url)       
        return []

Welcome to the forum :slight_smile:

This is more of a Python-related question than Rasa.

Following your code, it should enter the for loop if there is at least one result, utter the first result only, and quit.

So, on the opposite case, if there are no result, it won’t even enter the for loop, and therefore won’t return and will continue. This is where you can utter the “Not found” message:

for url in output['product_url']:
    dispatcher.utter_message(text=url)       
    return []

dispatcher.utter_message(text='Not found')       
return []
2 Likes

image

I understand that you want all dataframe lines that have the url. Then you can do a for in your result dataframe and put that value in a string separated by \n.

1 Like