Get latest performed custom action?

Hello!

I’m trying to get the bots latest performed custom action. I’ve tried both

tracker.latest_action_name

which only returns action_listen as it should and

tracker.get_last_event_for()

as mentioned in the docs. The latter I cant get to work at all. Is there a way to get the name of the latest performed custom action?

Thanks in advance!

I guess, the interface does not offer you a method to retrieve the latest performed custom action. The method tracker.get_last_event_for(ActionExecuted) should return the last action that was executed. But I guess that would also be action listen mostly.

You should be able to get it by implementing something like this (no guarantee that it is actually working):

    def get_latest_custom_action(self) -> Optional[Text]:
        for e in reversed(tracker.events):
            if isinstance(e, ActionExecuted):
                # TODO: as you don't want to have any action but only
                # your custom actions, you should check that here
                if e.action_name in ["custom-action-1"]:
                    return e
        return None

Thanks for replying!

Using inspiration for the code above I finally landed on this

for e in reversed(tracker.events): if e[“event”] == “action”: if e[“name”] != “action_listen”: print(e[“name”]) which works fine for my purpose Thanks!