简体   繁体   中英

How can i use action_listen inside a custom action in Rasa

I want to listen to user inside custom action and then continue that custom action. Basically what i am looking for is.

I have a loop in custom action from 0 to 5. for each value i want to take some input from user and continue that loop.

def Action():
   for 0 to 5:
      input = action_listen
      // do something with input

You should use a form for this. A form loops over a set of slots that you define until all are filled.

Looping with action_listen in a regular action won't work because an action has only one run() method and the events are only added to the tracker once the run() method has returned, after which the action is completed (and you can't get back into it).

https://rasa.com/docs/rasa/core/forms/

Thanks for your response, but some tricks also works for me to do the same in custom action.

I returned the Form as FollowUpAction at each iteration and reduce the loop variable by one.

Now the Form will ask the user to get required slot (Do the needful with with information) and again Set the slot to None with SlotSet. Now return the Action as FollowUpAction in form.

In this way for each iteration Bot will take response from user.

global i = 0
class Action():
   def run():
      for i to 5:
         return [FollowUpAction('ActionForm')]

class ActionForm():
   def requiredslot():
         return ['take_value']

   def submit():
         //Do needful with input
         return [SlotSet("take_value", None), FollowUpAction("my_action")]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM