How to use slot_was_set properly

I am having problem trying to greet user differently: for new user, just say hi, and for known user (i.e. the firstname is already set a value) to greet by name.

rules:
- rule: greet to new user
  condition:
  - slot_was_set:
    - firstname: null
  steps:
  - intent: greet
  - action: utter_greet


- rule: greet to known user
  condition:
  - slot_was_set:
    - firstname           
  steps:
  - intent: greet
  - action: utter_greet_known_user

But there is error when running rasa train: InvalidRule: Contradicting rules or stories found :rotating_light:

- the prediction of the action 'utter_greet' in rule 'greet to new user' is contradicting with rule(s) 'greet to known user'.
- the prediction of the action 'utter_greet_known_user' in rule 'greet to known user' is contradicting with rule(s) 'greet to new user'.

You should use custom actions:

class ActionGreet(Action):
    def name(self):
        return 'action_greet'

    def run(self, dispatcher, tracker, domain):
        if tracker.get_slot('firstname'):
            firstname = tracker.get_slot('firstname')
            dispatcher.utter_message(f'Hello, {firstname}')
        else:
            dispatcher.utter_message(f'Hello')
        return []

nice. thank you @ChrisRahme. It totally worked. :+1:

1 Like