IBM Watson Extension Setup Guide

The IBM Watson widget lets you analyze the content of an entry and extract meta-data from the content such as categories, concepts, emotions, entities, keywords, relations, semantic roles, and sentiment. This widget uses custom annotation models developed by Watson Knowledge Studio to analyze the data and identify industry- or domain-specific entities and relations in unstructured text.

This widget uses IBM Watson APIs to offer a wide variety of services that let you get more out of your content. Refer to the IBM Cloud API docs for more details.

This step-by-step guide explains how to create the IBM Watson widget extension in Contentstack. The steps to be performed are as follows:

  1. Create service instance in IBM Watson
  2. Generate service credentials
  3. Deploy Lambda function
  4. Add ‘IBM Watson' widget extension to your stack
  5. Use the extension

Step 1 - Create service instance in IBM Watson

To begin with, you need to create an instance of the ‘Natural Language Understanding’ service and create service-specific credentials to provide authentication to the selected service in IBM Cloud. To do so, perform the steps given below:

  1. Log in to your IBM Cloud account.
  2. Go to the Natural Language Understanding page in the IBM Cloud Catalog.
  3. Click Create. This creates your service instance.

Next, we’ll see how to retrieve the service credentials. For more information, refer the Getting started with Watson and IBM Cloud page.

Step 2 - Generate service credentials

Perform the steps given below after creating your service instance:

  1. When you are led to the Manage page, go to the Credentials tab
  2. Click Show to view your credentials. You will find the API key and URL of your service.
  3. Note down the API key and URL, as you will need to use them in Step 6.

For more information, refer the Service credentials for Watson services page.

Step 3 - Configure and deploy Lambda function

To protect sensitive information (such as API Key and URL) and avoid Cross-Origin Resource Sharing (CORS) issues, you can use Lambda function for this extension. To do so, perform the below functions:

  1. After retrieving the credentials, deploy the code for the lambda function to AWS Lambda.

    Note: Refer Step 4 for the source code along with the lambda function of the IBM Watson extension.

  2. In the Environment Variables section of AWS Lambda, enter the credentials against the variables as follows:
WATSON_SERVICE_API_KEY= API Key received in service instance credentials
WATSON_SERVICE_URL= URL received in service instance credentials

Step 4 - Add ‘IBM Watson’ widget extension to your stack

  1. Go to Settings > Extensions. Click on the + Add Extension button on the top-right corner and select Create new.
    Creating new extension.png
  2. Select the extension type as Custom Widget.
    Select Extension Type - Custom Widget.png
  3. You will be led to the ‘Create New Extension’ details page where you need to enter details in the fields as given below:
    • Title: Provide a suitable title. For example, IBM Watson.
    • Hosting method: Select Hosted By Contentstack. As soon as you do this, you will see the ‘Extension Source Code’ field below.
    • Extension Source Code: Enter the source code for the extension. For the source code of the IBM Watson extension, contact us.
      1. The support team will provide you with the source code.
      2. You need to use the code from the index.html file located inside the root folder.
      3. Paste this code in the Extension source code field.
    • Config Parameter: Enter the configuration details for the extension. Here, you need to mention the AWS API gateway URL for the lambda function (in the ‘url’ parameter). If you have enabled API key for secured access, you need to mention that too.
          "url": "https://abcde1234.execute-api.
          "x-api-key": "SSS111Sss1ssSSsssS11s11SS11SS"
    • Scope: You can choose to incorporate this widget in either ‘All Content Types’ or ‘Specific Content Types’. Selecting the latter option displays a list of content types from which you can select the required ones.
  4. Click on Save. This will create your extension.

Now, let’s understand how to use this widget extension in your entries.

Step 5 - Use the extension

Once you have added this widget, you can use it in the entries of the selected content type(s). Let’s look at the steps involved in using this widget.

  1. Click on the content type for which you have enabled the custom widget.
  2. Click on an entry. You will see the Widgets dropdown on the top of the page, as shown in the image below.

    Selecting Widget Screen.png
  3. Click on it and select IBM Watson. The selected widget expands on the sidebar.
  4. Select a Field from the dropdown.
  5. Select a Model and click on Run. Based on the model selected, you will find the result on the sidebar.
    final text analytics screen sidebar 1.png

Once done using the widget, click on the close (x) button.

Was this article helpful?