Welcome to the Forum, Testie!
I would just like to add something a little more advanced, but cleaner in my opinion.
You can have a form with buttons on each question.
Every button will have the same payload intent, but different entities.
'/inform{{"pizza":"cheese"}}'
'/inform{{"delivered":"no"}}'
'/inform{{"time":"8pm"}}'
The entity values specified in the payload will be saved in a slot of the same name for long-term memory (entities are for short-term memory, they get reset on every message).
Then, in the form, to branch off, you can have a dynamic form behavior to ask for a slot depending on a previous one.
To stop the form when the user presses x
, its button payload would have to be a different intent. e.g., /cancel
. In a rule and/or story, you can specify to deactivate the form by handling an unhappy path and execute a certain action if that intent was detected.
stories:
- story: User doesn't want to continue
steps:
- intent: request_restaurant
- action: restaurant_form
- active_loop: restaurant_form
- intent: cancel
- action: action_deactivate_loop
- active_loop: null
- action: utter_canceled
That certain action is a custom action that will reset all the slots.
- story: User doesn't want to continue
steps:
# etc...
- active_loop: null
- action: action_reset_slots
You can reset the slots by returning a list of SlotSet events which will each set its given slot to the value None
. Alternatively, if you want to reset absolutely all slots, you can use the AllSlotsReset event.
return [SlotSet('pizza', None), SlotSet('delivered', None), SlotSet('time', None)]
return [AllSlotsReset()]
If you want the form to automatically restart after canceling, you can also return the FollowupAction event in the list of the custom action mentioned just above.
If you have your own frontend interface, you can even disable the text input when buttons are present to make sure the users will press the buttons and thus control their behavior.
I have done these in my project if you want something to look at (even though building your own project may be easier than understanding someone else’s )
Nik’s approach is perfectly fine and easier though I just feel this solution is cleaner and more scalable, even though harder to understand and set up. It all comes down to preferences!