# Wait for user input in custom action

**URL:** <https://forum.rasa.com/t/wait-for-user-input-in-custom-action/22072>\
**Category:** Rasa Open Source\
**Created:** [December 4, 2019, 5:52pm UTC](https://forum.rasa.com/t/wait-for-user-input-in-custom-action/22072 "2019-12-04T17:52:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaelh](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@michaelh](https://forum.rasa.com/u/michaelh)\
**Post date:** [December 4, 2019, 5:52pm UTC](https://forum.rasa.com/t/wait-for-user-input-in-custom-action/22072/1 "2019-12-04T17:52:50Z")

</div>

Hello

i have an issue with dynamically creating buttons for multiple questions after each other, similar to: [How to get values from payload in button after choosing an option?](http://forum.rasa.com/t/how-to-get-values-from-payload-in-button-after-choosing-an-option/11979)

However, i have multiple questions. For now i tried to put them in a for-loop, but that returns all the questions/buttons at once, without waiting for user input. Is there a way to check for user input? like triggering “action\_listen” from my custom action.

> ```
> def run(self, dispatcher, tracker, domain):
> dispatcher.utter_message("Welches der Bilder entspricht dir am meisten?")
> custom_dicts = [[{"parameter1": 3*i+1,"payload": '/temporary{/"codes_tmp":/"code_'+str(3*i+1)+'/"',"title": f"Neigung {3*i+1}","typus": "image_button"},
> {"parameter1": 3*i+2,"payload": '/temporary{/"codes_tmp":/"code_'+str(3*i+2)+'/"',"title": f"Neigung {3*i+2}","typus": "image_button"},
> {"parameter1": 3*i+3,"payload": '/temporary{/"codes_tmp":/"code_'+str(3*i+3)+'/"',"title": f"Neigung {3*i+3}","typus": "image_button"}] for i in range(9)]
> 
> tmp_prev = ['code_1','code_2','code_3']
> SlotSet("n_1",['z'])
> for i in custom_dicts:
> dispatcher.utter_message("Welches der Bilder entspricht dir am meisten?")
> dispatcher.utter_custom_json(i)
> n_prev = tracker.get_slot('n_1')
> 
> #### here is the issue: how do i wait for the user input, before i read the slot to add the value to the list?
> n = [tracker.get_slot('codes_tmp')]
> # while not n in tmp_prev: # this is sth i tried, wait until the slot changes
> # print('sleep')
> # time.sleep(10)
> # tmp_prev = tmp_prev + n
> #SlotSet("n_1",n_prev+n)
> return[]
> 
> ```

---

<div class="post-metadata">

**Author:** ![btotharye](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/btotharye/32/5321_2.png) [@btotharye](https://forum.rasa.com/u/btotharye)\
**Post date:** [December 10, 2019, 12:09pm UTC](https://forum.rasa.com/t/wait-for-user-input-in-custom-action/22072/2 "2019-12-10T12:09:10Z")

</div>

Hey @michaelh sorry for the late reply we do have a `action_listen` it is documented at [Actions](https://rasa.com/docs/rasa/core/actions/#id2) along with some of the other options you have. Might be the best thing to use here, ask for a few options, get answer, maybe give more payload, etc.

---

<div class="post-metadata">

**Author:** ![michaelh](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@michaelh](https://forum.rasa.com/u/michaelh)\
**Post date:** [December 11, 2019, 5:03pm UTC](https://forum.rasa.com/t/wait-for-user-input-in-custom-action/22072/3 "2019-12-11T17:03:12Z")

</div>

Hi @btotharye

how would i call the action\_listen from within a custom function? I tried `FollowupAction("action_listen ")`, but that did not interrupt my loop and all the questions still came at once.

We solved it now on the frontend side, but it would still be nice to solve it within Rasa 🙂

---

<div class="post-metadata">

**Author:** ![btotharye](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/btotharye/32/5321_2.png) [@btotharye](https://forum.rasa.com/u/btotharye)\
**Post date:** [December 12, 2019, 12:03pm UTC](https://forum.rasa.com/t/wait-for-user-input-in-custom-action/22072/4 "2019-12-12T12:03:58Z")

</div>

Well from re-looking at this we don’t really support or recommend doing it that way. For this use case I would just use forms and set that up so it can ask for each of the different slot values then do something when they are all filled.

You can see more of this at [Forms](https://rasa.com/docs/rasa/core/forms/#id1)

---

<div class="post-metadata">

**Author:** ![michaelh](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@michaelh](https://forum.rasa.com/u/michaelh)\
**Post date:** [December 12, 2019, 1:32pm UTC](https://forum.rasa.com/t/wait-for-user-input-in-custom-action/22072/5 "2019-12-12T13:32:42Z")

</div>

Thank you.

I am aware that our solution is quite wonky, but we needed the custom json and the dynamic buttons and that unfortunately did not work with forms.
