# Newbie seeks pointers on quick state machine setup

**URL:** <https://forum.rasa.com/t/newbie-seeks-pointers-on-quick-state-machine-setup/48116>\
**Category:** Rasa Open Source\
**Created:** [September 30, 2021, 4:19am UTC](https://forum.rasa.com/t/newbie-seeks-pointers-on-quick-state-machine-setup/48116 "2021-09-30T04:19:53Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [September 30, 2021, 7:22pm UTC](https://forum.rasa.com/t/newbie-seeks-pointers-on-quick-state-machine-setup/48116/9 "2021-09-30T19:22:16Z")

</div>

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](https://rasa.com/docs/rasa/forms) with [buttons](https://rasa.com/docs/rasa/responses#buttons) on each question.

Every button will have the same payload [intent](https://rasa.com/docs/rasa/glossary#intent), but different [entities](https://rasa.com/docs/rasa/training-data-format#entities).

```auto
'/inform{{"pizza":"cheese"}}'
'/inform{{"delivered":"no"}}'
'/inform{{"time":"8pm"}}'

```

The entity values specified in the payload will be saved in a [slot](https://rasa.com/docs/rasa/domain#slots) 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](https://rasa.com/docs/rasa/forms#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](https://rasa.com/docs/rasa/rules) and/or [story](https://rasa.com/docs/rasa/stories), you can specify to [deactivate the form](https://rasa.com/docs/rasa/forms#deactivating-a-form) by [handling an unhappy path](https://rasa.com/docs/rasa/forms#writing-stories--rules-for-unhappy-form-paths) and execute a certain action if that intent was detected.

```auto
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](https://rasa.com/docs/action-server/sdk-actions) that will reset all the slots.

```auto
- 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](https://rasa.com/docs/action-server/sdk-events#slotset) [events](https://rasa.com/docs/action-server/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](https://rasa.com/docs/action-server/sdk-events#allslotsreset) event.

```python
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](https://rasa.com/docs/action-server/sdk-events#followupaction) event in the list of the custom action mentioned just above.

If you have your own [frontend interface](http://forum.rasa.com/t/rasa-gui-integration/47416/3), 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](https://github.com/ChrisRahme/fyp-chatbot) 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!

---

_[View the full topic](https://forum.rasa.com/t/newbie-seeks-pointers-on-quick-state-machine-setup/48116)._
