How to give out user input error messages?

how to give out error messages if a user input doesn’t match any intents. Example: I am making a restaurant finding rasa bot, so I was thinking of making the rasa bot ask location of where the user is looking for a restaurant, So if there are no restaurants in location entered by the user how to return “sorry there are no restaurants in this location” message.

Hi @AayushDangol123! You can do this with a custom action. Once you get the user’s location you can call a custom action to check if there are any nearby restaurants. Based on the result you can respond back to your user with dispatcher.utter_message notifying the user whether a restaurant was found or not.

For your use case that custom action could look something like this where you would check for nearby_restaurants and then based on that result send a response to the user.

class ActionCheckRestaurants(Action):
   def name(self) -> Text:
      return "action_check_restaurants"

   def run(self,
           dispatcher: CollectingDispatcher,
           tracker: Tracker,
           domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

      nearby_restaurants = tracker.get_slot('nearby_restaurants')
      if nearby_restaurants:
          dispatcher.utter_message("I found nearby restaurants")
         dispatcher.utter_message("Sorry, I couldn't find any restaurants nearby.")

      return [SlotSet("nearby_restaurants", nearby_restaurants if nearby_restaurants is not None else [])]
1 Like