# Ask in different ways for the same slot

**URL:** <https://forum.rasa.com/t/ask-in-different-ways-for-the-same-slot/50597>\
**Category:** Rasa Open Source\
**Created:** [January 14, 2022, 1:20pm UTC](https://forum.rasa.com/t/ask-in-different-ways-for-the-same-slot/50597 "2022-01-14T13:20:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Belen](https://avatars.discourse-cdn.com/v4/letter/b/898d66/32.png) [@Belen](https://forum.rasa.com/u/Belen)\
**Post date:** [January 14, 2022, 1:20pm UTC](https://forum.rasa.com/t/ask-in-different-ways-for-the-same-slot/50597/1 "2022-01-14T13:20:18Z")

</div>

Hi,

I would like to ask for a slot first with a question that can be answered with text, and then, if the slot is not filled, ask for the same slot with buttons.

I have tried it with with this custom action.

```auto
class AskForComidaAction(Action):
    def __init__ (self):
        self.first_time = True

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

    def run(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> List[EventType]:
        if self.first_time:
            dispatcher.utter_message(f"¿Qué tipo de comida te gustaría pedir?")
            self.first_time = False
        else:
            dispatcher.utter_message(
                text=f"No lo he entendido, ¿qué tipo de comida te gustaría pedir?",
                buttons=[{"title": p, "payload": p} for p in ['Pizza', 'Hamburguesa', 'Ensalada']]
            )
        return []

```

This action works, the problem is that the parameter first\_time is only True when the action server starts, not when a conversation starts.

Can this problem be solved in any way?

---

<div class="post-metadata">

**Author:** ![ILG2021](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/ilg2021/32/18166_2.png) [@ILG2021](https://forum.rasa.com/u/ILG2021)\
**Post date:** [January 14, 2022, 1:28pm UTC](https://forum.rasa.com/t/ask-in-different-ways-for-the-same-slot/50597/2 "2022-01-14T13:28:34Z")

</div>

> [@Belen](#):
>
> uld like to ask for a slot first with a question that can be answered with text, and then, if the slot is not filled, ask for the same slot with buttons.

I think it is a common misunderstand for rasa starter, I have do the same thing like you, then somebody teach me to use slot. You should always use slot instead of variable, because it is the bot’s memory 😀.

---

<div class="post-metadata">

**Author:** ![Belen](https://avatars.discourse-cdn.com/v4/letter/b/898d66/32.png) [@Belen](https://forum.rasa.com/u/Belen)\
**Post date:** [January 14, 2022, 8:04pm UTC](https://forum.rasa.com/t/ask-in-different-ways-for-the-same-slot/50597/3 "2022-01-14T20:04:01Z")

</div>

Thanks for you reply @ILG2021

Actually I use the slot `comida` and this action is to ask about it.

I know what I could add in responses `utter_ask_comida` with a question or buttons, but I want to ask first with a question, and then, if the slot is not filled with the user’s text, ask again with buttons.

Sorry for not being clear earlier, I have an entity with the same name as the slot to be able to extract it from the user’s text, but I would like to limit the possible answers after asking once.

---

<div class="post-metadata">

**Author:** ![Belen](https://avatars.discourse-cdn.com/v4/letter/b/898d66/32.png) [@Belen](https://forum.rasa.com/u/Belen)\
**Post date:** [February 8, 2022, 4:42pm UTC](https://forum.rasa.com/t/ask-in-different-ways-for-the-same-slot/50597/4 "2022-02-08T16:42:04Z")

</div>

I have found a possible solution to my problem.

I have created the slot `first_time_buttons` as follows

```auto
slots:
  first_time_buttons:
    type: bool
    initial_value: True
    mappings:
      - type: custom

```

then I have changed the action that asks for the slot as follows:

```auto
    class AskForComidaAction(Action):
        def __init__ (self):
            self.first_time = True

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

        def run(
                self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
        ) -> List[EventType]:
            first_time_buttons = tracker.get_slot("first_time_buttons")
            if first_time_buttons:
                dispatcher.utter_message(f"¿Qué tipo de comida te gustaría pedir?")
                return [SlotSet("first_time_buttons", False)]
            else:
                dispatcher.utter_message(
                    text=f"No lo he entendido, ¿qué tipo de comida te gustaría pedir?",
                    buttons=[{"title": p, "payload": p} for p in ['Pizza', 'Hamburguesa', 'Ensalada']]
                )
            return []

```

and then in the form validation, I create a function that validates the slot only to set the value of `first_time_buttons` back to True, since I ask this way for multiple slots.

```auto
    def validate_comida(
        self,
        slot_value: Any,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: DomainDict,
    ) -> Dict[Text, Any]:
        if slot_value:
            return {
                "comida": slot_value,
                "first_time_buttons": True,
            }
        return {}

```
