# From action ask user to choose item from list

**URL:** <https://forum.rasa.com/t/from-action-ask-user-to-choose-item-from-list/49273>\
**Category:** Rasa Open Source\
**Tags:** testing\
**Created:** [November 16, 2021, 12:59pm UTC](https://forum.rasa.com/t/from-action-ask-user-to-choose-item-from-list/49273 "2021-11-16T12:59:31Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![pb1234](https://avatars.discourse-cdn.com/v4/letter/p/f4b2a3/32.png) [@pb1234](https://forum.rasa.com/u/pb1234)\
**Post date:** [November 16, 2021, 12:59pm UTC](https://forum.rasa.com/t/from-action-ask-user-to-choose-item-from-list/49273/1 "2021-11-16T12:59:31Z")

</div>

Hi I want to create a form which asks the user to choose a value from a list. This list is dynamic and is retrieved from another python call.

The flow would be something like this:

> user: “Select filter”  
> background → retrieves list of filter options  
> bot: “These are the available filters:   
> 1) country  
> 2) date  
> …”  
> user: “by country please”   
> background → sets filter

I can get the flow to set the slots (as I´ve given it some examples) but I cannot get the bot to print the list of filters to the user. I believe its something to do with my action or story. Tbh I´m unsure how I should set up the story for a flow like this.

**ACTION:**

```auto
import requests
import json

from typing import Any, Text, Dict, List
from rasa_sdk import Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk import Action
from rasa_sdk.events import SlotSet

class ActionSelectFilters(Action):

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

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        URL = 'http://localhost:8082/process'
        HEADERS = {'content-type': 'application/json', 'charset': 'UTF-8'}

        # Retrieve slots
        selected_filter = tracker.get_slot("filter")

        data = {
            "action": "select_filter",
            "filter": selected_filter
        }

        try:
            if selected_filter is None: # No filter specified
                r = requests.post(url=URL, headers=HEADERS, json=data, verify=False)
                output = json.loads(r.text)

                dispatcher.utter_message(response="utter_ask_for_filter")
                dispatcher.utter_message(response="\n".join(output["filter"]))

                return [SlotSet("filter", None)]

            else: # Filter specified
                r = requests.post(url=URL, headers=HEADERS, json=data, verify=False)
                output = json.loads(r.text)

            if output and "type" in output and output["type"] == "error":
                print(f"Received exception from web service: {output['message']}")
                return [] # Finished --> error
            elif output["complete"]:
                dispatcher.utter_message(response="utter_filter_set")
                return [] # Finished

        except Exception as ex:
            print(f"Exception received: {ex}")

```

---

_[View the full topic](https://forum.rasa.com/t/from-action-ask-user-to-choose-item-from-list/49273)._
