Getting last executed action(not action_listen)

Try this:

def get_last_utter_action(tracker):

##goes back through the list of events and finds
##the last utter_action
for event in reversed(tracker.events):

         try:
        #print("current action name is", event.get('name'))
        if event.get('name') not in [ 'action_listen', None, 'utter_ask_continue' ] :
            last_utter_action = event.get('name')
            #print('found action', last_utter_action)
            return last_utter_action
        else :
            #print(event.get('name'))
            pass
    except:
        pass
        #print(event.get('text'))
return 'error! no last action found'
5 Likes