Before you start
Put your code in a package next toagent.yml: a folder named addons/ with an
empty __init__.py file. Start rasa from the project root so the package can
be imported.
Subclass InputChannel
Import InputChannel, CollectingOutputChannel, and the other types from
rasa.api.channels.v1. Implement name, connect, and blueprint.
blueprint returns a Sanic Blueprint, which holds the routes your channel
serves. Each incoming message goes to the agent through on_new_message.
addons/custom_channel.py
CollectingOutputChannel for that, which is a built-in output channel. If your
service needs replies pushed to it instead, subclass OutputChannel and implement
send_text_message. Then pass that output channel in UserMessage.
The example checks a bearer token on each request. Reject requests that do not
carry it, as this one does, so anyone who knows the URL cannot send messages.
Register the class under channels, using its module path as the key. The values
under it arrive in connect as settings.params:
integrations.yml
/webhooks/<name>/, where
<name> is the value name() returns. With the example above, the endpoint is
POST /webhooks/my_channel/webhook.
Subclass a built-in connector
To change one part of a built-in connector and keep the rest, subclass it fromrasa.api.channels.v1.twilio. This example tags each message with the Twilio
number it arrived on, which helps when one agent serves several numbers:
addons/custom_twilio.py
integrations.yml
webhook_url is the public URL Twilio posts to. The signature check uses it, so
it must match the URL in your Twilio console. The check itself is inherited
unchanged. The keys are the ones the built-in Twilio connector reads. See
channels for the rules on each channel
entry.
Versioning
The importrasa.api.channels.v1 is the version. YAML names only the class. See
Custom integrations: Versioning.