Rasa Chatbot: Handling repeated scenario

I am working in follow up bot, each user has many tasks, when user ask about his/her tasks, the Bot will fetch tasks using API then the bot will displayed the tasks one by one and going to ask the user if he/she able to finish it today. if user said yes the the the task will marked as completed if no the bot will ask the user about finished date.

I tired many solution in Action by iterate over tasks and dispatch template but after dispatching the loop stop and never go back again.

class ActionRequestTasks(Action):

def name(self):
    return "action_request_tasks"

@staticmethod
def json2obj(data):
    return json.loads(data, object_hook=lambda d: namedtuple('X', d.keys())(*d.values()))

def run(self, dispatcher, tracker: DialogueStateTracker, domain):
    response = requests.get('url', headers=headers)
    tasks_wrapper = self.json2obj(response.text)
    data = tasks_wrapper.Data
    first_message = "You have {} delayed tasks, I will help you to go through all of them".format(len(data))
    dispatcher.utter_message(first_message)

    for task in data:
        task_message = "Task Title {}\nComplete percentage {}\nStart Date {}\nFinish Date{}".format(task.Title,
                                                                                                    task.PercentComplete,
                                                                                                    task.StartDate,
                                                                                                    task.FinishDate)
        dispatcher.utter_message(task_message)
        dispatcher.utter_template("utter_able_to_finish", tracker)
    return []

1 answer

  • answered 2019-07-11 12:31 Tom Metcalfe

    This sounds like the perfect application for a Form. You can make the API call in the required_slots() method, then use validation to fill the slots dependent on the user's response. The form will run until all slots are filled, then you can decide what to do with the slots in the submit() method (for instance, updating the task status for each one via another request).

    I recommend reading the docs on Form setup and also checking out the code for formbot to see a working implementation