Then, I have defined a rule to deactivate the form
- rule: Submit OTP
condition:
# Condition that form is active.
- active_loop: otp_form
steps:
# Form is deactivated
- action: otp_form
- active_loop: null
- slot_was_set:
- requested_slot: null
- is_authenticated: true
# The actions we want to run when the form is submitted.
- action: utter_otp_submitted
- action: action_get_account_details
After I train the model, I get this error:
InvalidRule:
Contradicting rules or stories found
the prediction of the action ‘utter_what_help_is_needed’ in story ‘Activate OTP form and authentication’ is contradicting with rule(s) ‘Submit OTP’ which predicted action ‘utter_otp_submitted’.
the prediction of the action ‘utter_products_offers’ in story ‘New offers & products and authentication’ is contradicting with rule(s) ‘Submit OTP’ which predicted action ‘utter_otp_submitted’.
Please update your stories and rules so that they don’t contradict each other.
You can find more information about the usage of rules at Rules.
How can I solve this error, so that I can reuse the OTP form while going down the flow with both intents separately?
Both the ‘Account details’ intent and ‘products and offers’ intent appear as buttons in the same level of bot reply.
Your rules are in contradiction with the stories. Just to be on the same page here:
Rasa is trying to apply a rule that says “when the opt_form is deactivated because the is_authenticated slot was set to true, I have to say utter_otp_submitted.”
The story is telling Rasa to do something else after the is_authenticated slot is set to true, which is to either say utter_what_help_is_needed or utter_products_offers (depending on the intent).
My recommendation:
Try to add utter_otp_submitted and action_get_account_details to your stories by inserting them right before utter_products_offers like so:
This is because the action that will be predicted after is_authenticated: true is utter_otp_submitted and not utter_products_offers. You have to do this for both stories since they rely on the same form.
Choose which utterance to run based on the last detected intent and run these inside a custom action. For example, at the end of action_get_account_details, you can dispatch the correct template (utter_products_offers or utter_what_help_is_needed). I personally dislike this approach become having the bulk of the conversation handled by Rasa rules and stories makes the code easier to read and debug. If you do this, your stories will just look like this:
current_intent = tracker.latest_message['intent'].get('name')
dispatcher.utter_message(text=f'current_intent is {current_intent}') # debug
if current_intent == 'account_details':
dispatcher.utter_message(template="utter_what_help_is_needed")
elif current_intent == 'new_offers':
dispatcher.utter_message(template="utter_products_offers")
I tried using tracker.latest_message, but it is not showing the last intent by the user. Instead it is showing the previous intent. Any idea how to code for this in custom actions? I tried adding examples to intents as well. But still no avail