no problem. Let’s assume you have a function print_given_entities which should be executed in every validation method of your actions.py.
This would look like:
def print_given_entities(self, latest_message, dispatcher, tracker, domain):
# the tracker got the information about recent events
for event in tracker.events:
# if there is further data bein parsed
if 'parse_data' in event:
# is only doing something if there actually are entities
for entity in event['parse_data']['entities']:
logger.debug('Found entity: {}'.format(entity))
if you call this method e.g. in one of your FormActions and kept in mind to provide the expected arguments, then the method will give you what you want to have.
If there are problems with the code, don’t hesitate to ask.
I’m also trying to do something similar. I want to extract the entity from the last message however when I tried with tracker.latest_message, it returned an empty list
Also, I tried your solution (I was not sure how to create my own function, so I used the run function itself in a custom action class. Here’s the code for the same
class ActionTimeframeSalesFigures(Action):
def name(self):
return "time_based_sales_figures"
def run(self, latest_message, dispatcher, tracker, domain):
entities = tracker.latest_message['entities']
print(entities)
print(tracker.events)
for timeframe in entities:
if timeframe == "Today's" or timeframe == "today's":
dispatcher.utter_message(f"Todays Sales figures are 100$ {timeframe}")
elif timeframe == "Weekly":
dispatcher.utter_message("Current week's sales figures are 100$")
elif timeframe == "Monthly" or timeframe == "monthly":
dispatcher.utter_message("Current month's sales figures are 100$")
elif timeframe == "Quarterly":
dispatcher.utter_message("Current quarter's sales figures are 100$")
else:
dispatcher.utter_message("Please enter the correct timeframe")
return []
This gave an error saying run method is missing with the domain argument
Can you please let me know if I’m doing something wrong here?