# How to define buttons in forms in Rasa 3.0

**URL:** <https://forum.rasa.com/t/how-to-define-buttons-in-forms-in-rasa-3-0/50932>\
**Category:** Rasa Open Source\
**Created:** [January 27, 2022, 2:15pm UTC](https://forum.rasa.com/t/how-to-define-buttons-in-forms-in-rasa-3-0/50932 "2022-01-27T14:15:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![LindaA](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/lindaa/32/18445_2.png) [@LindaA](https://forum.rasa.com/u/LindaA)\
**Post date:** [January 27, 2022, 2:15pm UTC](https://forum.rasa.com/t/how-to-define-buttons-in-forms-in-rasa-3-0/50932/1 "2022-01-27T14:15:10Z")

</div>

Hi RASA community,

I certainly scanned the whole rasa documentation but am completely unable to find specifications regarding buttons in forms. I really would like to use buttons as answer format to fill the slots but I don’t know how to implement it.

If slots are defined like that:

```auto
slots:
  departure_city:
    type: text
    mappings:
    - type: from_entity
      entity: city
      role: from
    - type: from_entity
      entity: city
  arrival_city:
    type: text
    mappings:
    - type: from_entity
      entity: city
      role: to
    - type: from_entity
      entity: city
  arrival_date:
    type: any
    mappings:
    - type: from_entity
      entity: date
forms:
  your_form:
    required_slots:
    - departure_city
    - arrival_city
    - arrival_date

```

And buttons are defined like that:

```auto
responses:
  utter_greet:
  - text: "Hey! How are you?"
    buttons:
    - title: "great"
      payload: "/mood_great"
    - title: "super sad"
      payload: "/mood_sad"

```

How to bring them both together? I would love to have some documentation on that since it is really hard to migrate from 2 to 3 otherwise.

Thank you sooo much in advance!

---

<div class="post-metadata">

**Author:** ![E-dC](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@E-dC](https://forum.rasa.com/u/E-dC)\
**Post date:** [January 27, 2022, 2:41pm UTC](https://forum.rasa.com/t/how-to-define-buttons-in-forms-in-rasa-3-0/50932/2 "2022-01-27T14:41:00Z")

</div>

Hi @LindaA ,

For each slot to fill in a form, Rasa will look for a response called `utter_ask_<form_name>_<slot_name>`: see [Forms](https://rasa.com/docs/rasa/forms#defining-a-form:)

> Once the form action gets called for the first time, the form gets activated and will prompt the user for the next required slot value. It does this by looking for a [response](https://rasa.com/docs/rasa/responses) called `utter_ask_<form_name>_<slot_name>` or `utter_ask_<slot_name>` if the former isn’t found. Make sure to define these responses in your domain file for each required slot.

You can then define your response as usual:

```yaml
 utter_ask_welcome_form_wellbeing_slot:
  - text: "Hey! How are you?"
    buttons:
    - title: "great"
      payload: "/mood_great"
    - title: "super sad"
      payload: "/mood_sad"

```

FInally, in your domain you can define your `wellbeing_slot` (in above example) as being mapped from an intent (or a trigger intent) (see: [Domain](https://rasa.com/docs/rasa/domain#from_intent)):

```yaml
  wellbeing_slot:
    type: any # Change the type as needed
    mappings:
    - type: from_intent
      value: some_value_to_put_in_wellbeing_slot_when_mood_great
      intent: mood_great
    - type: from_intent
      value: some_value_to_put_in_wellbeing_slot_when_mood_sad
      intent: mood_sad

```

This should work because the _payloads_ defined in your responses are kinda like shortcuts to the corresponding intents. This also has the advantage that if a user ignores the buttons and types “I’m great”, your form should still capture the intent `mood_great`.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![LindaA](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/lindaa/32/18445_2.png) [@LindaA](https://forum.rasa.com/u/LindaA)\
**Post date:** [January 27, 2022, 3:15pm UTC](https://forum.rasa.com/t/how-to-define-buttons-in-forms-in-rasa-3-0/50932/3 "2022-01-27T15:15:09Z")

</div>

Thank you! I will try it out. Just a follow-up question: What can “value” be? A string defined with quotations marks or a number? Mainly asking for when I want to use the value for processing…

---

<div class="post-metadata">

**Author:** ![E-dC](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@E-dC](https://forum.rasa.com/u/E-dC)\
**Post date:** [January 27, 2022, 3:23pm UTC](https://forum.rasa.com/t/how-to-define-buttons-in-forms-in-rasa-3-0/50932/4 "2022-01-27T15:23:57Z")

</div>

I’m not sure, the docs don’t precise that, but my guess would be primitive data types like string, number, boolean? Perhaps anything handled in YAML?  
You can probably try by writing an action which uses the value and see what you can pass 🙂

---

<div class="post-metadata">

**Author:** ![LindaA](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/lindaa/32/18445_2.png) [@LindaA](https://forum.rasa.com/u/LindaA)\
**Post date:** [January 27, 2022, 5:28pm UTC](https://forum.rasa.com/t/how-to-define-buttons-in-forms-in-rasa-3-0/50932/5 "2022-01-27T17:28:46Z")

</div>

Thank you a lot! I just tried the solution out you suggested but my bot won’t ask the question with the button solutions. Do you know what I’m doing wrong?

Here is my code:

NLU:

```auto
- intent: mood_great
  examples: |
    - perfect
    - great
    - amazing
    - feeling like a king
    - wonderful
    - I am feeling very good
    - I am great
    - I am amazing
    - I am going to save the world
    - super stoked
    - extremely good
    - so so perfect
    - so good
    - so perfect

- intent: mood_unhappy
  examples: |
    - my day was horrible
    - I am sad
    - I don't feel very well
    - I am disappointed
    - super sad
    - I'm so sad
    - sad
    - very sad
    - unhappy
    - not good
    - not very good
    - extremly sad
    - so saad
    - so sad

- intent: inform
  examples: |
    - [Mambo No.5](song) is my favorite song
    - my favorite song is [Saturday night fever](song)
    - I love [Take a chance on me](song)
    - what do you think about [Let it be](song) as a song
    - hmm [dance night long](song)
    - I would say [everything from ABBA](song) 
    - a great song is [coconat banana](song)
    - [Let it be](song)
    - [walking on sunshine](song) 
    - Definitely [walking on sunshine](song)
    - 5 coffee per day
    - 2 cofffe in the moring
    - 3 during the day
    - 6 in a day
    - I drink not much coffe just 1
    - only 1 cup

```

Rules:

```auto
- rule: activate basic form
  steps:
  - intent: take_survey
  - action: basic_form
  - active_loop: basic_form

- rule: submit basic form
  condition:
  - active_loop: basic_form
  steps:
    - action: basic_form
    - active_loop: null
    - slot_was_set:
      - requested_slot: null
    - action: utter_submit
    - action: utter_slots_values

```

Domain:

```auto

intents:
  - greet
  - goodbye
  - affirm
  - deny
  - mood_great
  - mood_unhappy
  - bot_challenge
  - take_survey
  - inform

entities:
- number
- song
slots:
  song:
    type: text
    mappings:
    - type: from_entity
      entity: song
  num_coffee:
    type: any
    mappings:
    - type: from_entity
      entity: number
  wellbeing: 
    type: any
    mappings: 
    - type: from_intent
      value: good_mood
      intent: mood_great
    - type: from_intent
      value: bad_mood
      intent: mood_unhappy

responses:
  utter_submit:
  - text: "All done!"

  utter_slots_values:
  - text: "That are your values:\n
           - song: {song}\n
           - num_coffee: {num_coffee}\n
           - wellbeing: {wellbeing}\n"

  utter_ask_song:
  - text: "What is your favorite song?"

  utter_ask_num_coffee:
  - text: "How many cup of coffees to you think?"

  utter_ask_wellbeing: 
  - text: "Hey! How are you?"
    buttons:
    - title: "Great!"
      payload: "/mood_great"
    - title: "Super sad"
      payload: "/mood_unhappy"

forms:
  basic_form:
    # ignored_intents: 
    # - chitchat
    required_slots:
        - song
        - num_coffee
        - wellbeing

```

The rule policy is set in the config file. Your help is highly appreciated!

---

<div class="post-metadata">

**Author:** ![LindaA](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/lindaa/32/18445_2.png) [@LindaA](https://forum.rasa.com/u/LindaA)\
**Post date:** [January 27, 2022, 6:06pm UTC](https://forum.rasa.com/t/how-to-define-buttons-in-forms-in-rasa-3-0/50932/8 "2022-01-27T18:06:28Z")

</div>

Maybe it is because of the “type: any?”

> Slots of type `any` are always ignored during conversations. The property`influence_conversation` cannot be set to `true` for this slot type. If you want to store a custom data structure which should influence the conversation, use a [custom slot type](https://rasa.com/docs/rasa/domain#custom-slot-types). in [Domain](https://rasa.com/docs/rasa/domain/#unique-from_entity-mapping-matching)

Could it possible that I need to use something like categorical and then write a custom slot mapping? But I’m wondering why the bot is not even providing the question…

---

<div class="post-metadata">

**Author:** ![E-dC](https://avatars.discourse-cdn.com/v4/letter/e/9fc348/32.png) [@E-dC](https://forum.rasa.com/u/E-dC)\
**Post date:** [January 31, 2022, 2:47pm UTC](https://forum.rasa.com/t/how-to-define-buttons-in-forms-in-rasa-3-0/50932/9 "2022-01-31T14:47:19Z")

</div>

Hi @LindaA,  
Missed the post updates, apologies. I’m unsure what is going wrong, but I’d try a few things:

- Are the two other slot questions being asked? If so, try putting `wellbeing` first in your form definition so that you can see if the problem lies with the other slots or `wellbeing` itself (perhaps it is never triggered at all)
- As you wrote, I’d avoid type `any` and change `wellbeing` to `categorical` and `num_coffee` to `float`. But I don’t see why that would affect the forms 😕
- You could try running `rasa shell --debug` when chatting with the bot and see what the core model is predicting, that might help too

---

<div class="post-metadata">

**Author:** ![LindaA](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/lindaa/32/18445_2.png) [@LindaA](https://forum.rasa.com/u/LindaA)\
**Post date:** [February 8, 2022, 2:27pm UTC](https://forum.rasa.com/t/how-to-define-buttons-in-forms-in-rasa-3-0/50932/10 "2022-02-08T14:27:24Z")

</div>

Your debug suggestion showed me the right way, it works now. Many thanks! 🙂
