How can I access metadata in custom actions?

nlu:

  • intent: secured_isolated

    examples:
    
    - text: |
    
        secured or isolated bay & purpose
    
      metadata:
    
        ask: secure_bay_purpose
    

I need to access this metadata “ask” in custom action. How do I do that?

Hey @AnkitChouhan

I think you intention was to read the metadata in your action python. If yes, here is some sample code which you can refer…

> class ActionSearchResult(Action):
> 	def name(self):
> 		return "action_result"
> 		
> 	def run(self, dispatcher, tracker, domain):
> 		item = tracker.get_slot('item')
> 		item = item.lower()
> 		
> 		
> 		if item =="book":
> 			dispatcher.utter_message("Hello from books...!")
> 		elif item =="course":
> 			dispatcher.utter_message("Hello from courses...!")
> 		elif item =="skill":
> 			dispatcher.utter_message("Hello From Skills...")

Further, you have to register the entity like, from the above code the entity is “item” in your domain.yml

> entities:
> - item
> slots:
>   item:
>     type: text
>     influence_conversation: true

Also, you have to pass these entities from the nlu intents.

- intent: ask_query
        examples: |
- i'm looking for important [books](item:book) in machine learning 
- [ML Books](item:book)
- [ML Courses](item:course)
- [Machine Learning Courses](item:course)
- [ML Skills](item:skill)

and map the corresponding slots in your stories. Thanks

stories:

  • story: happy path1 steps:

    • intent: greet
    • action: utter_greet_ask
    • intent: ask_query entities:
      • item: “ML Books”
    • slot_was_set:
      • item: “book”
    • action: action_result
    • action: utter_did_that_help
    • intent: deny
    • action: utter_goodbye
  • story: happy path2 steps:

    • intent: greet
    • action: utter_greet_ask
    • intent: ask_query entities:
      • item: “ML Courses”
    • slot_was_set:
      • item: “course”
    • action: action_result
    • action: utter_did_that_help
    • intent: deny
    • action: utter_goodbye
  • story: happy path3 steps:

    • intent: greet
    • action: utter_greet_ask
    • intent: ask_query entities:
      • item: “ML Skills”
    • slot_was_set:
      • item: “skill”
    • action: action_result
    • action: utter_did_that_help
    • intent: deny
    • action: utter_goodbye

Best Regards, Ravi

1 Like

Thanks for the quick reply. But I wanted to fetch the metadata not the entities(or slots) from user messages.

. This is the screenshot from rasa documentation, I want to implement such kind of feature and fetch “sentiment”:“neutral” (according to the screenshot) in my custom actions.py file

@AnkitChouhan Did find solution?