notice
This is documentation for Rasa Action Server Documentation v2.x, which is no longer actively maintained.
For up-to-date documentation, see the latest version (3.x).
Actions
The Action
class is the base class for any custom action. To
define a custom action, create a subclass of the Action
class
and overwrite the two required methods, name
and run
. The
action server will call an action according to the return value
of its name
method when it receives a request to run an action.
A skeleton custom action looks like this:
Methods
Action.name
Defines the action's name. The name returned by this method is the one used in your bot's domain.
Returns:
Name of action
Return type:
str
Action.run
The run
method executes the side effects of the action.
Parameters
dispatcher – the dispatcher which is used to send messages back to the user. Use
dispatcher.utter_message()
or any otherrasa_sdk.executor.CollectingDispatcher
method. See the documentation for the dispatchertracker – the state tracker for the current user. You can access slot values using
tracker.get_slot(slot_name)
, the most recent user message istracker.latest_message.text
and any otherrasa_sdk.Tracker
property. See the documentation for the tracker.domain – the bot's domain
Returns
A list of rasa_sdk.events.Event
instances. See the documentation for events.
Return type
List
[Dict
[str
, Any
]]
Example
In a restaurant bot, if the user says “show me a Mexican restaurant”,
your bot could execute the action ActionCheckRestaurants
,
which might look like this:
This action queries a database to find restaurants matching
the requested cuisine, and uses the list of restaurants found
to set the value of the matches
slot.