Get the last utter message from the bot

Hi everyone, I’m wondering how can if it’s possible to get the last utter message from the bot in RASA ? thank you !

Hi @Ahmed,

can you describe a bit more detailed in which context you want to access this message? Basically you can get that via tracker.events - the question is, in which environment you want to access it!?

Regards

Thank’s @JulianGerhard,

In actions.py, I’d like to access to the last bot utterance in a FormAction.

Regards

Okay,

that should be possible in every method that implements

tracker: Tracker

as an argument. If so, you could iterate over events:

for event in tracker.events:
    <do what you like>

Feel free to ask if help is needed.

I’m not able to extract the last utterance using the loop.

Which version you are using. Try: value = tracker.latest_message.get(‘text’)

2 Likes
for slot, value in slot_values.items():
       ##goes back through the list of events and finds
       #the last utter_action
       for event in tracker.events:
           if event.get("event") == "bot":
               try:
                   print("event : ", event.get("text"))
               except:
                   pass

I’m able to get all utterances. Thank’s for your help.

1 Like