You can implement your own custom channel connector as a python class. You can
rasa.core.channels.rest.RestInput class as a template.
A custom connector class must subclass
and implement at least a
name method defines the url prefix for the connector's webhook. It also defines the channel name you should use
in any channel specific response variations and the name you
should pass to the
output_channel query parameter on the trigger intent endpoint.
For example, if your custom channel is named
myio, you would define the
name method as:
You would write a response variation specific to the
myio channel as:
The webhook you give to the custom channel to call would be
the host and port with the appropriate values from your running Rasa server.
needs to create a sanic blueprint
that can be attached to a sanic server.
Your blueprint should have at least the two routes:
health on the route
receive on the route
/webhook (see example custom channel below).
As part of your implementation of the
receive endpoint, you will need to tell
Rasa to handle the user message. You do this by calling
on_new_message will send the user message to the
See more details on the
UserMessage object here.
output_channel argument refers to an output channel implementing the
OutputChannel class. You can
either implement your own output channel class with the methods for your particular chat channel
(e.g. methods to send text and images) or you can use the
to collect the bot responses Rasa creates while the bot is processing your messages and return
them as part of your endpoint response. This is the way the
channel is implemented. For examples on how to create and use your own output
channel, take a look at the implementations of the other
output channels, e.g. the
Here is a simplified example of a custom channel connector that makes use of the
Metadata on messages
If you need to use extra information from your front end in your custom
actions, you can pass this information using the
metadata key of your user
message. This information will accompany the user message through the Rasa
server into the action server when applicable, where you can find it stored in
tracker. Message metadata will not directly affect NLU classification
or action prediction.
InputChannel class's default implementation of
get_metadata ignores all metadata.
To extract metadata in a custom connector, implement the
SlackInput channel provides one example of a
get_metadata method that extracts metadata according to the channel's response format.
Credentials for Custom Channels
To use a custom channel, you need to supply credentials for it in a credentials configuration file
This credentials file has to contain the module path (not the channel name) of your custom channel and
any required configuration parameters.
For example, for a custom connector class called
MyIO saved in a file
the module path would be
addons.custom_channel.MyIO, and the credentials could look like:
To make the Rasa
server aware of your custom channel, specify the path to
credentials.yml to the Rasa server at startup with the command line argument
Testing the Custom Connector Webhook
To test your custom connector, you can
POST messages to the webhook using a json body with the following format:
For a locally running Rasa server, the curl request would look like this: