# Dynamically adding buttons to a slot response in a form

**URL:** https://forum.rasa.com/t/dynamically-adding-buttons-to-a-slot-response-in-a-form/41431
**Category:** Rasa Open Source
**Created:** [March 18, 2021, 12:29pm UTC](https://forum.rasa.com/t/dynamically-adding-buttons-to-a-slot-response-in-a-form/41431 "2021-03-18T12:29:46Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![pomegran](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/pomegran/32/16087_2.png) [@pomegran](https://forum.rasa.com/u/pomegran)
#### Post date: [March 18, 2021, 12:29pm UTC](https://forum.rasa.com/t/dynamically-adding-buttons-to-a-slot-response-in-a-form/41431/1 "2021-03-18T12:29:46Z")

</div>

Hi,

I’ve got a slot filling form all working quite nicely with some custom validation logic within each slot. All working well so far.

However, I would like to help the user with buttons when I need them to disambiguate if the entity entered did not exactly match the entity from a list (based on my cosine similarity validation logic). I therefore need to dynamically add buttons to the default “utter\__\<form\_name\>_” in my domain file.

Is there a way to override the action that displays the utter in my form?

Thanks!

---

<div class="post-metadata">

### Author: ![m.vielkind](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m.vielkind/32/12693_2.png) [@m.vielkind](https://forum.rasa.com/u/m.vielkind)
#### Post date: [March 18, 2021, 12:55pm UTC](https://forum.rasa.com/t/dynamically-adding-buttons-to-a-slot-response-in-a-form/41431/2 "2021-03-18T12:55:41Z")

</div>

Hi @pomegran I believe you can do this. Let me make sure I understand the problem. You are validating the user input of a slot. During that validation you’re checking if that value is acceptable using some criteria. If the value is valid you’d like to continue with the form. If the value is not valid you’d like to offer some dynamic button choices of the closest options based on your cosine similarity results?

Am I interpreting your problem correctly?

---

<div class="post-metadata">

### Author: ![pomegran](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/pomegran/32/16087_2.png) [@pomegran](https://forum.rasa.com/u/pomegran)
#### Post date: [March 18, 2021, 1:56pm UTC](https://forum.rasa.com/t/dynamically-adding-buttons-to-a-slot-response-in-a-form/41431/3 "2021-03-18T13:56:32Z")

</div>

Yep, that’s exactly it Matthew. I have my utter\_\<\> in my domain setup already, but I’d like to dynamically add buttons to it based on a validation criteria (cosine similarity match) I currently have setup.

---

<div class="post-metadata">

### Author: ![m.vielkind](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/m.vielkind/32/12693_2.png) [@m.vielkind](https://forum.rasa.com/u/m.vielkind)
#### Post date: [March 18, 2021, 2:55pm UTC](https://forum.rasa.com/t/dynamically-adding-buttons-to-a-slot-response-in-a-form/41431/4 "2021-03-18T14:55:30Z")

</div>

Great. Could you share what you have setup in the domain so far?

---

<div class="post-metadata">

### Author: ![pomegran](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/pomegran/32/16087_2.png) [@pomegran](https://forum.rasa.com/u/pomegran)
#### Post date: [March 18, 2021, 4:08pm UTC](https://forum.rasa.com/t/dynamically-adding-buttons-to-a-slot-response-in-a-form/41431/5 "2021-03-18T16:08:55Z")

</div>

Sure. The domain is very simple:

```
version: '2.0'
config:
  store_entities_as_slots: true
session_config:
  session_expiration_time: 60
  carry_over_slots_to_new_session: true
intents:
- report_damage:
    use_entities: true
- help_me:
    use_entities: true
entities:
- panel
- damage_type
- damage_severity
slots:
  panel:
    type: rasa.shared.core.slots.TextSlot
    initial_value: null
    auto_fill: true
    influence_conversation: true
  damage_type:
    type: rasa.shared.core.slots.TextSlot
    initial_value: null
    auto_fill: true
    influence_conversation: true
  damage_severity:
    type: rasa.shared.core.slots.TextSlot
    initial_value: null
    auto_fill: true
    influence_conversation: true
responses:
  utter_help:
    text: You need to enter the appropriate information.
  utter_ask_damage_form_panel:
  - text: Which panel was the damage on?
  utter_ask_damage_form_damage_type:
  - text: Can you tell me the type of damage please?
  utter_ask_damage_form_damage_severity:
  - text: Can you describe the damage severity please?
  utter_damage_form_complete:
  - text: The panel is <{panel}>, the damage_type is <{damage_type}> and the damage severity is <{damage_severity}>
actions:
- validate_damage_form
- action_default_fallback
- action_damage_form_complete
- action_reset_all_slots
forms:
  damage_form:
    damage_severity:
    - auto_fill: true
      entity: damage_severity
      initial_value: null
      type: from_text
    damage_type:
    - auto_fill: true
      entity: damage_type
      initial_value: null
      type: from_text
    panel:
    - auto_fill: true
      entity: panel
      initial_value: null
      type: from_text
e2e_actions: []
```

---

<div class="post-metadata">

### Author: ![ChikkaUdayaSai](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@ChikkaUdayaSai](https://forum.rasa.com/u/ChikkaUdayaSai)
#### Post date: [March 19, 2021, 4:21am UTC](https://forum.rasa.com/t/dynamically-adding-buttons-to-a-slot-response-in-a-form/41431/6 "2021-03-19T04:21:19Z")

</div>

Hi @pomegran ,

It’s possible. You need to use custom actions instead of utter\_ask{slot\_name}, you need to use action\_ask\_{slotname} and write logic in the custom actions.

Follow this docs for more info.

> **[Forms](https://rasa.com/docs/rasa/forms#using-a-custom-action-to-ask-for-the-next-slot)**
>
> Follow a rule-based process of information gathering using forms in open source bot framework Rasa.

---

<div class="post-metadata">

### Author: ![pomegran](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/pomegran/32/16087_2.png) [@pomegran](https://forum.rasa.com/u/pomegran)
#### Post date: [March 19, 2021, 7:28am UTC](https://forum.rasa.com/t/dynamically-adding-buttons-to-a-slot-response-in-a-form/41431/7 "2021-03-19T07:28:39Z")

</div>

Morning!

Ok, just to be clear, I just need to create a custom action called e.g. ‘action\_ask\_panel’? How does this get called in a form? Does it get called "under the hood’?

I’ll take a look this morning though, thanks for the speedy response!

---

<div class="post-metadata">

### Author: ![ChikkaUdayaSai](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@ChikkaUdayaSai](https://forum.rasa.com/u/ChikkaUdayaSai)
#### Post date: [March 19, 2021, 8:37am UTC](https://forum.rasa.com/t/dynamically-adding-buttons-to-a-slot-response-in-a-form/41431/8 "2021-03-19T08:37:33Z")

</div>

After creating the **action\_ask\_panel** in your actions.py, list down the **action\_ask\_panel** in domain.yml file under actions just like any other action name.

The action will be called automatically by the Form Logic.

---

<div class="post-metadata">

### Author: ![pomegran](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/pomegran/32/16087_2.png) [@pomegran](https://forum.rasa.com/u/pomegran)
#### Post date: [March 19, 2021, 8:56am UTC](https://forum.rasa.com/t/dynamically-adding-buttons-to-a-slot-response-in-a-form/41431/9 "2021-03-19T08:56:29Z")

</div>

Yep, got it. Thank you - works as you say (don’t know how I missed this in the docs).

For anybody else using this, also remove your “utter” for the slot as this takes precedence (if it exists).

Thanks for your help! 😀
