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 :
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)
Do all custom connector related configuration in credentials.yml file
a. MyIo is the script name i.e MyIo.py
b. RestInput is the class name inside MyIo.py script file.
Run your custom action server with the usual command:
python -m rasa_sdk --actions actions
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
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
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.
Thanks Prashant for sharing valuable information.I will try and let you know. In case of any queries or doubts.
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.
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?
You will need to add one environment variable and set path of your project into that variable.
PYTHONPATH=“path to your custom connector file”.
Afte that you can check out and let me know if it solved your issue pal
This is so great, thank you so much!
One question: where do you put the webhook url? In the credentials file? Endpoints?
Aaah ok! Thank you
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.
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)
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.
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
zmq_server.py (351 Bytes)
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?
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:
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?
Have you set path variable i.e PYTHONPATH to your custom connector file??
you mean the environment variable PATH? Yes I did set it to the folder.
Okay. Just let me think what is going.