I need some pointers on calling custom action from formaction. Below is what I’ve done so far -
I have an unfeaturized variable - programGrp that is to be used for populating dynamic buttons. Dynamic, because the button payloads and titles are to be populated from the DB dip. For this I’ve written a custom action - “action_populate_prog_grp”.
Now there are other properties (to be filled) as well, so I’m using FormAction - like name, email etc.
The requested_slots are like this -
[“name”, “email”, “phone”, “programGrp”]
I’ve set the slot_mappings for “programGrp” -
“programGrp”: self.from_entity(entity=“programGrp”),
I’ve created some stories in the interactive mode and have directed to call - “action_populate_prog_grp” before form submit.
Now when I try to run rasa shell, it never predicts “action_populate_prog_grp” and waits for user input after the utterance - “utter_ask_programGrp”
So, in a nut-shell how to manage the dynamic buttons in FormAction ?
I’d appreciate if you can give a small example to explain how it’s to be done.
I would suggest running a validation within the form to handle this instead of calling a separate action, this way the slot can be filled dynamically within the form code itself. There’s docs on validation actions here and an example of how this works in the formbot too. Try it out and let me know if this doesn’t solve the issue.
Hi, What I have understood is you have to add buttons having dynamic title and payload when slot programGrp is asked.
Go ahead and overwrite this function “request_next_slot”.
I have attached code for your reference
for slot in self.required_slots(tracker):
if self._should_request_slot(tracker, slot):
if slot == 'programGrp':
//perform your db hit here and append the data in button title and payload
buttons=[]
buttons.append({"title": 'dynamic_title', "payload":'dynamic_payload'})
dispatcher.utter_message(text="Whaterver text or template you have", buttons=buttons)
## For all other slots, continue as usual
else:
dispatcher.utter_message(template=f"utter_ask_{slot}", **tracker.slots)
return [SlotSet(REQUESTED_SLOT, slot)]
return None
hi @alkak95 …need some help please… i was able to create the json for dynamic buttons with for loop from an api response… my problem right now is how can i write an intent to perform an action for a button click which can be anything?
I want to capture the dynamic title clicked by user. I can do it with Tracker data but my problem is how to trigger the action without any intent since I can’t add every possible dynamic title of a button as examples for intent.