Restart conversation inside validation function

How do I restart conversation inside validation function? If I return “Restarted()” it just sets the current slot to [{‘event’: ‘restart’, ‘timestamp’: None}]

Why would you want to do that?

One of my slots is an intermediary check of an external api call. If the call does not return any value, it is because the current slots that were already set do not work and we need to restart to either: restart the form OR reset the conversation. I can restart the form by setting all slots to None but I can’t restart the conversation in case the user does not want to continue.

If the user doesn’t want to continue, can you reset the form and deactivate it ? Is there a reason you have to restart the conversation ? It seems like the history of the conversation shouldn’t have any impact to the conversation if the user just want to get out of the form and move on.

No, I don’t need to restart the conversation, I just need to deactivate the form and reset (set all slots to None). How do I do this in the validation function?

In the validation_{slot_name} function, you can simply return self.deactivate() to deactivate the current form. Read more at: Forms.

If i remember correctly, it will only reset the currently requested_slot though.

Yeah, that won’t work. I can manually set all slots to None, but still, it does not deactivate the form and the bot then asks for the first slot again (instead of forgetting the form)

You mean the self.deactivate() function doesn’t deactivate the form or it doesn’t reset all the slot ?

sorry I explained it incorrectly. Returning self.deacttivate() in the validation function sets the slot to: “[{‘event’: ‘form’, ‘name’: None, ‘timestamp’: None}, {‘event’: ‘slot’, ‘name’: ‘requested_slot’, ‘timestamp’: None, ‘value’: None}]”

It also does not reset the form and continues asking for the next slots.

You cant use self.deactivate() in the validation function, because the validation function returns a dictionary. You want any function, that may return events. You could for example check for the slot value in the request_next_slot method and return self.deactivate there.

Ok thank you very much. I’ll try that!

I works :slight_smile:

hi @teresalazar13 I have the same issue. Can you provide your request_next_slot method

Hi @lindig.

Your can try sth such as:

def request_next_slot(......:
    if tracker.get_slot(name_of_slot) == something:
         return self.deactivate()
1 Like