Search code examples
pythonchatbotrasa

How do I get user input in a custom action in Rasa?


I am extracting questions from database because It's relatively large dump of data and I wanted to know if there was a way to extract user input from custom actions. I'm using Rasa SDK 2.0.0a1 . Solutions I have tried:

  • tracker.latest_message["text"]
  • tracker.latest_message.text
  • tracker.latest_message.get("text") Any other solutions would be appreciated.

Thank you!


Solution

  • You can extract the latest user message from the current state of the tracker:

    current_state = tracker.current_state()
    latest_message = current_state["latest_message"]["text"]
    

    An even easier way to do that is by using the method: tracker.latest_message['text']