The goal of this demo is to build a chatbot with IBM Watson Assistant and Node-RED. Node-RED is a visual programming and internet wiring tool which is quite useful for hackathons and prototypes. It connects all the devices with the cloud services, backend systems and external services. The figure shows a sample architecture.
This demo guide is based on a tutorial by Thomas Suedbroecker (@tsuedbroecker), which also contains some videos.
Hope you find this useful and have fun trying it out. Feedback including issues and contributions is certainly welcome.
You need an IBM Cloud account. Please sign-up for the IBM Cloud, if not done already. If you are attending a hackathon you might get a special registration URL, e.g. http://ibm.biz/promo4yourhackathon (just an example, this link does not work).
The Watson Assistant service is an artificial intelligence service within the IBM Cloud and can be found the AI category of the catalog.
- go to the Catalog, under All Categories on the left click on AI
- click on Watson Assistant and choose a region, e.g. Frankfurt
- click on Create, the click on the alias
- bookmark this page
The service is now running and can be used.
- make note of the API key and the URL
- click on Launch tool and on Skills (in the top menu)
We are using a pre-installed skill that we can modify.
- click on the 3 dots of the pre-installed Customer Care Sample Skill
- click on View API details and make note of the workspace ID, the username (apikey) and the password (the 1st one)
- close the API details view and open the Customer Care Sample Skill by clicking on the center of the tile Now you can see the tabs where you can modify the skill, primarily the intents, entities amnd the dialog.
- click on Try it at the upper right corner and enter hello
The Watson Assistant service can be accessed on various ways:
- SDKs (Go, Java, Node, Python, Ruby, Swift)
- Node-RED
- REST/curl
This interface is documented in the API reference. Note, that the API endpoint (gateway-fra.watsonplatform.net) depends on the region.
Example:
curl -X POST -u "apikey:mkRm0xVF.........Edbxde0ua" --header "Content-Type:application/json" --data "{\"input\": {\"text\": \"Hello\"}}" "https://gateway-fra.watsonplatform.net/assistant/api/v1/workspaces/c321c0......eae0eb10d/message?version=2019-02-28"
Chatbots can be used in a variety of use cases and the Watson Assistant services is the perfect tool to create them as described in this demo and these instructions for developers. Messenger and Slack can be connected directly to an Assistant of the Watson Assistant Service :
- go to https://cloud.ibm.com/resources and search for your Watson Assistant service
- go to the service overview, click on Launch tool
- under the tab Assistants click on Create assistant and follow the instructions
Other platforms like Telegram, Alexa, Skype etc. need an additional component (e.g. Node-RED, Cloud Functions, Node.js) to connect to the Watson Assistant service.
Programmatic calls can be used to create/update/read/delete real-time data from backend systems, see example.
- go to the Catalog and search for Node-RED Starter or directly to Create a Cloud Foundry App/Node-RED Starter
- enter a unique App name, e.g. myuniqueapp...
- choose a region, organization, and a space or use the defaults
- click on Create, the app is now starting
- click on Visit App URL
- click Next
- enter a Node-RED Username and Password and click Next twice, then click Finish
- click on Go to your Node-RED flow editor and login
You have to add the Node-RED Dashboard (UI nodes) before you import the sample flow.
- select manage palatte from the menu on right upper side of the page
- now choose the tab install, search for Node-RED Dashboard (node-red-dashboard) and press install
Now you can import and deploy the sample flow
- import this Node-RED flow via the clipboard
- the sample code is now imported into several Node-RED flow which can be selected by clicking of the tabs
The dashboard nodes imported above are used to access the user interface.
- you can go to the UI (dashboard) if you click on Dashboard
and then on the little arrow
Lots of tutorials are available, just search for Dashboard Node-RED, or see https://www.youtube.com/watch?v=X8ustpkAJ-U , for example.
- go to flow 1. Basics and click on the red Deploy button to deploy and run all flows (click Confirm deploy and Close)
- enable the debug messages in the right sidebar
- now click on the button of the Hello World inject node
This way a message is generated (in attribute payload of the message), transferred to the green debug node, that displays it in the right sidebar.
The tab 2. Assistant is a simple flow calling the Watson Assistant service.
- click on the blue Watson Assistant node and enter user name apikey, password, API Key, URL and workspace ID gathered above and then click the Deploy button
- click in the debug icon the upper right corner to see the output of the Watason Assistant node
- click on the Inject node ("I want to make a appointment") , you should see the response of the Watson Assistant service ("What day would you like to come in?") in the right sidebar
With http requests you can send/receive data to/from external services. There's a sample POST request (to a bank) as a starting point.
Another option would be an integration with a calendar service.
Here you can see a description of the node. The body (payload) and headers of the request are set in the function node "build the request". To invoke the request, click on Inject (the output of that node is not used).
The Node-RED instance is reachable via REST APIs. The http in node is used to define the endpoint (route, method), see also https://cookbook.nodered.org/http/post-form-data-to-a-flow.
You can find an example if you
- go to flow 8. PROVIDE REST API (Basic)
In case of CORS problems using Node-RED as REST server, a simple REST forwarding server based on Node.js, which is CORS enabled, might help, see https://github.com/gitjps/hackathons_and_node-red/tree/master/simple_forward_server. A simple web app can be used to check this.













