How to get user entered text in custom action

HI All,

I am trying to get the user entered text inside run method of a custom action. In which object I can get that

def run(self, dispatcher, tracker, domain):
2 Likes

You can get this with tracker.latest_message.text

7 Likes

Got it thanks :slight_smile:

@akelad thanks for your answer. i have one more question how can I run multiple projects in a rasa core server instance.

I mean I have a FAQ Bot and Helpdesk bot How to run these at a time and how can I call them using REST API?

I am trying to do that but no success yet. I get the error as below:

rasa_core.actions.action - Failed to run custom action ‘action_help’. Action server responded with a non 200 status code of 500. Make sure your action server properly runs actions and returns a 200 once the action is executed. Error: 500 Server Error: INTERNAL SERVER ERROR for url: http://localhost:5055/webhook ERROR rasa_core.processor - Encountered an exception while running action ‘action_help’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code. ERROR rasa_core.processor - Failed to execute custom action. in my actions.py I have this line of code below: dispatcher.utter_message(tracker.latest_message.entities(help)) As soon as I remove this line of code everything works as it should. The precise error I get is: AttributeError: 'dict' object has no attribute 'entities' Any help on this.

Thanks

1 Like

For version 11.0 and above Use this

(tracker.latest_message)['text']

This is for version 0.10 and lower tracker.latest_message.text

5 Likes

Thanks for the reply. It worked for me.

1 Like

I m trying to print only those user input which bot cant interpret using following code

txt=tracker.latest_message.text
return txt

Now getting this error

AttributeError: 'dict' object has no attribute 'text'

My ultimate task is to add those input which are not present in training data under some intent like unknown user input

Try it this way

message = tracker.latest_message.get('text')

4 Likes

Thanks. Its working.

thanks

hi, may i know how and where you add in those code for tracking user input?

Hi all,

I want get the username from the chat conversations

example:- bot:- Hi user:- Hi Bot: May i know your name? User: I am Karthik Bot : Thanks for providing details Karthik

Like the above example i have call the user with there name can anybody please help

if i have form action … it is taking latest message of form field of text value. but need a user question.

input_str = tracker.latest_message.get(“text”)
it is taking form field values if form fields are manually text field format. so how can i get the input str as user query.

In order to extract the name, one way to go about it is create an intent get_name with entity name; you can feed training data which demonstrates response to needed question.

eg:

## intent: get_name
    - My name is [Karthik](name)
    - My name is [possible](name)
    - My name is [other names](name)
    - I am [Sumanth](name)
    - I am [William](name)
    - I am [Lazarus](name)

hey, I have tried this but it isn’t working. I have also tried the tracker.latest_message.text. I’m using the rasa/rasa-sdk:2.0.0x docker image and I had it working previously, now it’s not working. The custom action is just running completely ignoring the latest text thing. Please help, Thank you!

Hi @thundersparkf

The code is

tracker.latest_message.get('text')
2 Likes

This will work in action :

tracker.latest_message[‘text’]