An application that monitors a Twitter feed and determines customer sentiment using IBM Watson Assistant, Tone Analyzer, Natural Language Understanding, as well as CloudantDB
This repository will not be updated. The repository will be kept available in read-only mode.
Read this in other languages: 日本語.
In this code pattern, 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.
When the reader has completed this code pattern, 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:
$ git clone https://github.com/IBM/cognitive-social-crm
$ cd cognitive-social-crm
The application requires the following software to be installed locally.
npm install -g @angular/cli
.package.json
when setting up client using Angular cli
.package.json
for server.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.
$ npm run app-install
NOTE: Currently Windows OS is not supported
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 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, signup for IBM Cloud. Create the following services:
NOTE: When provisioning Cloudant, for
Available authentication methods
chooseUse both legacy credentials and IAM
Launch tool
.Skills
tab.Create new
Import skill
tab.Choose JSON file
, go to your cloned repo dir, and Open
the workspace.json file in data/assistant/workspace-social-crm-airline-classification.json
.Everything
and click Import
.To find the WORKSPACE_ID
for Watson Assistant:
Skills
tab.View API Details
.Workspace ID
GUID.Optionally, to view the Assistant dialog, click on the skill and choose the
Dialog
tab. Here's a snippet of the dialog:
The env.sample
file should be copied to .env
before the application is executed on IBM Cloud or locally. The .env
file resides on the server
folder as it is required by the server code.
The
.env
file is where all the parameters like credentials, log settings and other constants required by this application is kept.
The credentials for IBM Cloud services (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.
NOTE: When provisioning Cloudant, for
Available authentication methods
chooseUse both legacy credentials and IAM
From the root of the project, go to server
folder (cd server
) and
Copy the env.sample
to .env
.
$ cd server
$ cp env.sample .env
Add all the credentials that you have saved from creating the services, as explained earlier, in the .env
file.
env.sample
# Copy this file to .env and replace the credentials with
# your own before starting the app.
CLOUDANT_USERNAME=<use cloudant username>
CLOUDANT_PASSWORD=<use cloudant password>
CLOUDANT_ANALYSIS_DB_NAME=analysis_db
## Un-comment and use either username+password or IAM apikey.
# NATURAL_LANGUAGE_UNDERSTANDING_USERNAME=<use natural language understanding username>
# NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD=<use natural language understanding password>
NATURAL_LANGUAGE_UNDERSTANDING_IAM_APIKEY=<use natural language understanding iam API key>
NATURAL_LANGUAGE_UNDERSTANDING_URL=<use natural language understanding URL>
## Un-comment and use either username+password or IAM apikey.
# TONE_ANALYZER_USERNAME=<use tone analyzer username>
# TONE_ANALYZER_PASSWORD=<use tone analyzer password>
TONE_ANALYZER_IAM_APIKEY=<use tone analyzer iam API key>
TONE_ANALYZER_URL=<use tone analyzer url>
## Un-comment and use either username+password or IAM apikey.
# ASSISTANT_USERNAME=<use assistant username>
# ASSISTANT_PASSWORD=<use assistant password>
ASSISTANT_IAM_APIKEY=<use assistant iam apikey>
ASSISTANT_URL=<use assistant url>
ASSISTANT_CLASSIFICATION_WORKSPACE_ID=<use assistant workspace id>
# Configuration from you twitter account
TWITTER_CONSUMER_KEY=<use twitter consumer key>
TWITTER_CONSUMER_SECRET=<use twitter consumer secret>
TWITTER_ACCESS_TOKEN=<use twitter access token>
TWITTER_ACCESS_SECRET=<use twitter access secret>
#TWITTER_LISTEN_FOR=<use twitter hashtag or keyword or @tag>
TWITTER_LISTEN_TO=<use your @tag>
TWITTER_FILTER_CONTAINING=<use keyword you want to filter in tweets>
TWITTER_PROCESS_RETWEETS=true
# App level configuration
LOGGING=true
LOG_LEVEL=info
OUTPUT_TYPE=json
SAVE_TYPE=cloudant
Either Run the app on IBM Cloud
or Run the app locally
.
dist
folder in your project root directory and copies the compile code and necessary files to be deployed to IBM cloud.$ npm run build
$ ibmcloud cf login -a https://api.ng.bluemix.net
Make sure you set the
target
andspace
correctly usingibmcloud target -o <target> -s <space>
$ ibmcloud app push
Cloud Foundry Applications
section of IBM cloud dashboard. Click the name of the application you just pushed and clikc Visit App URL
to access the application.Once all the credentials are in place, the application can be started with:
$ npm run start
The server runs on port 3000
and the client
runs on port 4200
. You can access the UI by accessing the following URL in the browser:
http://localhost:4200
You will see informations about Tweets:
as well as Classification of live tweets, Sentiment over time, Emotional Tone over time, and Keywords mentioned:
This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.