@@ -191,9 +191,38 @@ to set, you can set more slots than just the one you are validating from inside
191
191
a helper validation method. However, you are responsible for making sure that
192
192
those extra slot values are valid.
193
193
194
- You can also deactivate the form directly during this validation step (in case the
195
- slot is filled with something that you are certain can't be handled) by returning
196
- ``self.deactivate() ``
194
+ In case the slot is filled with something that you are certain can't be handled
195
+ and you want to deactivate the form directly,
196
+ you can overwrite the ``request_next_slot() `` method to do so. The example below
197
+ checks the value of the ``cuisine `` slot directly, but you could use any logic
198
+ you'd like to trigger deactivation:
199
+
200
+ .. code-block :: python
201
+
202
+ def request_next_slot (
203
+ self ,
204
+ dispatcher : " CollectingDispatcher" ,
205
+ tracker : " Tracker" ,
206
+ domain : Dict[Text, Any],
207
+ ) -> Optional[List[EventType]]:
208
+ """ Request the next slot and utter template if needed,
209
+ else return None"""
210
+ for slot in self .required_slots(tracker):
211
+ if self ._should_request_slot(tracker, slot):
212
+
213
+ # # Condition of validated slot that triggers deactivation
214
+ if slot == " cuisine" and tracker.get_slot(" cuisine" ) == " caribbean" :
215
+ dispatcher.utter_message(text = " Sorry, I can't help you with that" )
216
+ return self .deactivate()
217
+
218
+ # # For all other slots, continue as usual
219
+ logger.debug(f " Request next slot ' { slot} ' " )
220
+ dispatcher.utter_message(
221
+ template = f " utter_ask_ { slot} " , ** tracker.slots
222
+ )
223
+ return [SlotSet(REQUESTED_SLOT , slot)]
224
+ return None
225
+
197
226
198
227
If nothing is extracted from the user's utterance for any of the required slots, an
199
228
``ActionExecutionRejection `` error will be raised, meaning the action execution
0 commit comments