# How do I reuse a form for different intents?

**URL:** <https://forum.rasa.com/t/how-do-i-reuse-a-form-for-different-intents/47078>\
**Category:** Rasa Open Source\
**Created:** [August 20, 2021, 1:01pm UTC](https://forum.rasa.com/t/how-do-i-reuse-a-form-for-different-intents/47078 "2021-08-20T13:01:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![actorkrishna](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@actorkrishna](https://forum.rasa.com/u/actorkrishna)\
**Post date:** [August 20, 2021, 1:01pm UTC](https://forum.rasa.com/t/how-do-i-reuse-a-form-for-different-intents/47078/1 "2021-08-20T13:01:58Z")

</div>

I have defined two stories, one for ‘Products & offers’ and another for ‘account details’. Both require dummy authentication through an ‘otp\_form’.

```
    - story: Account Details and authentication
  steps:
  - slot_was_set:
    - is_authenticated: false
  - intent: account_details
  - action: otp_form
  - active_loop: null
  - slot_was_set:
    - is_authenticated: true
  - action: utter_what_help_is_needed

- story: New offers & products and authentication
  steps:
  - slot_was_set:
    - is_authenticated: false
  - intent: new_offers
  - action: otp_form
  - active_loop: null
  - slot_was_set:
    - is_authenticated: true
  - action: utter_products_offers

```

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](https://rasa.com/docs/rasa/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.

---

<div class="post-metadata">

**Author:** ![snek](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/snek/32/13510_2.png) [@snek](https://forum.rasa.com/u/snek)\
**Post date:** [August 21, 2021, 11:17am UTC](https://forum.rasa.com/t/how-do-i-reuse-a-form-for-different-intents/47078/2 "2021-08-21T11:17:25Z")

</div>

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:

1. Try to add `utter_otp_submitted` and `action_get_account_details` to your stories by inserting them right before `utter_products_offers` like so:

```auto
- story: New offers & products and authentication
  steps:
  - slot_was_set:
    - is_authenticated: false
  - intent: new_offers
  - action: otp_form
  - active_loop: null
  - slot_was_set:
    - is_authenticated: true
  - action: utter_otp_submitted
  - action: action_get_account_details
  - action: utter_products_offers

```

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.

1. 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](https://rasa.com/docs/action-server/2.3.0/sdk-dispatcher#parameters) 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:

```auto
- story: Account Details and authentication
  steps:
  - slot_was_set:
    - is_authenticated: false
  - intent: account_details
  - action: otp_form
  - active_loop: null
  - slot_was_set:
    - is_authenticated: true
  - action: utter_otp_submitted
  - action: action_get_account_details

- story: New offers & products and authentication
  steps:
  - slot_was_set:
    - is_authenticated: false
  - intent: new_offers
  - action: otp_form
  - active_loop: null
  - slot_was_set:
    - is_authenticated: true
  - action: utter_otp_submitted
  - action: action_get_account_details

```

---

<div class="post-metadata">

**Author:** ![actorkrishna](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@actorkrishna](https://forum.rasa.com/u/actorkrishna)\
**Post date:** [August 23, 2021, 12:40pm UTC](https://forum.rasa.com/t/how-do-i-reuse-a-form-for-different-intents/47078/3 "2021-08-23T12:40:58Z")

</div>

# code to manage re-use of OTP form

```
    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

---

<div class="post-metadata">

**Author:** ![snek](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/snek/32/13510_2.png) [@snek](https://forum.rasa.com/u/snek)\
**Post date:** [August 29, 2021, 6:03pm UTC](https://forum.rasa.com/t/how-do-i-reuse-a-form-for-different-intents/47078/4 "2021-08-29T18:03:48Z")

</div>

> [@actorkrishna](#):
>
> but it is not showing the last intent by the user. Instead it is showing the previous intent.

Do you mean it is showing the intent that would come before either `new_offers` or `account_details`? Also, in what action is this code?
