Customizing default fallback

Hey guys,

I’m trying to think of a way to customize the default fallback in a way so that it returns a feedback form after being activated for the third time. I imagine it doing this:

user: iohqioghq
bot: I didn't get that
user: iohqioghq
bot: I didn't get that
user: iohqioghq
bot: I must be doing something wrong. Care to tell me what's up? *feedback form*

Thing is, I’m not much of a programmer. Can you guys help?

shameless self-bump

I think you would good very similar behavior out of the box with Policies.

If you want to it yourself in a custom action, it’s probably sth like (didn’t have time to test it, but as a start):

from rasa_sdk import Action
from import UserUtteranceReverted

class ActionSearchVenues(Action):
    def name(self):
        return "action_custom_fallback"

    def run(self, dispatcher, tracker, domain):
        number_of_fallbacks_in_a_row = 0
        for event in tracker.events_after_latest_restart():
            if event.get("event") == "action":
                action_name = event.get("name")

                if action_name == "action_custom_fallback":
                    number_of_fallbacks_in_a_row += 1
                elif action_name != "action_listen":
                    # it's okay if a action_listen is in between
                    number_of_fallbacks_in_a_row = 0

        if number_of_fallbacks_in_a_row >= 2:
            pass # fill this with your desired behavior
            dispatcher.utter_message("Please rephrase") # Could be the case that you also have to revert this one
            # Revert latest user utterance
            return [UserUtteranceReverted]
1 Like

Thanks Tobias, I’ll check out if this works the way I intend!