How to Create a Chatbot on IBM Cloud and Integrate with Slack: Part 3

2 min read

Part 3 of a four-part series. In this post, we are going to create a process flow in Node-RED and integrate with Watson Assistant Q&A.

How to Create a Chatbot on IBM Cloud and Integrate with Slack: Part 3

Step 1. Launch Node-RED

  1. Open your Node-RED app on the IBM Cloud dashboard and click Visit URL.
  2. Initially, it will show setup screens. Set up your user name and password, if necessary.
    Initially, it will show setup screens. Set up your user name and password, if necessary.
  3. Click Go to your Node-RED flow editor.
    Click Go to your Node-RED flow editor.

Step 2. Connect to Watson Assistant

Let's try connecting to your Watson Assistant (see Part 2 of this series: "Configure Watson Assistant to process simple Q&A.")

  1. Expand the top right menu and click Import.
    Expand the top right menu and click Import.
  2. Copy and paste the contents of the following text file and click Importnode_red_watson_test.txt 
    Copy and paste the contents of the following text file and click Import.
  3. Let's get the credentials of Watson Assistant. Open the service and the assistant you created.
  4. From the top right menu, click on Settings.
  5. Open API Details and get your Assistant ID and Api Key.
    Open API Details and get your Assistant ID and Api Key.
  6. Enter the ID and key in the assistant V2 node and click Deploy. You can leave Username and Password blank.
    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. 

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 Watson 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

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.

/talk flow:

  1. /talk is called and it accepts user input.
  2. See if the session already started or not.
  3. Pass the user input to Watson.
  4. Set session ID to continue the conversation with Watson.
  5. Respond.

/clear flow: 

  1. /clear is called by an user.
  2. 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 Watson 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. 

Be the first to hear about news, product updates, and innovation from IBM Cloud