notice
This is unreleased documentation for Rasa Documentation Main/Unreleased version.
For the latest released documentation, see the latest version (3.x).
Sanic Extensions
New in 3.6
You can now extend Sanic features such as middlewares, listeners, background tasks and additional routes.
You can now create additional Sanic extensions by accessing the app object created by the action server. The hook implemented
in the plugin package provides you access to the Sanic app object created by rasa-sdk
when starting the action server.
Step-by-step guide on creating your own Sanic extension in rasa_sdk
This example will show you how to create a Sanic listener using plugins.
Create the rasa_sdk_plugins package
Create a package in your action server project which you must name rasa_sdk_plugins
. Rasa SDK will try to instantiate this package in your project to start plugins.
If no plugins are found, it will print a debug log that there are no plugins in your project.
Register modules containing the hooks
Create the package rasa_sdk_plugins
and initialize the hooks by creating an __init__.py
file where the plugin manager will look for the module where the hooks are implemented:
Implement your hook
Implement the hook attach_sanic_app_extensions
. This hook forwards the app object created by Sanic in the rasa_sdk
and allows you to create additional routes, middlewares, listeners and background tasks. Here's an example of this implementation that creates a listener.
In your rasa_sdk_plugins.your_module.py
: