How to fill form fields from custom action

How to fill form fields from custom action , Instead of utter_ask_{slotname} , How to fill the form from custom action

The return value of an action is a list of events. The event you are looking for is

SlotSet(<name of slot>, <value you want to set>)

to use that import

from rasa_sdk.events import SlotSet

@IgNoRaNt23 , Thanks for the response . My problem is not slot filling, Is there a way to execute custom actions instead of the default utter_ask_{slot_name} templates in a FormAction?

1 Like

Sorry, I dont understand your problem. Could you give an example?

@IgNoRaNt23, when I was running FormAction , form fields are executed by asking the questions from utter_ask_{slot_name} in the domain file, Instead of that I want to run alternative for utter_ask_{slot_name}.

Not sure, what you call a ‘form field’. What you actually fill is called a slot. Anyway, its hard to understand what you want without providing an example. If you want to change the text you could just change the template.

Whatever, the function that produces the utter_ask_{slot_name} output is request_next_slot, you could overwrite that as well.

tldr: Provide an example if you want an actually helpful response

@IgNoRaNt23, Thanks for the response . How to overwrite request_next_slot. I want send below code.

response = [{

                   "title": store_name,
                   "subtitle": "this is a test address",
                   "image_url": "http://s3.amazonaws.c/15351164test.jpg",
                   "buttons": [{
                       "type": "postback",
                       "title": "Select Store",
                       "payload": store_id + " " + store_name,
                   }]
               }, {
                   "title": store_name,
                   "subtitle": "this is a test address",
                   "image_url": "http://s3.amazonaws.com/TestCapitalhypermarket.jpg",
                   "buttons": [{
                       "type": "postback",
                       "title": "Select Store",
                       "payload": store_id + " " + store_name,
                   }]
               }]

dispatcher.utter_custom_json(gt)

Just define a function with that name in your custom FormAction. Here is the default function from FormAction

    def request_next_slot(
    self,
    dispatcher,  # type: CollectingDispatcher
    tracker,  # type: Tracker
    domain,  # type: Dict[Text, Any]
):
    # type: (...) -> Optional[List[Dict]]
    """Request the next slot and utter template if needed,
        else return None"""

    for slot in self.required_slots(tracker):
        if self._should_request_slot(tracker, slot):
            logger.debug("Request next slot '{}'".format(slot))
            dispatcher.utter_template(
                "utter_ask_{}".format(slot),
                tracker,
                silent_fail=False,
                **tracker.slots
            )
            return [SlotSet(REQUESTED_SLOT, slot)]

    # no more required slots to fill
    return None

@IgNoRaNt23 , where can I write the above mentioned json code?

I have the same problem, did you find a solution?

Is there any way to do it?

Not sure, what you call a ‘form field’. What you actually fill is called a slot. Anyway, its hard to understand what you want without providing an example. If you want to change the text you could just change the template.