Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
images
README.md
skill-claim.json

README.md

chatbot

Node-RED Watson Assistant Demo

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.

image

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.

Prerequisites

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).

Watson Assistant Service

The Watson Assistant service is an artificial intelligence service within the IBM Cloud and can be found the AI category of the catalog.

Installation

  • 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

WA service

The service is now running and can be used.

  • make note of the API key and the URL

WA service details

  • 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

Accessing the WA service

The Watson Assistant service can be accessed on various ways:

  • SDKs (Go, Java, Node, Python, Ruby, Swift)
  • Node-RED
  • REST/curl

Access via REST APIs/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"

Chatbot Platforms

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.

Using Programmatic Calls

Programmatic calls can be used to create/update/read/delete real-time data from backend systems, see example.

Install the Node-RED Starter Kit

  • 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

Node-RED running

  • 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

Select Manage Palette

  • now choose the tab install, search for Node-RED Dashboard (node-red-dashboard) and press install

Node-RED install nodes

Now you can import and deploy the sample flow

Node-RED import

  • the sample code is now imported into several Node-RED flow which can be selected by clicking of the tabs

Using the Dashboard

The dashboard nodes imported above are used to access the user interface.

Accessing the Dashboard

  • you can go to the UI (dashboard) if you click on Dashboard

Go to Dashboard

and then on the little arrow

Dashboard arrow

Designing the Dashboard

Lots of tutorials are available, just search for Dashboard Node-RED, or see https://www.youtube.com/watch?v=X8ustpkAJ-U , for example.

Hello World

debug messages

  • 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

hello world

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.

Calling the Watson Assistant from Node-RED

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

Making HTTP Requests

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.

  • go to flow 9. useCreditpaas Api sample (Hacknext) Post Request

Another option would be an integration with a calendar service.

  • click on the http POST request node and then on the little i (information) Post Request

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).

Provide a REST API

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)

Simple forwarding server

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.

You can’t perform that action at this time.