Custom action go to fall back default action

Hello i have a custom action and in a condition i want to go to the action_default_fallback but i dont know how i can achieve that i have an if statement on the action like

if(true):

do something here

else:

action_default_fallback

that does not work, someone can help me?

Hi @ramon, @MetcalfeTom will get back to you about you question soon. Meanwhile could you provide some more information about what you are trying to do? Which kind of condition are you talking about? Is something related to state of the conversation?

yes i have an if slot not set do the question another time, i need to do something like that because sometimes the slot is not set and return None

You can use FollowupAction events for this. Look here: FollowupAction Events

In particular, you can just

  1. import FollowupActions: from rasa_core_sdk.events import FollowupAction
  2. in your else block: return [FollowupAction(‘action_default_fallback’)]

Let me know if that works out for you

Traceback (most recent call last):
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\_compat.py", line 35, in reraise
    raise value
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask_cors\decorator.py", line 128, in wrapped_function
    resp = make_response(f(*args, **kwargs))
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\rasa_core_sdk\endpoint.py", line 74, in webhook
    return jsonify(response)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\json\__init__.py", line 321, in jsonify
    dumps(data, indent=indent, separators=separators) + '\n',
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\json\__init__.py", line 179, in dumps
    rv = _json.dumps(obj, **kwargs)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\simplejson\__init__.py", line 399, in dumps
    **kw).encode(obj)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\simplejson\encoder.py", line 296, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\simplejson\encoder.py", line 378, in iterencode
    return _iterencode(o, 0)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\json\__init__.py", line 81, in default
    return _json.JSONEncoder.default(self, o)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\simplejson\encoder.py", line 273, in default
    o.__class__.__name__)
TypeError: Object of type FollowupAction is not JSON serializable

mycode:

from rasa_core.events import FollowupAction
return[FollowupAction('action_default_fallback')]

@ramon: Can you share your entire custom action class?

This is how it should look like for example:

from rasa_core.events import FollowupAction
from rasa_core_sdk import Action

class ActionXXX(Action):
    def name(self):
        # define the name of the action which can then be included in training stories
        return "action_xxx"

    def run(self, dispatcher, tracker, domain):
        if xxx:
            pass
        else:
            return [FollowupAction('action_default_fallback')] 
        return []

if i do what say in the documentation: Events i get this error:

Traceback (most recent call last):
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\_compat.py", line 35, in reraise
    raise value
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask\app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\flask_cors\decorator.py", line 128, in wrapped_function
    resp = make_response(f(*args, **kwargs))
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\rasa_core_sdk\endpoint.py", line 72, in webhook
    response = executor.run(action_call)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\lib\site-packages\rasa_core_sdk\executor.py", line 177, in run
    events = action(dispatcher, tracker, domain)
  File "C:\Users\Ramon\Desktop\RASA-PYTHON\RASA-FILES\XONEBOT\actions.py", line 48, in run
    tracker.trigger_followup_action(self.action_default_fallback)
AttributeError: 'Tracker' object has no attribute 'trigger_followup_action'

code:

tracker.trigger_followup_action(self.action_default_fallback)

class ActionColl(Action):
    def name(self):
        return "action_coll"

    def run(self, dispatcher, tracker, domain):
        # what your action should do

        coll = tracker.get_slot('coll')
        if(coll is not None):
                message = "asi se crea una coleccion de tipo " + coll
        # sustituir con llamada a base de datos
        else:
            message = "el campo de referencia esta vacio porfavor escriba lo que quiere de forma distinta"
            return [FollowupAction('action_default_fallback')] 
        dispatcher.utter_message(message)
        return[]

Hmm, that looks ok to me. Even though there’s one minor issue in there. The message in your else block won’t be sent because you return in the next line, so in the else case dispatcher.utter_message(message) will never be executed.

Can you share how and / or the code you use to run the server? Also which version of rasa_core are you running?

rasa core the default downloaded with pip and

online training:

python -m rasa_core.train --online -o models/core/xonebot -d bot_domain.yml -s data/stories.md -u models/nlu/default/xonebot --endpoints endpoints.yml

server:

python -m rasa_core_sdk.endpoint --actions actions

well i need to put another utter mesage before the other return but that is a minor problem

Hi @ramon,

Instead of

from rasa_core.events import FollowupAction
return[FollowupAction('action_default_fallback')]

try importing the FollowupAction from rasa_core_sdk.events.

now works fine thank you