In this developer journey, 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 defaullt 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.
This journey will demonstrate two use cases for accessing Watson Discovery News:
-
Trending Topics in the News - Identify popular topics over the past 24 hours. Topics can be general, or for a specific industry or category.
-
Search - Query for the most relevant new articles about a specific topic or subject. Results will include enrichment data, such as article summary text and sentiment analysis.
Optionally included in this journey are examples of how to:
-
Build a RSS News Feed generator to push Trending Topic news to your favorite RSS reader.
-
Build a SlackBot to access the Search feature from Slack.
- The user interacts with the Watson Discovery News Server via the app UI.
- User input is processed and routed to the Watson Discovery News Server.
- The Watson Discovery News Server sends user requests to the Watson Discovery Service.
- The Watson Discovery Service queries the Watson News Collection.
- The Watson Discovery Service seeds news articles to the RSS Reader.
- The Watson Discovery Service responds to Slack search requests.
Want to take your Watson app to the next level? Looking to leverage Watson Brand assets? Join the With Watson program which provides exclusive brand, marketing, and tech resources to amplify and accelerate your Watson embedded commercial solution.
- Watson Discovery: A cognitive search and content analytics engine for applications to identify patterns, trens, and actionable insights.
- Node.js - An asynchronous event driven JavaScript runtime, designed to build scalable applications
- React - Javascript library for building User Interfaces
- Express - A popular and minimalistic web framework for creating API and Web server
- Yarn - Fast, reliable and secure dependency manager for node.js
- RSS - RSS (Rich Site Summary) is a format for delivering regularly changing web content in our case it will be trending topics
- Slack - Slack is a cloud-based set of team collaboration tools and services with chat bot integration
- Botkit - Framework for creating and managing chat bots
- coming soon
Use the Deploy to Bluemix
button OR create the services and run locally.
-
Press the above
Deploy to Bluemix
button and then click onDeploy
. -
In Toolchains, click on Delivery Pipeline to watch while the app is deployed. Once deployed, the app can be viewed by clicking 'View app'.
- To see the app and services created and configured for this journey, use the Bluemix dashboard. The app is named
watson-discovery-news
with a unique suffix. The following services are created:- discovery-news-service
NOTE: These steps are only needed when running locally instead of using the
Deploy to Bluemix
button.
- Clone the repo
- Create Bluemix services
- Configure Watson Discovery
- Configure Slack
- Run the application
Clone the watson-discovery-news
locally. In a terminal, run:
$ git clone https://github.com/ibm/watson-discovery-news
Create the following service:
Fill in name you want to give to your service and click Create.
After the service is created, click on Service credentials and then click on View Credentials. Save these credentials as they will be needed when configuring the app.
To integrate a new Slack Bot into your existing Slack team, navigate to https://my.slack.com/services/new/bot. Enter a username for the bot and click Add bot integration.
Once created, save the API Token that is generated.
If you used Deploy to Bluemix
, most of the setup is automatic, but not
quite all of it. We have to update a few environment variables.
In the Bluemix dashboard find the App that was created. Click on Runtime
on the menu and navigate to the Environment variables
tab.
Update the following environment variable:
- Set
SLACK_BOT_TOKEN
to the token you saved previously
Save the new value and restart the application, watch the logs for errors.
- Install Node.js and Yarn
- Install all of the dependencies by running
yarn
. This will install of the node modules specified inpackage.json
$ yarn
- Run
yarn bootstrap
to copy the.env.sample
to.env
$ yarn bootstrap
- Edit the
.env
file and enter the Watson Discovery credentials and Slack Bot Token saved in previous steps - Start the app by running
yarn start
. If you are developing and making changes to the app and would like the server to restart every time then runyarn start:watch
$ yarn start
- Open a browser and go to
http://localhost:{PORT}
, where PORT is the value specified in.env
(default is 3000)
On the Trending News Panel, click the RSS Feed button to launch a new tab in your browser. Cut and paste the tab URL into your favorite RSS Reader. If your RSS Feed Reader supports push notifications you can get alerted when trending topics change along with a news article for that topic.
Since RSS feed is a standard way to consume constantly changing data such as news, we can use the RSS feeds we generated to also post news articles to your organizations slack channel to track trends in your industry, or consume the feed to generate a dialy digest of news and email in the morning. Other uses may include automaticaly posting tweets to a twitter account on news articles on trending topics using a service called IFTTT.
- Setting environment variables for a local run
NOTE: This only needs to be set if the application is running locally.
The credentials for Bluemix services (Discovery), can
be found in the Services
menu in Bluemix, and selecting the Service Credentials
option.
# Watson Discovery
DISCOVERY_USERNAME=<add_discovery_username>
DISCOVERY_PASSWORD=<add_discovery_password>
# Slack
SLACK_BOT_TOKEN=<add_slack_bot_token>
- Ensure port is not already in use
If the port is unavailable, you will see the following error:
Error: listen EADDRINUSE :::{port}
If using the Deploy to Bluemix button some metrics are tracked, the following information is sent to a Deployment Tracker service on each deployment:
- Node.js package version
- Node.js repository URL
- Application Name (
application_name
) - Application GUID (
application_id
) - Application instance index number (
instance_index
) - Space ID (
space_id
) - Application Version (
application_version
) - Application URIs (
application_uris
) - Labels of bound services
- Number of instances for each bound service and associated plan information
This data is collected from the package.json
file in the sample application and the VCAP_APPLICATION
and VCAP_SERVICES
environment variables in IBM Bluemix and other Cloud Foundry platforms. This
data is used by IBM to track metrics around deployments of sample applications to IBM Bluemix to
measure the usefulness of our examples, so that we can continuously improve the content we offer
to you. Only deployments of sample applications that include code to ping the Deployment Tracker
service will be tracked.
To disable tracking, simply remove cf_deployment_tracker.track()
from the
index.js
file in the top level directory.