Skip to content

A Node.js web app that uses the Watson Discovery News service to query and view the latest trending news items.

License

Notifications You must be signed in to change notification settings

IBMDeveloperTokyo/watson-discovery-news

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

  • 日本オリジナルパターンは こちら

Query Watson Discovery News using the Watson Discovery Service

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.

This Code Pattern 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 will be 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.

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 IBM Cloud button OR create the services and run locally.

Deploy to IBM Cloud

Deploy to IBM Cloud

  1. Press the above Deploy to IBM Cloud 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 Code Pattern, use the IBM Cloud 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 IBM Cloud button.

  1. Clone the repo
  2. Create Watson Services with IBM Cloud
  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 Cloud

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 IBM Cloud button...

If you used Deploy to IBM Cloud, most of the setup is automatic, but not quite all of it. We have to update a few environment variables.

In the IBM Cloud 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 daily digest of news and email in the morning. Other uses may include automatically 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 the IBM Cloud services (Discovery), can be found in the Services menu in IBM Cloud, and selecting the Service Credentials option.

# Copy this file to .env and replace the credentials with
# your own before starting the app.

# Watson Discovery
DISCOVERY_URL=<add_discovery_url>
## Un-comment and use either username+password or IAM apikey.
# DISCOVERY_USERNAME=<add_discovery_username>
# DISCOVERY_PASSWORD=<add_discovery_password>
# DISCOVERY_IAM_APIKEY=<add_discovery_iam_apikey>

# Run locally on a non-default port (default is 3000)
# PORT=3000

# Slack
SLACK_BOT_TOKEN=<slack_bot_token>

# Run locally on a non-default port (default is 3000)
# PORT=3000
  • Ensure port is not already in use

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

Error: listen EADDRINUSE :::{port}

Links

Learn more

  • Artificial Intelligence Code Patterns: Enjoyed this Code Pattern? Check out our other AI Code Patterns.
  • AI and Data Code Pattern Playlist: Bookmark our playlist with all of our Code Pattern videos
  • With Watson: Want to take your Watson app to the next level? Looking to utilize Watson Brand assets? Join the With Watson program to leverage exclusive brand, marketing, and tech resources to amplify and accelerate your Watson embedded commercial solution.

License

Apache 2.0

About

A Node.js web app that uses the Watson Discovery News service to query and view the latest trending news items.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 76.1%
  • CSS 23.7%
  • Dockerfile 0.2%