Part 3 of a four-part series. In this post, we are going to create a process flow in Node-RED and integrate with watsonx Assistant Q&A.
- Part 1: Set up required apps and services.
- Part 2: Configure watsonx Assistant to process simple Q&A.
- Part 3: Create a simple flow on Node-RED and integrate with watsonx Assistant.
- Part 4: Configure Slack and Node-RED integration.
Step 1. Launch Node-RED
- Open your Node-RED app on the IBM Cloud dashboard and click Visit URL.
- Initially, it will show setup screens. Set up your user name and password, if necessary.
- Click Go to your Node-RED flow editor.
Step 2. Connect to watsonx Assistant
Let’s try connecting to your watsonx Assistant (see Part 2 of this series: “Configure watsonx Assistant to process simple Q&A.”)
- Expand the top right menu and click Import.
- Copy and paste the contents of the following text file and click Import: node_red_watson_test.txt
- Let’s get the credentials of watsonx Assistant. Open the service and the assistant you created.
- From the top right menu, click on Settings.
- Open API Details and get your Assistant ID and Api Key.
- Enter the ID and key in the assistant V2 node and click Deploy. You can leave Username and Password blank.
Let’s see if it can connect. Click inject, which sends an empty string. If it goes successfully, a response from your assistant will be shown in the right debug tab.
Step 3. Understand the flow
Now, we are going to create an http endpoint in Node-RED so that external applications can connect to the watsonx Assistant. When you import the json below using the same steps, you will have the following flows. Make sure you enter Assistant ID and Api Key again: node_red_watson_bot.txt
/talk flow:
- /talk is called and it accepts user input.
- See if the session already started or not.
- Pass the user input to Watson.
- Set session ID to continue the conversation with Watson.
- Respond.
/clear flow:
- /clear is called by an user.
- Clears the session ID stored.
What’s next?
In the final part of this blog series, we are going to integrate with Slack. However, please note that you can connect to the endpoint we created in this part from any app or service. On top of that, you can customize the flow however you want.
Here are partial examples of how you can expand:
- Modify input from a user using function node
- Modify responses from watsonx Assistant using function node before passing it back to users
- Import other nodes to integrate with other services
- Integrate with other Watson services
- Integrate with OpenWhisk
In fact, Node-RED is essentially a NodeJS application, so you can create a similar or better feature using it.
Disclaimer
IBM is not liable for any damages arising in contract, tort or otherwise from the use of or inability to use this post or any material contained within. All sample code is provided as-is and IBM does not support customization. Do not use the code in production.