Skip to main content
A channel is how the agent receives messages and sends replies. An input channel receives messages from a service over HTTP and passes each one to the agent. The built-in connectors cover Twilio, Slack, Telegram, and others. Write your own when your service’s webhook format is none of those, or subclass a built-in to change one part of it.

Before you start

Put your code in a package next to agent.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
This example replies by returning the messages in the HTTP response. It uses 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
By default, Rasa serves a channel’s routes under /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 from rasa.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 import rasa.api.channels.v1 is the version. YAML names only the class. See Custom integrations: Versioning.