/watson-discovery-news

A Node.js web app that uses the Watson Discovery News service, it allows the user to query and view trending news

Primary LanguageJavaScriptApache License 2.0Apache-2.0

Build Status Bluemix Deployments

Query Watson Discovery News using the Watson Discovery Service

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 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.

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.

Flow

  1. The user interacts with the Watson Discovery News Server via the app UI.
  2. User input is processed and routed to the Watson Discovery News Server.
  3. The Watson Discovery News Server sends user requests to the Watson Discovery Service.
  4. The Watson Discovery Service queries the Watson News Collection.
  5. The Watson Discovery Service sends news articles to the RSS Reader.
  6. The Watson Discovery Service responds to Slack search requests.

With Watson

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.

Included components

  • Watson Discovery: A cognitive search and content analytics engine for applications to identify patterns, trends, and actionable insights.

Featured technologies

  • 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

Watch the Video

Steps

Use the Deploy to Bluemix button OR create the services and run locally.

Deploy to Bluemix

Deploy to Bluemix

  1. Press the above Deploy to Bluemix button and then click on Deploy.

  2. In Toolchains, click on Delivery Pipeline to watch while the app is deployed. Once deployed, the app can be viewed by clicking 'View app'.

  1. 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

Run locally

NOTE: These steps are only needed when running locally instead of using the Deploy to Bluemix button.

  1. Clone the repo
  2. Create Bluemix services
  3. Configure Watson Discovery
  4. Configure Slack
  5. Run the application

1. Clone the repo

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

$ git clone https://github.com/ibm/watson-discovery-news

2. Create Watson Services with IBM Bluemix

Create the following service:

3. Configure Watson Discovery

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.

4. Configure Slack

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.

5. Run the application

If you used the Deploy to Bluemix button...

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.

If you decided to run the app 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
$ yarn
  1. Run yarn bootstrap to copy the .env.sample to .env
$ yarn bootstrap
  1. Edit the .env file and enter the Watson Discovery credentials and Slack Bot Token saved in previous steps
  2. 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 run yarn start:watch
$ yarn start
  1. Open a browser and go to http://localhost:{PORT}, where PORT is the value specified in .env (default is 3000)

Sample output

Trending Topics RSS Feed

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.

 

Search from Slack

Troubleshooting

  • 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}

License

Apache 2.0

Privacy Notice

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.

Disabling Deployment Tracking

To disable tracking, simply remove cf_deployment_tracker.track() from the app.js file in the top level directory.