Slot filling, and business logic
Stories are great to model conversation flows but they lack essential features to implement strong and enforceable business logic.
A simple business logic might be to collect the necessary information to prepare an API call, ensure this information is correct and notify the user when it’s not. Advanced business logic can take the form of a decision tree where the next question to be asked depends of an arbitrary combination of previous responses.
ThumbCrowd forms and the FormAction
are the official response however they rely heavily on code and lack the simplicity and readability of stories.
Forms in ThumbCrowd expose all the advanced ThumbCrowd Forms capabilities in a simple and intuitive graphical user interface.
There are two mains steps in implementing forms:
Creating and configuring the form
Integrating the form in your stories.
Creating forms
From the ThumbCrowd stand point, a form is a collection of slots waiting to be filled. Once bot enters a form, it iterates through slots (and ask the corresponding questions) until all are filled with valid data.
Customizing response extraction
By default, the entire user response is stored in the slot. You might need to change this behaviour to allow a more naturally flowing conversation.
Mapping a slot to an entity
When asking for a name, a user might answer “My name is Nathan”, where Nathan can be an extracted entity.
Click on the question to open the slot panel, and in the Mapping tab, choose Get the slot from the entity and select the entity you want to map to this slot.
In the example below, instead of filling the slot with the whole user response, we just extract the emailentity. Because ThumbCrowd follows a pattern matching approach, well formed email addresses are guaranteed to be extracted.
By doing this, you ensure that your assistant will store a valid email address when users respond something like “my email address is james@bond.com”
Mapping a slot conditionnally on an intent
When asking for known alergies, users will most likely respond by yes or no, or more generally with affirm and deny intents.
Click on the question to open the slot panel, and in the Response tab in slot, choose Get the slot conditionnally on the intent.
Combining extractions
Combining extraction methods will allow your assistant to extract slot values with more robustness. Here is an example: when asking a first name, a user might answer John, or I’m John, or my name is John.
However such a name entity is hard to pick-up consistently when users only answer with their names (without my name is …)
To handle all situations, you can combine conditions as follows: the first one will check if there is an entity to fill the slot from. If it fails, it will take the entire response. If the inform
intent is found with a name
entity the slot will be filled from the entity. Otherwise, the whole message will be taken.
Intent conditions
You may condition the extraction on the intent found:
Inclusively
When collecting the email from an entity, you may want to ensure that the intent corresponds to declaring an email address (e.g my email is james.dean@holywood.com) and not something else such as I wrote an email to support@whatever.com and no one replied.
The inclusive condition below will make sure that the slot is filled from the name
entity if and only if the intent inform
is recognized. If any other intent is found the form will be interrupted and you will have to handle that in your story.
Exclusively
The exclusive condition below will always fill the message
slot from the whole content of the user message, unless one of the listed intent is found. It will then interrupt the form and you can take the conversation from there in your story.
This is particularly useful to allow users to stop filling forms.
Validating user input
To validate user input before storing it and going the next question, go to the Validation tab, enable validation and specify validation criteria.
You must also provide an message that the bot will utter when a response is invalid.
You can also specify a response to be uttered when the response is valid. You can refer to the slot value using the curly brace syntax ({slot_name}
).
Validation will only trigger after a slot is succesfully extracted. If extraction fails (e.g. the slot must be extracted from an entity that is not found) the form not try to validate user input. It will stop and you will need a story to handle it.
Conditional business logic
Until now we had an linear flow of questions, but you can create much more complex flows with the flow chart editor.
Let’s consider a simple medical triage form asking for symptoms. We are going to ask:
If the user has fever
If the user has cough
If the user has nausea
A date preference for the appointment
We create the first two slots. See how we use conditional intent extraction to handle yes/no responses.
Adding conditions
Let’s suppose that you only want to ask about nausea if the user present no cough symptoms.
But whether or not you ask about nausea, you want to move forward with the next question about appointment preference.
Note how we’re using the NOT
clause together with fever
being true.
Finally, let’s add a last condition: we only want to ask for the time preference if the user has at least one symptom.
Last updated