IBM/watson-discovery-news-alerting

Name: watson-discovery-news-alerting

Owner: International Business Machines

Description: Monitor a product's marketplace life-cycle using Watson's Discovery service to intelligently alert when a product's stance in the marketplace has changed. Receive periodic updates via email related to a product or brand and how they're perceived in the News.

Created: 2017-05-31 06:42:04.0

Updated: 2018-04-27 13:38:46.0

Pushed: 2018-04-27 13:38:48.0

Homepage: https://developer.ibm.com/code/patterns/create-cognitive-news-alerting-app/

Size: 10898

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

Watson Discovery News Alerting

In this Code Pattern, we will build a Node.js web application that will use the Watson Discovery Service to access Watson Discovery News.

Watson Discovery News is a default data collection that is associated with the Watson Discovery Service. It is a dataset of primarily English language news sources that is updated continuously, with approximately 300,000 new articles and blogs added daily.

The focus of this Code Pattern is to monitor a product's marketplace life-cycle using Watson's Discovery service to intelligently alert when a product's stance in the marketplace has changed. Users can recieve periodic email alerts about a product or brand and how they're perceived in the News.

Alert tracking can be set up for the following areas:

The Code Pattern highlights the steps required to build a front-end management interface to search Watson News and a back-end service which periodically sends alerts out related to customizable queries.

Flow
  1. The user interacts with the backend server via the app UI. The frontend app UI uses React to render search results and can reuse all of the views that are used by the backend for server side rendering. The frontend is using watson-react-components and is responsive.
  2. User input is processed and routed to the backend server, which is responsible for server side rendering of the views to be displayed on the browser. The backend server is written using express and uses express-react-views engine to render views written using React.
  3. The backend server stores subscription information in a Cloudant NonSQL database for product tracking.
  4. The backend server sends user requests to the Watson Discovery Service. It acts as a proxy server, forwarding queries from the frontend to the Watson Discovery Service API while keeping sensitive API keys concealed from the user.
  5. The Watson Discovery Service queries the Watson News Collection for articles related to the product.
  6. The backend server sends periodic updates to email.

Included components

Featured technologies

Watch the Video

Steps

  1. Clone the repo
  2. Create Watson Services with IBM Cloud
1. Clone the repo

Clone the watson-discovery-news-alerting locally. In a terminal, run:

t clone https://github.com/ibm/watson-discovery-news-alerting
2. Create Watson Services with IBM Cloud

Create the following service:

Run the application locally
  1. Install Node.js and Yarn
  2. Install all of the dependencies by running yarn. This will install of the node modules specified in package.json
     app
    rn
    
  3. Copy the env.sample to .env
     .env.sample .env
    
  4. Edit the .env file and enter the Watson Discovery credentials and SMTP Mail settings if you wish to use the tracking feature.
  5. Build and start the main app.
    rn run build
    rn start
    
  6. Build and start the tracking app.
    rn run start-notifier
    
  7. Open a browser and go to http://localhost:4391
Deploy and run the application on IBM Cloud

To deploy to IBM Cloud make sure you have IBM Cloud CLI tool installed. Then run the following commands to connect it with IBM Cloud and login with your IBM Cloud credentials.

 watson-discovery-news-alerting
uemix login

Then to deploy just run the following command and it will push the code, deploy it to a server and run it.

uemix cf push

If the cf push command complains that the application name is already taken, change the lines in the manifest.yml to have a custom application name specific for your setup:


ications:
me: custom-name
th: ./app

Two IBM Cloud applications should be created and running:

Set the environment variables required for each the notifier service to perform properly. Use the values unique to your setup:

uemix cf set-env watson-discovery-news-alert-notifier SMTP_SETTINGS '{"host":"smtp.gmail.com","user":"xxx@gmail.com","pass":"xxx","fromEmail":"xxx@gmail.com"}'
uemix cf set-env watson-discovery-news-alert-notifier BASE_URL 'https://watson-discovery-news-alerting.mybluemix.net'

Go to the URL route that is associated with the watson-discovery-news-alerting app in IBM Cloud to view the application. Typically, this would be https://watson-discovery-news-alerting.mybluemix.net.

Sample output

General Project Layout

The server which hosts the React web application, acts as an API to Watson, and communicates with the notifier App can be found at:

p/server.js

The server which periodically emails news alerts to subscribed users can be found at:

p/notifier.js

Architecture Diagram

Architecture

Back-end Server

Handles hosting of the static assets (React front-end application) and manages a thin API used by the front-end application.

Front-end Application

Displays results from querying the Watson Discovery Service API and manages subscriptions for push updates.

Worker Application

Background process which periodically sends updates to email.

Troubleshooting

NOTE: This only needs to be set if the application is running locally.

The credentials for IBM Cloud services (wdna-discovery and wdna-cloudant) can be found in the Services menu in IBM Cloud, and selecting the Service Credentials option.

If the port is unavailable, you will see the following error:

r: listen EADDRINUSE :::{port}

Links

Learn more

License

Apache 2.0


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.