Multiple slots in custom action

I am doing payment chat bot for that i am calling lot of API with large number of parameter values so i have to save these parameter values in different slots.So can you please let me know how can i set multiple slots in custom action.

Also if there is any other best way to store these multiple parameters values in slots so that i can access them in different classes please let me know(like inheritance in python class)

Thanks in advance

can any one help me with this

Hi @surya1994. Happy to help. Can you give me an example of what slots you would like to set? That would help me to give you the best advise :slight_smile:

Regarding accessing the slots in different classes - you can access the slots values using the tracker. So if the slots is set, the values should be accessible in any class using the method tracker.get_slot('slot_name')

Thanks @Juste Below is a story in which i will set username and password through forms( user_login_form) here in this story when user_login_form action gets activated it should take username and password and set them in slots instead it is throwing below error and all the actions are also showing same error. I already completed story without forms it is working fine so can you please let me know why i am facing error with forms and with required solution

  • user_payment_message
  • utter_message_login_credentials
  • utter_yes_no_buttons
  • affirm
  • user_login_form
  • form{“name”: “user_login_form”}
  • form{“name”:“null”}
  • action_outstanding_amount_preprocess
  • action_outstanding_amount
  • utter_payment_message
  • utter_yes_no_buttons
  • affirm

Error: Predicted next action ‘user_login_form’ with confidence 1.00. 2019-07-23 11:34:21 DEBUG rasa.core.actions.action - Calling action endpoint to run action ‘user_login_form’. 2019-07-23 11:34:21 ERROR rasa.core.processor - Encountered an exception while running action ‘user_login_form’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code. 2019-07-23 11:34:21 DEBUG rasa.core.processor - Failed to execute custom action. Traceback (most recent call last): File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/core/actions/action.py”, line 397, in run json=json_body, method=“post”, timeout=DEFAULT_REQUEST_TIMEOUT File “/u01/app/anaconda3/envs/rasa/lib/python3.6/asyncio/coroutines.py”, line 110, in next return self.gen.send(None) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/utils/endpoints.py”, line 142, in request resp.status, resp.reason, await resp.content.read() rasa.utils.endpoints.ClientResponseError: 500, INTERNAL SERVER ERROR, body=‘b’\n500 Internal Server Error\n

Internal Server Error

\n

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

\n’’

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/core/processor.py”, line 439, in _run_action events = await action.run(output_channel, nlg, tracker, self.domain) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/asyncio/coroutines.py”, line 110, in next return self.gen.send(None) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa/core/actions/action.py”, line 419, in run raise Exception(“Failed to execute custom action.”) from e Exception: Failed to execute custom action. 2019-07-23 11:34:21 DEBUG rasa.core.processor - Action ‘user_login_form’ ended with events ‘[]’ 2019-07-23 11:34:21 DEBUG rasa.core.processor - Current slot values: Email_address: None group_num: None password: None requested_slot: None user_id: None user_name: None 2019-07-23 11:34:21 DEBUG rasa.core.policies.memoization - Current tracker state [{‘intent_user_payment_message’: 1.0, ‘prev_action_listen’: 1.0}, {‘prev_utter_message_login_credentials’: 1.0, ‘intent_user_payment_message’: 1.0}, {‘intent_user_payment_message’: 1.0, ‘prev_utter_yes_no_buttons’: 1.0}, {‘intent_affirm’: 1.0, ‘prev_action_listen’: 1.0}, {‘intent_affirm’: 1.0, ‘prev_user_login_form’: 1.0}] 2019-07-23 11:34:21 DEBUG rasa.core.policies.memoization - There is no memorised next action 2019-07-23 11:34:21 DEBUG rasa.core.policies.mapping_policy - There is no mapped action for the predicted intent, ‘affirm’. 2019-07-23 11:34:21 DEBUG rasa.core.policies.form_policy - There is no active form 2019-07-23 11:34:21 DEBUG rasa.core.policies.fallback - NLU confidence threshold met, confidence of fallback action set to core threshold (0.4). 2019-07-23 11:34:21 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_4_FallbackPolicy 2019-07-23 11:34:21 DEBUG rasa.core.processor - Predicted next action ‘action_custom_fallback’ with confidence 0.40. 2019-07-23 11:34:21 DEBUG rasa.core.actions.action - Calling action endpoint to run action ‘action_custom_fallback’.

core: 2019-07-23 11:34:21 ERROR flask.app - Exception on /webhook [POST] Traceback (most recent call last): File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/flask/app.py”, line 2292, in wsgi_app response = self.full_dispatch_request() File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/flask/app.py”, line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/flask_cors/extension.py”, line 161, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/flask/app.py”, line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/flask/_compat.py”, line 35, in reraise raise value File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/flask/app.py”, line 1813, in full_dispatch_request rv = self.dispatch_request() File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/flask/app.py”, line 1799, in dispatch_request return self.view_functionsrule.endpoint File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/flask_cors/decorator.py”, line 128, in wrapped_function resp = make_response(f(*args, **kwargs)) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa_sdk/endpoint.py”, line 59, in webhook response = executor.run(action_call) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa_sdk/executor.py”, line 245, in run events = action(dispatcher, tracker, domain) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa_sdk/forms.py”, line 530, in run events.extend(self._validate_if_required(dispatcher, tracker, domain)) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa_sdk/forms.py”, line 502, in _validate_if_required return self.validate(dispatcher, tracker, domain) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa_sdk/forms.py”, line 350, in validate slot_values = self.extract_other_slots(dispatcher, tracker, domain) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa_sdk/forms.py”, line 230, in extract_other_slots other_slot_mappings = self.get_mappings_for_slot(slot) File “/u01/app/anaconda3/envs/rasa/lib/python3.6/site-packages/rasa_sdk/forms.py”, line 171, in get_mappings_for_slot self.slot_mappings().get(slot_to_fill, self.from_entity(slot_to_fill)) File “/u01/app/anaconda3/envs/rasa/Make_apayment_form/actions.py”, line 44, in slot_mappings

actions.py

-- coding: utf-8 --

from future import absolute_import from future import division from future import print_function from future import unicode_literals

import logging import requests import json from rasa_sdk import Action from rasa_sdk.events import SlotSet from rasa_sdk.events import Restarted from rasa_sdk.events import UserUtteranceReverted from rasa_sdk.events import UserUttered from rasa_sdk.forms import FormAction from rasa_sdk import Tracker from rasa_sdk.executor import CollectingDispatcher from typing import Dict, Text, Any, List, Union, Optional

logger = logging.getLogger(name)

#Form action logic class UserLoginForm(FormAction): “”“Example of a custom form action”""

def name(self):
    """Unique identifier of the form"""

    return "user_login_form"

@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:
    """A list of required slots that the form has to fill"""
    print("required slots")
    return ["user_id","password"]

def slot_mappings(self):
    # type: () -> Dict[Text: Union[Dict, List[Dict]]]
    """A dictionary to map required slots to
        - an extracted entity
        - intent: value pairs
        - a whole message
        or a list of them, where a first match will be picked"""
    print("user_id",user_id)
    print("password",password)
    return {"user_id": [self.from_text()],"password": [self.from_text()]}

def submit(self):
    """Define what the form has to do
        	after all required slots are filled"""
    dispatcher.utter_template("utter_submit", tracker)
    return []

Can any one help with with the issue ?