You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Use Node-RED lo-code tool to experiment with Cognitive services**
8
+
9
+
_Ross Cruickshank - Developer Advocate - IBM UK & Ireland_
10
+
_@rcruicks_
11
+
_ross@vnet.ibm.com_
12
+
13
+
14
+
15
+
<divstyle="page-break-after: always;"></div>
7
16
## Get fast usable access to AI services with Node-RED
8
17
9
18
The purpose of this workshop is to give you quick and easy access to the *IBM Watson Cognitive Services* APIs, and allow you to experiment with
@@ -315,7 +324,7 @@ You should see a response like:
315
324
The next Lab will build on your new Node-RED skills to pull in tweets from [Twitter](https://twitter.com), analyze with the Watson AI language services, and generate a dashboard showing trending emotional response.
316
325
317
326
<divstyle="page-break-after: always;"></div>
318
-
### Lab - twitter sentiment
327
+
### Lab - twitter emtional tone
319
328
320
329
This time, you can build a fun, simple application that uses the Watson Tone Analyzer service.
321
330
@@ -359,9 +368,21 @@ All being well, you should see the additonal nodes being dynamically added to th
359
368
You'll find these new nodes towards the bottom of the left-side palette menu.
360
369
361
370
Once more, create a new flow on the canvas with the following nodes:
371
+
362
372

363
373
364
-
For this Lab we will use **#Trump** as the Twitter topic to monitor.
374
+
The first time you use a `twitter` node, the application will need to be authorized to use Twitter (inbound and, optionally, outbound) using your Twitter credentials. This can be very simple if you have used Twitter through the same browser as you're using to access Node-RED:
375
+
376
+
1. in the `twitter` configuration panel, click the edit  icon
377
+
1. when you see following prompt in a new tab or window, click `Click here to authenicate with Twitter`
378
+

379
+
1. you'll be asked to authorise the Node-RED application - click `Authorize app`
380
+

381
+
1. you should receive a message similar to `Authorised - you can close this window and return to Node-RED` -- close the tab or window, and return to the Node-RED editor view
382
+
1. click `Add`
383
+
1. click `Done` and you're good to go with Twitter integration.
384
+
385
+
For this Lab we will use **#Trump trade** as the Twitter topic to monitor.
365
386
366
387
Since this topic is VERY active at the moment, we have to avoid the flood of the incoming tweets overwhelming the Node-RED instance. Add a `delay` node after the `twitter` node and setting the node action to “Limit rate to” 1 message per 1 seconds - this should leave sufficient time for the Watson Tone Analyzer service to handle each request.
367
388
@@ -378,13 +399,13 @@ In a `function` node named “Add tweet scores to total”, the scores can be ac
378
399
```
379
400
var defaultResult = {
380
401
"emotion_tone":{
381
-
"Anger":0,
382
-
"Disgust":0,
383
-
"Joy":0,
384
-
"Sadness":0,
385
-
"Fear":0
402
+
"Anger":0,
403
+
"Disgust":0,
404
+
"Joy":0,
405
+
"Sadness":0,
406
+
"Fear":0
386
407
},
387
-
"count":0
408
+
"count":0
388
409
}
389
410
390
411
if(msg.payload) {
@@ -452,29 +473,35 @@ Make sure the `Legend` option is updated to `Show` so you can distinguish betwee
452
473
453
474
Once you redeploy the application, following the link to the Dashboard
454
475
455
-
and you should see the chart building:
476
+

477
+
478
+
and you should see the chart beginning to build:
456
479
457
480

458
481
459
482
*_Congratulations!_* - you have completed the process of integrating live Twitter with Watson's natural language processing capabilities for identifying emtional tone.
460
483
461
-
The next Lab will extend this to .
484
+
The next Lab will extend this to direct some of the tweets (thos with higher emotional levels - > 0.75, for example) to a chatbot, which will offer responses based on the content of the tweet.
462
485
463
486
<divstyle="page-break-after: always;"></div>
464
487
### Lab - twitter chatbot setup
465
488
466
489
Now, a selection of the tweets can be directed to a chatbot service to trigger a response (based on the Watson Assitant service).
467
490
468
-
Firstly, get hold of an existing Chatbot configuration; for this lab, we will be using one of the many Bot definitions in the [IBM Bot Asset Exchange](https://developer.ibm.com/code/exchanges/bots/?s=jay-z)
491
+
Add the following 4-node flow to the existing Twitter analysis flow:
492
+
493
+

494
+
495
+
Now, get hold of an existing Chatbot configuration; for this lab, we will be using one of the many Bot definitions at the [IBM Bot Asset Exchange](https://developer.ibm.com/code/exchanges/bots/?s=jay-z). Click this link to access the sample Bot.
469
496
470
497
Click the `Get this bot` option and save the resulting JSON string to a local file. This file will be imported into the Watson Assistant tool shortly.
471
498
472
-
This bot responds to queries with the lyrics and wisdom of renowned artists[Jay-Z](https://en.wikipedia.org/wiki/Jay-Z).
499
+
This bot responds to queries/inputs with the lyrics and wisdom of renowned artist[Jay-Z](https://en.wikipedia.org/wiki/Jay-Z).
473
500
474
501
Yo will need to create an instance of the Watson Assistant service in the IBM Cloud catalog -
As before, leave the name to default, create the instance, and then use the `Launch Tool` option to beging creating a Conversation workspace.
504
+
As before when creating services, leave the name to default, create the instance, and when presented with the service overview panels, use the `Launch Tool` option to begin creating a Conversation workspace. The workspace will be populated by importing the earlier JSON file.
@@ -499,24 +526,81 @@ This will create the 3 main areas of chatbot server configuration:
499
526

500
527
501
528
502
-
Using the existing Node-RED flow, select one of the tone category streams from the twitter anlysis [Joy, Anger, Disgust, Sadness, Fear], to direct into the Chatbot, using the Watson Conversation node 
529
+
Using the existing Node-RED flow, select messages with a particularly high emotional count in any of the tone category streams from the twitter analysis [Joy, Anger, Disgust, Sadness, Fear], to direct into the Chatbot, using the Watson Conversation node
You will need the credentials for the Watson Assistant instance, to plug into the node configuration menu. Either:
505
534
+ make a connection between the Watson Assitant instance, and your Node-Red application, and after re-stage, the credentials will automatically populate the Watson Conversation nodes
506
535
+ copy the credentials from the Watson Assitant instance, and apply directly to the node configuration, and use straight away (as you did previously for the Watson Tone Analyzer service)
Click the details menu  and select `View details` to view the `Workspace ID` - copy this into the corresponding field in the Node-RED Conversation node configuration panel.
547
+
Click the details menu  and select `View details` to view the `Workspace ID` - add this into the corresponding field in the Node-RED Conversation node configuration panel.
548
+
516
549

517
550
551
+
The output from the `conversation` is a JSON object in `msg.payload` - to extract the text and display in the debug pane, update the `debug` node to select just that part of the message:
552
+
553
+

554
+
555
+
Configure the `change` node to move the twitter content into the `msg.payload` property:
518
556
557
+

558
+
559
+
Last, but not least, configure the `function` node to select messages based on high emotional tone:
560
+
561
+

562
+
```
563
+
var tones = msg.response.document_tone.tone_categories[0].tones;
564
+
var pass_on = false;
565
+
tones.forEach(function(tone){
566
+
if(tone["score"] > 0.75) {
567
+
pass_on = true;
568
+
}
569
+
});
570
+
if (pass_on) return msg;
571
+
```
572
+
573
+
And finally  !!
574
+
575
+
*_Congratulations!_* - you have completed the process of generating responses to select tweets, using a basic chatbot configuration.
519
576
520
577
<divstyle="page-break-after: always;"></div>
521
578
## Challenge
522
-
## Congrats!
579
+
580
+
Now you have a mechanism for processing web requests, handling real-time events from external services, and invoking Watson cognitive services -- what else other easy extensions could you make?
581
+
582
+
+ check tweets for attached images, and pass the images through the `Watson Visual Recognition` service to identify/classify the image content;
583
+
584
+
+ add `Watson Text to Speech` to enable the application to read messages out loud as they arrive, as well as the responses from the chatbot, using different voices
585
+
586
+
+ use the tweet user information to build a profile using `Personality Insights`, and generate tweets to them when "like-minded" twitter profiles are identified.
587
+
588
+
+ store tweets and responses in data store service (noSQL like Cloudant, or SQL like postgresql/DB2/MySQL/etc)
589
+
590
+
+ take what you've built in the IBM Cloud, and deploy into a Node-RED application on your Windows/Linux/MacOS laptop, or a [Raspberry PI](https://raspberrypi.org)
591
+
592
+
+ ...
593
+
594
+
## Congratulations
595
+
596
+
If you got this far, you will have added some news skills, and hopefully gained some pleasure from using the lo-code environment of Node-RED to explore APIs and services.
597
+
598
+
Capabilities you implemented:
599
+
600
+
+ Live **Node-RED** application deployed to **IBM Cloud Cloud Foundry** environment
601
+
+ application retrieve and reformat data from remote API service (**JSONServer**)
602
+
+ application able to respond to requests for data from browsers or other HTTP requests
603
+
+ integrate with **Twitter** to receive live tweets on particular topics/areas of interest
604
+
+ analyze Tweets for emotional tones using **Watson Tone Analyzer** service
605
+
+ display a dashboard widget charting the changes in average emotional tone over time
606
+
+ select a subset of messages based on emotional tone levels, and generate comments using **Watson Assistant** language processing and dialog service
0 commit comments