rasa.core.actions.forms
FormAction Objects
Action which implements and executes the form logic.
__init__
Creates a FormAction
.
Arguments:
form_name
- Name of the form.action_endpoint
- Endpoint to execute custom actions.
name
Return the form name.
required_slots
A list of required slots that the form has to fill.
Returns:
A list of slot names.
from_entity
A dictionary for slot mapping to extract slot value.
From:
- an extracted entity
- conditioned on
- intent if it is not None
- not_intent if it is not None, meaning user intent should not be this intent
- role if it is not None
- group if it is not None
get_mappings_for_slot
Get mappings for requested slot.
If None, map requested slot to an entity with the same name
entity_mapping_is_unique
Verifies if the from_entity mapping is unique.
get_entity_value_for_slot
Extract entities for given name and optional role and group.
Arguments:
name
- entity type (name) of interesttracker
- the trackerslot_to_be_filled
- Slot which is supposed to be filled by this entity.role
- optional entity role of interestgroup
- optional entity group of interest
Returns:
Value of entity.
get_slot_to_fill
Gets the name of the slot which should be filled next.
When switching to another form, the requested slot setting is still from the previous form and must be ignored.
Returns:
The slot name or None
validate_slots
Validate the extracted slots.
If a custom action is available for validating the slots, we call it to validate them. Otherwise there is no validation.
Arguments:
slot_candidates
- Extracted slots which are candidates to fill the slots required by the form.tracker
- The current conversation tracker.domain
- The current model domain.output_channel
- The output channel which can be used to send messages to the user.nlg
-NaturalLanguageGenerator
to use for response generation.
Returns:
The validation events including potential bot messages and SlotSet
events
for the validated slots, if the custom form validation action is present in
domain actions.
Otherwise, returns empty list since the extracted slots already have
corresponding SlotSet
events in the tracker.
validate
Extract and validate value of requested slot and other slots.
Returns:
The new validation events created by the custom form validation action
Raises:
ActionExecutionRejection exception to reject execution of form action if nothing was extracted.
Subclass this method to add custom validation and rejection logic.
request_next_slot
Request the next slot and response if needed, else return None
.
activate
Activate form if the form is called for the first time.
If activating, run action_extract_slots to fill slots with
mapping conditions from trigger intents.
Validate any required slots that can be filled, and return any SlotSet
events from the extraction and validation of these pre-filled slots.
Arguments:
output_channel
- The output channel which can be used to send messages to the user.nlg
-NaturalLanguageGenerator
to use for response generation.tracker
- Current conversation tracker of the user.domain
- Current model domain.
Returns:
Events from the activation.
do
Executes form loop after activation.
is_done
Checks if loop can be terminated.
deactivate
Deactivates form.