Name: cognitive-social-crm
Owner: International Business Machines
Description: An application that monitors a Twitter feed and determines customer sentiment using IBM Watson Assistant, Tone Analyzer, Natural Language Understanding, as well as CloudantDB
Created: 2017-08-17 17:14:44.0
Updated: 2018-05-17 00:03:22.0
Pushed: 2018-05-17 00:03:21.0
Size: 19968
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Watson Conversation is now Watson Assistant. Although some images in this code pattern may show the service as Watson Conversation, the steps and processes will still work.
In this journey, our server application subscribes to a Twitter feed as configured by the user. Each tweet received will be analyzed for emotional tone and sentiment, and the intent of the tweet will be determined by the Watson Assistant service. All data is stored in a Cloudant database, with the opportunity to store historical data as well. The resulting analysis is presented in a Web UI as a series of graphs and charts. Credit goes to Werner Vanzyl as the author of the original code and documents.
When the reader has completed this journey, they will understand how to:
The setup is done in 3 primary steps. You will download the code, setup the application and then deploy the code to IBM Cloud. If you would like to run the code locally, there will be one more step to configure the credentials locally.
Clone the cognitive-social-CRM
locally. In a terminal, run:
t clone https://github.com/IBM/cognitive-social-crm
cognitive-social-crm
We?ll be using the file data/conversation/workspaces/workspace-social-crm-airline-classification.json
to configure our Watson Assistant workspace.
The application requires the following software to be installed locally.
npm install -g @angular/cli
.If you have Angular CLI already installed. Please read the upgrade instructions for Angular CLI when you upgrade the software.
Run the following command, from the application folder, to install both the client and server dependencies.
m install
To subscribe to Tweets from a specific handle or hashtag in this application, it is required to create a Twitter account and a Twitter application. The Twitter account will be used as the account that receives the messages from other Twitter users as well as the owner of the application, required by Twitter, to receive Tweets.
Either Setup the IBM Cloud Deployment or Setup Local Deployment.
Explanation: You will create a placeholder application in IBM Cloud that connects to all the required services first.
Application Dashboard
, create a new Application
.
- On the left, select Apps
> Cloudfoundry Apps
.SDK for Node.js
.Connections
.Watson Assistant
, Natural Language Understanding
, Tone Analyzer
, and Cloudant NoSQL DB
.Connections
page open, as you will reference the credentials in the next step.Explanation: You will create the IBM Cloud services and configure them to use on a locally running server app.
If you do not already have a IBM Cloud account, sign up for Bluemix. Create the following services:
Launch the Watson Assistant tool. Use the import icon button on the right
Find the local version of data/conversation/workspaces/workspace-social-crm-airline-classification.json
and select
Import. Find the Workspace ID by clicking on the context menu of the new
workspace and select View details. Save this ID for later.
The env-vars-example.json
file should be copied to env-vars.json
before the application is executed on IBM Cloud or locally.
The
env-vars.json
file is where all the parameters of this application is kept. The setup utility, explained later, will guide you through setting up some of the parameters in this file, but you can come back and modify them at any time.
The credentials for IBM Cloud services (Assistant, Tone Analyzer,
Natural Language Understanding, and Cloudant), can be found in the Services
menu in IBM Cloud,
by selecting the Service Credentials
option for each service.
The other setting for Assistant was collected during the
earlier setup steps (WORKSPACE_ID
).
Copy the env-vars-example.json
to env-vars.json
.
env-vars-example.json env-vars.json
Edit the env-vars.json
file with the necessary settings.
The Cloudant and Twitter settings will be populated when you execute npm run setup
in the next step. These variables could be hand edited if you wish, but the setup utility is required to create the Cloudant documents.
env-vars-example.json:
LOUDANT_CONNECTION_URL": <populated by `npm run setup`>,
LOUDANT_USERNAME": <populated by `npm run setup`>,
LOUDANT_PASSWORD": <populated by `npm run setup`>,
LOUDANT_ANALYSIS_DB_NAME": "analysis-db",
LOUDANT_CONVERSATION_STATE_DB_NAME": "conversation-state-db",
ONVERSATION_API_URL": "",
ONVERSATION_API_USER": "",
ONVERSATION_API_PASSWORD": "",
ONVERSATION_CLASSIFICATION_WORKSPACE_ID": "",
LU_API_USER": "",
LU_API_PASSWORD": "",
ONE_ANALYZER_USER": "",
ONE_ANALYZER_PASSWORD": "",
WITTER_CONSUMER_KEY": <populated by `npm run setup`>,
WITTER_CONSUMER_SECRET": <populated by `npm run setup`>,
WITTER_ACCESS_TOKEN": <populated by `npm run setup`>,
WITTER_ACCESS_SECRET": <populated by `npm run setup`>,
WITTER_LISTEN_FOR": "populated by `npm run setup`",
WITTER_FILTER_FROM": "populated by `npm run setup`",
WITTER_FILTER_CONTAINING": "populated by `npm run setup`",
WITTER_PROCESS_RETWEETS": false,
WITTER_RECEIVER_START_AT_BOOT": true,
WITTER_CHATBOT_SCREENNAME": <populated by `npm run setup`,
WITTER_CHATBOT_START_AT_BOOT": true
The Social CRM application consist of a Setup utility that you can run that will update the configuration files required by the application and create the Cloudant DB documents. It will also allow you to test Twitter and query the database.
In the directory where to code is located (previously downloaded and cd'ed into) run the following command
m run setup
The setup utility consist of a number of actions that should be performed.
This action will create the databases required to run the application as well as load all the design documents and indexes. You need to have the Cloudant username and password handy, which you can find in the credentials of your Cloudant service in IBM Cloud.
This action will update the configuration with the parameters needed to connect to Twitter as well as subscribe to tweets. You need to have the Consumer Key (API Key), Consumer Secret (API Secret), Access Token and Access Token Secret from dev.twitter.com available.
At this point you should have decided what Twitter handle you will be “listening” to. The Watson Assistant Intents for this journey are configured to work with a Twitter account for an airline, but you could create relevant intents for whichever business domain you wish. The Twitter handle would be something other people would tweet to, for example @aircanada
. This value is what Twitter would use as trigger to send you the tweets.
NOTE: Due to the potential for a large volume of API calls, this Accelerator will work best with a paid subscription to IBM Cloud. If you try and use this accelerator on an screen name that produces a lot of tweets, then you take the risk of using up your free allocation of API calls very quickly. The Accelerator will suspend for 15 minutes listening to tweets if there are errors returned from the enrichment pipeline. When the receiver on the UI is paused, it usually means you have exceeded your limit for the day.
When you select the Twitter
option on the main menu of the setup utility, you will be required to enter the Twitter Tokens first. Continue to enter the screen name you are listening to, the Assistant API workspace id for the classifications, and finally the Chatbot screen name and Assistant API workspace for the Dialog implementation.
The next option is to test out the Twitter parameters. When you select this option from the setup utility's main menu, the listener will be started and you will see tweets being received and displayed on the console. If some of the parameters are incorrect, then you should see the error.
Note: If you want to leverage this feature, you have to complete the local setup.
You sometimes want to populate your database with previous Tweets. This Accelerator provides you with the ability to go back 7 days to search for tweets that match your “listen to” screen name. It will do the enrichment and place the tweets into the database.
Either Run the app on IBM Cloud
or Run the app locally
.
Use the name of the application you created previously to update the configuration files locally.
Open the manifest.yml
file and change the name
AND host
value to the unique application name you created on IBM Cloud previously.
Compile the Angular 2 client code using the following command.
m run build:client
Connect to IBM Cloud in the command line tool and follow the prompts to log in
login -a https://api.ng.bluemix.net
Push the app to IBM Cloud.
push
The application should now be running on IBM Cloud and listening to Tweets. You can access the application URL using the application name you defined in the manifest.yml
file with a '.mybluemix.net' appended to it.
The application is secured with a username and password. See the end of this README for details.
Once all the credentials are in place, the application can be started with:
m run develop
There is only 1 user required for this application. This user is watson
with a password of p@ssw0rd
The user names and passwords can be modified in the /server/boot/init-access.js
file.
There are some customization what can be done in the application apart from using your own Twitter screen name to monitor and the conversation workspaces you provide.
env-vars.json
file.client/src/app/shared/config.service.ts
file.You will see informations about Tweets:
as well as Classification of live tweets, Sentiment over time, Emotional Tone over time, and Keywords mentioned: