This repository will not be updated. The repository will be kept available in read-only mode. Refer to https://github.com/IBM/watson-discovery-news for a similar example.
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 receive 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.
Clone the watson-discovery-news-alerting
locally. In a terminal, run:
git clone https://github.com/ibm/watson-discovery-news-alerting
Create the following service:
wdna-discovery
wdna-cloudant
yarn
. This will install of the node modules specified in package.json
cd app
yarn
env.sample
to .env
cp .env.sample .env
Edit the .env
file and enter your Watson Discovery and Cloudant NoSQL DB credentials. Add SMTP Mail settings if you wish to use the tracking feature.
Build and start the main app.
yarn run build
yarn start
yarn run start-notifier
http://localhost:4391
To deploy to IBM Cloud make sure you have the IBM Cloud CLI tool installed. Then run the following commands to connect it with IBM Cloud and login with your IBM Cloud credentials.
cd watson-discovery-news-alerting
ibmcloud login
Run the following command to deploy and run the alerting and notifier apps on the IBM Cloud. It will automatically connect to your existing Watson Discovery and Cloudant NoSQL DB services if your service names match the names specified in the manifest.yml
file.
ibmcloud cf push
If the ibmcloud 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:
...
applications:
- name: custom-name
path: ./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:
ibmcloud cf set-env watson-discovery-news-alert-notifier SMTP_SETTINGS '{"host":"smtp.gmail.com","user":"xxx@gmail.com","pass":"xxx","fromEmail":"xxx@gmail.com"}'
ibmcloud 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
.
The server which hosts the React web application, acts as an API to Watson, and communicates with the notifier App can be found at:
./app/server.js
The server which periodically emails news alerts to subscribed users can be found at:
./app/notifier.js
Handles hosting of the static assets (React front-end application) and manages a thin API used by the front-end application.
Displays results from querying the Watson Discovery Service API and manages subscriptions for push updates.
Background process which periodically sends updates to email.
.env
config fileThe 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:
Error: listen EADDRINUSE :::{port}
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.