If else flow

    next:
      - if: slots.has_taken_previous_medications
        then: has_taken_previous_medications_id
      - else: no_previous_medication_id
      
  - id: no_previous_medication_id
    action: utter_no_previous_medication_response

  - id: has_taken_previous_medications_id
    collect: user_previous_medications

Above is the code that I am using in the flow. Why both if and else conditions are getting executed?

Hello Adeel,

If a step in a flow does not have a next field, then Rasa executes the next step defined in the flow.

So from the flow steps defined above, step has_taken_previous_medications_id will always be run after step no_previous_medication_id.

More information can be found in the flow documentation.

can you help in modifying the above code according to the flow in the image

Sure, this adds empty_step as a place for no_previous_medication_id to jump to, to skip step has_taken_previous_medications_id:

   next:
      - if: slots.has_taken_previous_medications
        then: has_taken_previous_medications_id
      - else: no_previous_medication_id
      
  - id: no_previous_medication_id
    action: utter_no_previous_medication_response
    next: empty_step

  - id: has_taken_previous_medications_id
    collect: user_previous_medications

  - id: empty_step
    noop: true