3

I can fetch the last user-inputted data from RASA chatbot using this method.

text = tracker.latest_message['text']

It's working perfectly in my case. Now I want to fetch the text of a button pressed by the user. For example, if the user presses the allion button, I want my text variable to hold as text = "allion".

enter image description here

Is there any preferable solution?

Shaiful Islam
  • 359
  • 2
  • 13

1 Answers1

1

The same way, you can get the string "allion" on click of the button, if you have sent the payload: allion in the button data.

buttons:
- title: allion
  payload: allion

Now when the user click the button, the Payload will be sent as user message. You can fetch that from tracker.events in your actions.py. All you need to add is, a check for what string has been sent.

for event in (list(reversed(tracker.events)))[:5]: # latest 5 messages
    if event.get("event") == "user": # check if the sent by user or bot
        event.get("text") # check here what button string is received, if allion or premio or corolla or axio or prius