[Solved] How to implement our own custom connector for the custom UI

Hi All,

I was facing issues while creating custom connector for my customized ui as well as whole functionality. But after countable amount of efforts and time I managed to implement custom connector using RestInput class template from rasa docs Custom Connectors

Below are the steps that I followed :

  1. Create python script file and copy paste RestInput template code and fix all imports.

    Below is my custom connector file :

    MyIo.py (4.4 KB)

  2. Do all custom connector related configuration in credentials.yml file

    MyIo.RestInput:

    a. MyIo is the script name i.e MyIo.py

    b. RestInput is the class name inside MyIo.py script file.

  3. Run your custom action server with the usual command:

    i.e python -m rasa_sdk --actions actions

  4. Run your rasa server using following command :

    To start rasa server with cross origin access use below command:

    rasa run -m models --enable-api --cors "*"

    with debug mode

    rasa run -m models --enable-api --cors "*" --debug

  5. Also set environment variable path for your custom connector file like below

    PYTHONPATH=“path to your custom connector file”

Note : Your webhook url will be as per the below format

http://localhost:5005/webhooks/myio/webhook

In above url myio is the name of component that we are returning from name method inside of our custom connector class i.e RestInput.

After completing you can connect it with any front-end or just test it with postman rest api testing tool.

8 Likes

HI Prashant,

Thanks Prashant for sharing valuable information.I will try and let you know. In case of any queries or doubts.

Regards,

Vikhil

Hi With out implemnting custom connector, i can test rasa using postman using url=http://localhost:5005/webhooks/rest/webhook. is there any default implementation

Yeah yeah @selvamsandeep you can test it without using custom connector.

you just need to specify rest: in your credentials.yml file that’s it. :slightly_smiling_face:

1 Like

Hi @prashant_kamble, I am trying to do the same steps, but always got the error ‘Module MyIo not found’. Can you share please the project structure or guide me, please, where to put that custom connector file?

Hi @dmlapteacru,

You will need to add one environment variable and set path of your project into that variable.

for e.g

PYTHONPATH=“path to your custom connector file”.

Afte that you can check out and let me know if it solved your issue pal :slightly_smiling_face:

1 Like

This is so great, thank you so much!

One question: where do you put the webhook url? In the credentials file? Endpoints?

Thank you!

Hi @ellav,

I am happy that it helped you :slightly_smiling_face:. If you are using custom front end with custom connector, you will need to put webhook url in front end javascript file where you will be making ajax requests to the bot.

Aaah ok! Thank you :slight_smile: I am making an application for a small robot to work via voice (so with ASR and TTS), so I probably need to add the webhook url to the MQ part.

You are very welcome :blush:

I am not clear about MQ part, but you can try.

Is there a way to do this without the POST request webhook thingy? I have my own connector file running now (I’ll attach it), and we want to just run it when asr receives something (which is dealt with in the zmq server side) and gives back a json file to te get_text() function with the client side of zmq, which extracts the text.

connector.py (3.1 KB)

Hi @ellav,

Can you little elaborate on asr and zmq server terminologies. You are recieving something using asr but what it is can you explain based on that I can suggest you.

Of course. So, ZMQ is the message queueing part, where it has a server side, where it receives the text in a JSON file, which is the output of the Automatic Speech Recognition (ASR). The text is what the user said. The client side of ZMQ is in the connector file, which asks for input of the server side, and the server side hands the asr output to the client side. The client side then extracts the text message from the JSON file. Does this make things more clear? I added the zmq server side, with the text for now just set (so no ASR).

Thanks for helping :slight_smile:

zmq_server.py (351 Bytes)

Hi ella,

Currently how is your flow exactly working. Means from any other fron-end are you making post requests so the bot could get user messages. connector part will be backend processing right? that’s what I understood. But you are telling that client side of ZMQ is in the connector file I am not clear on that a little bit.

I will tell you my understanding,

Actually at client side ASR is working and it is taking voice from user and zmq is used for that textual messages from asr.And ZMQ has user text messages and you want to take messages from zmq and make request to your custom connector and take bot response.

Please correct me if I am wrong? :blush:

Hi Prashant,

I am new to Rasa and this post really did help me. Thank you very much for this short tutorial. I followed all the steps but the last one gets this error: “AssertionError: A blueprint with the name “custom_webhook_RestInput” is already registered. Blueprint names must be unique.” When I change the name of the blueprint, I get another error: “sanic.router.RouteExists: Route already registered: /webhooks/rest/ [GET]” I have no idea what this means and I never saw anything similar in the forum. I wrote a file channel.py, copied your MyIo.py and editied the credentials.yml like this: rest:

channel.RestInput: username: “user_name” another_parameter: “some value”

I ran my action and Rasa servers with the commands you suggested. Can you or anybody else please tell me what I am missing?

Hi Eva,

Have you set path variable i.e PYTHONPATH to your custom connector file??

Hi Prashant,

you mean the environment variable PATH? Yes I did set it to the folder.

Okay. Just let me think what is going. :blush: