How create drop down list from dynamic values

I want create drop down list of dynamic values,so how can I achieve that ?or any alternative way for this ?

Hello @Shweta_Mohite, drop down list for what? Please give an example with specific explanation.

Hey @Shweta_Mohite, it depends on the Chatbot UI you are using. Which UI are you using?

GitHub - JiteshGaikwad/Chatbot-Widget: ChatBot widget easy to connect to RASA bot through REST channel(HR bot) I have used and using REST api I have integrated with website.I am not understanding how I can use drop down menu inside chatbot and how to call it after specific intent as a response ? can you share any example or please explain.

@Ayad0net and @JiteshGaikwad I am fetching some values from database and wants to give user for selection using drop down list

hey @Shweta_Mohite, I havenā€™t added support for dropdown box in that UI but you can give it it a try, you can send the data using custom message from custom actions of Rasa and show it in the frontend.

1 Like

You can, by using custom action and send custom data to the frontend.

:one: [Frontend] -----> [Rasa]

:two: [Rasa] ā€”> [Custom action] ----> [Prepare data] ----> [Frontend]

:three: [Frontend] ----> [Handle data and render it to dropdown list]

@Ayad0net Please can you share one example or explain more I didnā€™t get what exactly I can do with custom actions ?will I need to use jquery or angular js for this ?

hi @JiteshGaikwad can you please tell me if Iā€™ll send data using dispatcher.utter_message(ā€œjson_message=ā€) then how I can fetch that data at front end.

Hey @Shweta_Mohite, just give me sometime I will create an example and show it to you, does that helps?

ok @JiteshGaikwad thanks alot

hey @Shweta_Mohite, I have added the support for dropdown message in the UI, you can test it out:

actions.py file contents:

# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/core/actions/#custom-actions/


# This is a simple example for a custom action which utters "Hello World!"

from typing import Any, Text, Dict, List

from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher


class ActionHelloWorld(Action):

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

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        
        data=[{"label":"option1","value":"/inform{'slot_name':'option1'}"},{"label":"option2","value":"/inform{'slot_name':'option2'}"},{"label":"option3","value":"/inform{'slot_name':'option3'}"}]
        message={"payload":"dropDown","data":data}
        dispatcher.utter_message(text="Hello World!",json_message=message)

        return []


Code for rendering the dropdown in the chat widget: https://github.com/JiteshGaikwad/Chatbot-Widget/blob/58f685643ef5e70603147f99b7b1f5e35b73be0f/static/js/script.js#L227

Output:

Screenshot%20from%202020-03-10%2020-37-32

Let me know if this helps you :slight_smile:

5 Likes

Done !!! hey @JiteshGaikwad thank you very much ! really means alot !!

@Shweta_Mohite, Glad that it helped you :slight_smile:

1 Like

Hi @JiteshGaikwad I am able to get button value using this : if tracker.latest_message[ā€˜intentā€™][ā€˜nameā€™] == ā€˜informā€™: da =tracker.latest_message[ā€˜textā€™] but I want to get this condition inside so I am not able to get slot name as a inform so is there any alternative way to take button value ?or how I can get slot name ā€˜infromā€™ value?

@JiteshGaikwad do I have to mention ā€˜informā€™ as intent in nlu file ? if yes can you tell how ?

Hey @Shweta_Mohite, sorry for the late response. You need to check whether that slot_name key exists

Hi @JiteshGaikwad Iā€™m getting this warning

UserWarning: Failed to parse arguments in line ā€˜/inform{ā€˜slot_nameā€™:fcec1244-565d-5568-99d1-cbd127112e20}ā€™. Failed to decode parameters as a json object. Make sure the intent is followed by a proper json object. Error: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

I have used this:

    if intent_name == 'check_balance':
        data = []
        for (id, acc_no) in zip(ac_ids, accounts):
            data.append({"label": acc_no, "value": "/inform{'slot_name':" + id+"}"})

can you tell where I am doinng wrong ?do I need to write ā€˜infromā€™ as in intent in domain file or nlu ?

Hey @Shweta_Mohite, can you share the above errorā€™s screenshot?