Rasa chatbot with two-way integration
This is an example how to set your Rasa chatbot up to be able to trigger the execution of Robocorp digital workers, and how the robot is able to return it's results back to the conversation.
Chatbots and automation workflows are a great match creating great business outcomes together. Robots extend the capabilities of conversational user interface to be able to perform tasks with legacy systems that lack simple API connectivity.
This is an example how to set your Rasa chatbot up to be able to trigger the execution of Robocorp digital workers (aka robots) through Control Room, and how the robot is able to return it's results back to the conversation.
Check out the video for a quick overview.
The example chatbot can have a simple conversation and fetch the current time in difference cities around the world. Like this:
Bot: Hi, how are you?
Me: What time is it in Lisbon?
Bot: Wait a sec I'll get it. (starts a robot execution)
Bot: Time in Lisbon is 11:35! (Response from the robot)
The reference architecture uses Rasa's default chat interfance channel, and takes you through creating chat intents, custom actions and setting up the communications between Rasa and Robocorp.
Triggering the robot execution
Declare the custom action(s) in domain.yml, like this:
Also remember to make sure that you have necessary configuration for intents, stories and nlu that will trigger the action. We will not cover the setup of these in details in this example, please look for help from Rasa documentation. The code in this repo contains all you need to try out.
Set up the relevant robots
Once you have your robot and process set up in Robocorp Control Room, the easiest way to get the workspace ID, process ID and API key that are required for triggering the Process is throught the API Helper.
IMPORTANT: Copy your Control Room API key, Workspace ID and Process ID to the settings.py_EXAMPLE file, and rename so that the file name is just settings.py.
Returning the results of the robot execution to the conversation
As the robot execution might take some time depending on the types of tasks it's performing, it would be considered a best practise to let user know that the execution is started and the results will come back later.
Setting this up requires the use of external events, which on the Rasa configuration are also actions. The documentation and reminderbot example are really good sources to get this done. We are using a rule, intent and an action like this in our example:
You will also need to declare the entities that the robot is returning to the conversation in domain.yml, for example like this:
Accordingly, the robot will then send back an HTTP POST call to trigger the given intent that has a payload like this:
Running the example
As a prerequisite, you will need these things installed in your environment:
- Download the English language pipeline with
python -m spacy download en_core_web_md
- Set up the corresponding Robocorp process first
- http-server which is used to host the chat UI (optional)
To run the example chatbot, perform these actions on three different terminal tabs.
On any terminal, train Rasa language model:
On the first terminal tab, start the custom action server:
On the second tab, start the Rasa chatbot server:
On the third tab start the http-server that will provide the chat UI. This needs to happen in the root of the repository where the index.html is located.
The chatbot is now available on http://127.0.0.1:8080. Have fun chatting! If you got it all right, you can ask for example "What time is it in Helsinki?", and the execution is handed over to your digital worker!