# Filter buttons the user has clicked before

**URL:** <https://forum.rasa.com/t/filter-buttons-the-user-has-clicked-before/39673>\
**Category:** Rasa Open Source\
**Created:** [February 1, 2021, 8:04am UTC](https://forum.rasa.com/t/filter-buttons-the-user-has-clicked-before/39673 "2021-02-01T08:04:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartinJaskulla](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/martinjaskulla/32/11344_2.png) [@MartinJaskulla](https://forum.rasa.com/u/MartinJaskulla)\
**Post date:** [February 1, 2021, 8:04am UTC](https://forum.rasa.com/t/filter-buttons-the-user-has-clicked-before/39673/1 "2021-02-01T08:04:31Z")

</div>

I want to loop three options until the user has clicked all three. Each clicked option should be filtered out.

For example:

```
utter_learn_more:
    - text: 'Learn more'
      buttons:
        - title: "Option A"
          payload: '/opta'
        - title: "Option B"
          payload: '/optb'
        - title: "Option C"
          payload: '/optc'

```

Bot: Learn more

- A
- B
- C

User: A

Bot: _Explains A_

Bot: Learn more

- B
- C

User: C

Bot: _Explains C_

Bot: Learn More: B

> Should I use custom actions or forms for this? And how would I do that?

---

<div class="post-metadata">

**Author:** ![j.mosig](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/j.mosig/32/3588_2.png) [@j.mosig](https://forum.rasa.com/u/j.mosig)\
**Post date:** [February 1, 2021, 9:20am UTC](https://forum.rasa.com/t/filter-buttons-the-user-has-clicked-before/39673/2 "2021-02-01T09:20:05Z")

</div>

Hello @MartinJaskulla

To implement your logic I would define a [list slot](https://rasa.com/docs/rasa/next/domain#list-slot) `available_options` that holds the currently available options with `influence_conversation: true`. Then I’d write a custom action `action_learn_more` that shows buttons based on `available_options`, and have the buttons send the _same_ intent with an entity that indicates the chosen option: `payload: '/choose{{"option": "A"}}'`, etc. The entity should have a corresponding slot `option` that holds the option that the user chose. Finally, a second custom action `explain_option` gives the explanation to the option stored in the `option` slot and removes that option from `available_options`.

With this setup, I think you can define the entire logic in two rules: one that applies when `available_options` still contains something, and one that applies when `available_slots` is empty.

---

<div class="post-metadata">

**Author:** ![MartinJaskulla](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/martinjaskulla/32/11344_2.png) [@MartinJaskulla](https://forum.rasa.com/u/MartinJaskulla)\
**Post date:** [February 2, 2021, 9:28pm UTC](https://forum.rasa.com/t/filter-buttons-the-user-has-clicked-before/39673/3 "2021-02-02T21:28:43Z")

</div>

Thanks for your help!

Very new to Rasa and struggled quite a bit, so here is what I did if anyone else is interested:

_domain.yml_

```
utter_all_options:
- text: 'Choose option'
  buttons:
    - title: "Option A"
      payload: '/choose_option{"option": "utter_option_a"}'
    - title: "Option B"
      payload: '/choose_option{"option": "utter_option_b"}'
    - title: "Option C"
      payload: '/choose_option{"option": "utter_option_c"}'
utter_option_a:
- text: 'Option A'
utter_option_b:
- text: 'Option B'
utter_option_c:
- text: 'Option C'

slots:
      option:
        type: text
      options:
        type: list
        influence_conversation: true
        initial_value: [
          {title: 'Option A',payload: '/choose_option{"option": "utter_option_a"}'},
          {title: 'Option B',payload: '/choose_option{"option": "utter_option_b"}'},
          {title: 'Option C',payload: '/choose_option{"option": "utter_option_c"}'}
        ]
entities:
      - option

```

_actions.py_

```
class ActionChooseOption(Action):

def name(self) -> Text:
    return "action_choose_option"

def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
    options = tracker.get_slot('options')
    option = tracker.latest_message['entities'][0]['value']

    for i in range(len(options)):
        if option in options[i]['payload']:
            del options[i]
            break
    dispatcher.utter_message(template=option, buttons=options)
    return [SlotSet("options", options)]

```

@j.mosig I would be happy about any improvements. Any reasons why two actions are needed?

---

<div class="post-metadata">

**Author:** ![MartinJaskulla](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/martinjaskulla/32/11344_2.png) [@MartinJaskulla](https://forum.rasa.com/u/MartinJaskulla)\
**Post date:** [February 3, 2021, 6:53am UTC](https://forum.rasa.com/t/filter-buttons-the-user-has-clicked-before/39673/4 "2021-02-03T06:53:05Z")

</div>

@j.mosig reply makes more sense to me now that I learned about:

- categorical slots
- calling more than one action in rules.yml

This allows me to list remaining options whenever I need to, and show remaining options only for some options (maybe option b wants to show sub options instead).

```
     rule: Show options in the beginning
     steps:
        - intent: /get_started
        - action: action_remaining_options

    - rule: Show remaining suggestions after option a
      steps:
        - intent: choose_option # Shows option a and removes it from options
        - action: action_choose_option
        - slot_was_set:
          - suggestion: option_a
        - action: action_remaining_options
```
