Sanjoy
Sanjoy

Reputation: 135

Using questionary CLI app within action server

I am using the questionary module from Tom Bocklisch built upon prompt_toolkit as part of an action in my action server. My environment is dockerized, i.e. I am using separate containers for NLU, Core and core_sdk.

The following code works perfectly when I run the basic code as a standalone script from rasa_core. However when I put it as an action in the action server running core_sdk, it fails.

def run(self, dispatcher, tracker, domain): acc = tracker.get_slot('account')

dev_key = requests.get('https://xxxx', timeout=5.0) 

questions = []

api_url = 'https://xxxx/token/' + dev_key 
api_key = requests.get(api_url, timeout=5.0)

field_data_url = 'https://xxxx/fields/' + api_key + '/' + 'Account'

fields = requests.get(field_data_url).json()
field_list = fields['Object']

for flds in field_list:
    if flds['IsRequired']:
        q_item = {'type': 'text', 'name': flds['FieldName'], 'message': flds['LabelText']}
        questions.append(q_item)

answers = qs.prompt(questions)


#SlotSet('account_fields', answers)


return answers

I guess it has something to do with interacting with CLI app over http but I am not sure how to deal with it. Any help would be highly appreciated.

Thanks

Upvotes: 0

Views: 41

Answers (1)

Tobias
Tobias

Reputation: 1910

What you are trying to do won't work. The action server has no access to your command line interface which you use to interact with Rasa Core since it is a separate server. The action server communicates with Rasa Core using HTTP requests. So if your action server executes qs.prompt(questions) there is no command line it can attach to, since it is completely independent of the Rasa Core command line interface.

If you want to ask users a question I would rather use dispatcher.utter_message or utter_templateto send messages to the user. If you want to have nice interactive prompts on your Core command line interface for actions which are executed on the action server you probably have to implement a custom channel which can process and format the bot answer accordingly.

Upvotes: 0

Related Questions