Skip to content

Commit cc11280

Browse files
committed
add jay-zbot flow and twitter config
1 parent ae328fb commit cc11280

10 files changed

+102
-18
lines changed

img/qcon-dash-link.png

10.8 KB
Loading

img/qcon-jayz-flow-add.png

29.6 KB
Loading

img/qcon-jayz-flow-change.png

16.1 KB
Loading

img/qcon-jayz-function-pass.png

30.1 KB
Loading

img/qcon-jayz-result.png

20.5 KB
Loading

img/qcon-twitter-auth-add.png

10.7 KB
Loading

img/qcon-twitter-auth-app.png

45.7 KB
Loading

img/qcon-twitter-config.png

20.1 KB
Loading

rdc-qcon-workshop-overview.md

Lines changed: 102 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
# AI benefits for the lazy hacker
66

7+
**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+
<div style="page-break-after: always;"></div>
716
## Get fast usable access to AI services with Node-RED
817

918
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:
315324
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.
316325

317326
<div style="page-break-after: always;"></div>
318-
### Lab - twitter sentiment
327+
### Lab - twitter emtional tone
319328

320329
This time, you can build a fun, simple application that uses the Watson Tone Analyzer service.
321330

@@ -359,9 +368,21 @@ All being well, you should see the additonal nodes being dynamically added to th
359368
You'll find these new nodes towards the bottom of the left-side palette menu.
360369

361370
Once more, create a new flow on the canvas with the following nodes:
371+
362372
![stage3-flow](img/qcon-stage3-flow.png)
363373

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 ![edit-twitter](img/qcon-config-edit-icon.png) icon
377+
1. when you see following prompt in a new tab or window, click `Click here to authenicate with Twitter`
378+
![edit-auth-add](img/qcon-twitter-auth-add.png)
379+
1. you'll be asked to authorise the Node-RED application - click `Authorize app`
380+
![edit-auth-app](img/qcon-twitter-auth-app.png)
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.
365386

366387
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.
367388

@@ -378,13 +399,13 @@ In a `function` node named “Add tweet scores to total”, the scores can be ac
378399
```
379400
var defaultResult = {
380401
"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
386407
},
387-
"count":0
408+
"count": 0
388409
}
389410
390411
if(msg.payload) {
@@ -452,29 +473,35 @@ Make sure the `Legend` option is updated to `Show` so you can distinguish betwee
452473

453474
Once you redeploy the application, following the link to the Dashboard
454475

455-
and you should see the chart building:
476+
![dash-link](img/qcon-dash-link.png)
477+
478+
and you should see the chart beginning to build:
456479

457480
![chart-results](img/qcon-emotion-chart.png)
458481

459482
*_Congratulations!_* - you have completed the process of integrating live Twitter with Watson's natural language processing capabilities for identifying emtional tone.
460483

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

463486
<div style="page-break-after: always;"></div>
464487
### Lab - twitter chatbot setup
465488

466489
Now, a selection of the tweets can be directed to a chatbot service to trigger a response (based on the Watson Assitant service).
467490

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+
![jayz-add](img/qcon-jayz-flow-add.png)
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.
469496

470497
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.
471498

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

474501
Yo will need to create an instance of the Watson Assistant service in the IBM Cloud catalog -
475502
![Watson Assistant](img/qcon-catalog-watson-assist.png)
476503

477-
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.
478505

479506
![Watson Assist tool](img/qcon-watson-assist-tool.png)
480507

@@ -499,24 +526,81 @@ This will create the 3 main areas of chatbot server configuration:
499526
![dialog](img/qcon-watson-assist-jayz-dialog.png)
500527

501528

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 ![converse](img/qcon-node-watson-conversation-icon.png)
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
530+
531+
![converse](img/qcon-node-watson-conversation-icon.png)
503532

504533
You will need the credentials for the Watson Assistant instance, to plug into the node configuration menu. Either:
505534
+ 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
506535
+ 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)
507536

508537
![creds](img/qcon-watson-tone-analyzer-credentials.png)
509538

510-
**Note** - you also need the Watson Assistant workspace identifiers to plug in to the node configuration
539+
**Note** - you also need the Watson Assistant workspace identifier to plug in to the node configuration
540+
511541
![tool-menu](img/qcon-watson-assist-menu.png)
512-
Select the `Workspaces` tab, to see access the workspaces in this instance.
542+
543+
Select the `Workspaces` tab, to access the workspaces in this instance.
544+
513545
![tool-workspaces](img/qcon-watson-assist-tool-workspaces.png)
514546

515-
Click the details menu ![details-icon](img/qcon-assist-menu-icon.png) 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 ![details-icon](img/qcon-assist-menu-icon.png) and select `View details` to view the `Workspace ID` - add this into the corresponding field in the Node-RED Conversation node configuration panel.
548+
516549
![assist config](img/qcon-assist-config.png)
517550

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+
![jayz-result](img/qcon-jayz-result.png)
554+
555+
Configure the `change` node to move the twitter content into the `msg.payload` property:
518556

557+
![jayz-change](img/qcon-jayz-flow-change.png)
558+
559+
Last, but not least, configure the `function` node to select messages based on high emotional tone:
560+
561+
![jayz-select](img/qcon-jayz-function-pass.png)
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 ![deploy](img/qcon-deploy-go.png) !!
574+
575+
*_Congratulations!_* - you have completed the process of generating responses to select tweets, using a basic chatbot configuration.
519576

520577
<div style="page-break-after: always;"></div>
521578
## 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

rdc-qcon-workshop-overview.pdf

238 KB
Binary file not shown.

0 commit comments

Comments
 (0)