I want to use domain.yml text in action.py

Hello everyone I am creating one chatbot which should not repeat the answer if same question is asked for that Now I am willing to take text of domain.yml text in action.py So that I can use some python logic to not to repeat same answer if same question is asked.So Can anyone tell me how to use take domain.yml response of particular intent in action.py

I have not tried any of this.

I think the issue will be keeping track of the responses, but you can access the bot’s last response ( How to get latest bot response? )

important snippet from that post

    for event in tracker.events:
        if event.get("event") == "bot":
            print("bot",event.get("text"))

The trick is to get all the text options for a response. I looked at the SDK for the CollectionDispatcher and it only returns 1 response at a time, and it’s random. One option could be to edit the core code in that class to make sure the response is unique. That would be a valuable PR and allow you to contribute back. I’d definitely use that.

HOWEVER, to address your initial question, the domain file data is 100% accessible from within the run method in your custom action.

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

In my custom action I just did a print(domain). You can see the multiple responses I tossed in for the utter_greet

So you can access it. FWIW, it looks like this

{
 'config': 
    {'store_entities_as_slots': True}, 
    'session_config': 
        {'session_expiration_time': 60, 
         'carry_over_slots_to_new_session': True
        }, 
    'intents': [
        {'greet': {'use_entities': True}}, 
        {'goodbye': {'use_entities': True}}, 
        {'affirm': {'use_entities': True}}, 
        {'deny': {'use_entities': True}}, 
        {'mood_great': {'use_entities': True}}, 
        {'mood_unhappy': {'use_entities': True}}, 
        {'bot_challenge': {'use_entities': True}}
    ], 
    'entities': [], 
    'slots': {}, 
    'responses': {
        'utter_greet': [
            {'text': 'Hey! How are you?'}, 
            {'text': 'Wassup?'}, 
            {'text': 'Oh hi there!'}
        ], 
        'utter_cheer_up': [{'text': 'Here is something to cheer you up:', 'image': 'https://i.imgur.com/nGF1K8f.jpg'}], 
        'utter_did_that_help': [{'text': 'Did that help you?'}], 
        'utter_happy': [{'text': 'Great, carry on!'}], 
        'utter_goodbye': [{'text': 'Bye'}], 
        'utter_iamabot': [{'text': 'I am a bot, powered by Rasa.'}]
    }, 
    'actions': ['action_dump_domain'], 
    'forms': {}, 
    'e2e_actions': []
}

Hope that helps.

And if you do a PR for this into Rasa, let me know! I’ll support it 100%

2 Likes

You could also handle this with your own NLG server as described here.