Interact with the deployed bot (on k3s using quick install script) using custom connectors

Hi @gaushh, When deploying on kubernetes, this is how I always do it for deploying custom channels & components.

I create a custom docker image of rasa that includes my custom channel as an installed python package, using these steps:

Create this folder structure with files whose content is described below:

|-custom_channels
| |channel.py
| |__init__.py
|
|setup.py
|Dockerfile

The folder custom_channels is just your code, with folder structure of a python package.

The file setup.py , is a minimalistic setup file to install the package.

Content of setup.py is something like this:

"""A setuptools based setup module.

See:
https://packaging.python.org/guides/distributing-packages-using-setuptools/
https://github.com/pypa/sampleproject
"""
from setuptools import setup, find_packages

setup(
    name='custom-channels',
    version='0.0.1',
    url='',
    author='',
    author_email='',
    description='Custom Channels for Rasa',
    packages=find_packages(),
    install_requires=[],
)

During development of your channel, it is useful to just install it inside your python environment, like a conda environment, in editable mode, using this command:

pip install -e .

And then in your bot, use a credentials.yml as defined below.

Once ready to deploy, the file Dockerfile is used to build the custom docker image of Rasa with your custom channel included:

#
# Notes:
# (-) See https://github.com/RasaHQ/rasa/blob/master/docker/Dockerfile_full
#
FROM rasa/rasa:1.10.16-full

##################################################
# Install the custom channel as a python package #
##################################################

USER root

# change working directory
WORKDIR /build-custom

# copy files
COPY custom_channels /build-custom/custom_channels
COPY setup.py /build-custom

# install custom channels
RUN pip install --upgrade pip
RUN python -m pip install .

# cleanup
RUN rm -rf /build-custom

##################################  
# change user to not run as root #
##################################
WORKDIR /app
USER 1001

Once you have this in place, you Build the docker image with:

sudo docker build . --no-cache --file Dockerfile -t custom-rasa:0.0.1

You then push this custom rasa image to your docker registry, and use it to deploy in your k3s cluster.

Note that an alternative to k3s is microk8s, which has a build in container registry. If you use microk8s, your workflow will become a bit easier, because you can just build the docker image on your computer or VM and push it directly into the cluster, without going through an external docker registry.

To deploy this custom rasa container in the cluster, I prefer to deploy using a helm-chart, as described here.

For the Rasa Open Source Version, you add this in the values.yml:

# rasa: Settings common for all Rasa containers
rasa:
    # https://rasa.com/docs/rasa/user-guide/connectors/custom-connectors/#id1
    # name of the Custom Rasa image to use
    # Prefix it with the docker-registry you use
    name: "<DOCKER-REGISTRY>/custom-rasa"
    # tag refers to the Custom Rasa image tag
    tag: "0.0.1"
    # additionalChannelCredentials which should be used by Rasa to connect to various
    # input channels
    additionalChannelCredentials:
      # Custom Connector
      # (-) use `custom_channels`, because the package directory name is `custom_channels`
      # (-) use `channel`, because the python module is called `channel.py`
      # (-) use `RestInput1`, because your class is called `RestInput1`
      rest:
      custom_channels.channel.RestInput1:
        # you don't need to provide anything here - this channel doesn't
        # require any credentials

You Talk to your bot with:

# replace `my_custom_rest_channel` with the name you return from the name() method of your class `RestInput1` in your python file `channel.py`
curl http://HOST:PORT/webhooks/my_custom_rest_channel/

I think that summarizes it. I hope this information helps you get it going.

The nice thing about this approach is that you can de-couple the custom channel development from your bots. You develop & maintain your custom channel code in one repository, and just install it or deploy it with your Rasa X as a custom Rasa container.

Then, you can use it with every bot you create, without having to copy a duplicate of the channel.py into every bot repository.

2 Likes