- 日本オリジナルパターンは こちら
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.
- 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 sends news articles to the RSS Reader.
- The Watson Discovery Service responds to Slack search requests.
- Watson Discovery: A cognitive search and content analytics engine for applications to identify patterns, trends, 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
Use the Deploy to IBM Cloud
button OR create the services and run locally.
-
Press the above
Deploy to IBM Cloud
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 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
NOTE: These steps are only needed when running locally instead of using the
Deploy to IBM Cloud
button.
- Clone the repo
- Create Watson Services with IBM Cloud
- 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 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.
- 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 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.
- 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}
- Demo on Youtube: Watch the video.
- Watson Node.js SDK: Download the Watson Node SDK.
- Cognitive discovery architecture: Learn how this Code Pattern fits into the Cognitive discovery Reference Architecture.
- Overview of the Watson Discovery service: Extract value from unstructured data by converting, normalizing, enriching it.
- Three ways IBM has evolved Alchemy Data News into Watson Discovery News and made it even better: Watson Discovery News takes big steps forward in NLP-enriched news search.
- IBM launches Watson Discovery Service for big data analytics at scale: Suite of APIs makes it easier for companies to ingest and analyze their data, even if they don’t have advanced degrees in data science.
- SlideShare: Building with Watson – Network Visualizations using Watson Discovery: See an app built on the Watson Discovery Service and D3.js that helps you explore your data using a network map built on NLP metadata.
- 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.