In times of crisis, chatbots can help people quickly find answers they need to critical questions. In the case of a pandemic like COVID-19, people might be trying to find basic information about testing, symptoms, community response, and other resources.
This tutorial shows you how to create a crisis communication chatbot using IBM® Watson™ Assistant and how to add webhooks to Watson Assistant to query for dynamic data using Watson Discovery and COVID-19 APIs.
Learning objectives
In this tutorial, you will:
- Provision an instance of Watson Assistant
- Add a dialog skill to your Watson Assistant instance
- Connect your Watson Assistant with Watson Discovery
- Create Cloud Functions
- Integrate data sources via a Watson Assistant webhook
Prerequisite
Register for an IBM Cloud account.
Estimated time
This tutorial takes about 40 minutes to complete.
Create your chatbot by setting up a Watson Assistant instance
We show you how to create a chatbot using Watson Assistant, a tool that enables you to build conversational interfaces into any application, device, or channel.
In the IBM Cloud catalog, navigate to the Services and provision an instance of Watson Assistant.
Launch the Watson Assistant service.
Click Create assistant and follow these detailed instructions for how to create an assistant.
Name the Watson Assistance instance COVID Crisis Communication.
Click Add dialog skill to the assistant. Follow the documentation if you have questions.
Click Import Skill > Choose JSON file and import the
Covid Json
file.Go back to All Assistants page. From the action menu (
⋮
), open Settings.On the Settings tab, click API Details on the left and make a note of the
Assistant ID
andAPI Key
for future use.Go back to the All Assistants page and click on the Skills link.
On the Skill page, click on the action menu ( ⋮ ) and open View API Details.
On the Skill Details page, make note of the Skill ID for future use.
Go back to your dialog skill and click on the Preview Link button on the side to get a link to test and verify your assistant.
Ask the Watson Assistant chatbot some questions about COVID-19.
Integrate your chatbot with data sources
Now that you’ve created your Watson Assistant-enabled chatbot, you need to connect it to a data source. The following section shows you how to do that by adding webhooks to Watson Assistant that query for dynamic data.
Our crisis communication chatbot uses three different data sources:
Defining webhooks
First, let’s look at what webhooks do. A webhook is a mechanism that allows you to call out to an external program based on something happening in your program. When used in a dialog skill, a webhook is triggered when the assistant processes a node that has a webhook enabled. The webhook collects data that you specify or that you collect from the user during the conversation and saves in context variables.
It sends the data as part of a HTTP POST request to the URL that you specify as part of your webhook definition. The URL that receives the webhook is the listener. It performs a predefined action using the information that you pass to it as specified in the webhook definition, and can optionally return a response.
Make use of Watson Discovery to get news information
From your IBM Cloud account, go to Watson Discovery.
Create a new lite service by clicking Create.
Make note of the API key and the URL. You need that in the next steps.
Open the Watson Discovery NEWS service, which is a prepopulated discovery dataset updated and maintained by the Watson Discovery team.
From the top right corner, open the API tab. Make note of the Collection ID and Environment ID.
Get a Weather Company API key
You need an API key to use The Weather Company API for COVID-19 Disease Tracking. Call for Code participants can read the Terms of Service and register to join the Call for Code 2020 COVID Challenge and request a TWC API key.
Sign up for an API key with your information. Your API key will be emailed to you.
Save the API key for future use.
Create Cloud Functions
In the IBM Cloud catalog, go to IBM Cloud Functions.
Click Start Creating.
Select Create Action.
Name your action. For the Runtime dropdown, select Node.js 10.
Replace the code with action/covid-webhook.js
Our code has two main parts. We decide whether to call the COVID-19 API or Watson Discovery based on a parameter sent on the function call. If a query param of
type=api
is set, you call the COVID-19 api on the summary endpoint.It returns the data in the following format:
{ Countries: [ { Country: "", Slug: "", NewConfirmed: 0, TotalConfirmed: 0, NewDeaths: 0, TotalDeaths: 0, NewRecovered: 0, TotalRecovered: 0 }, { Country: " Azerbaijan", Slug: "-azerbaijan", NewConfirmed: 0, TotalConfirmed: 0, NewDeaths: 0, TotalDeaths: 0, NewRecovered: 0, TotalRecovered: 0 }, ... ] }
If there is specific location (Country/Country Code/US State) selected, you look for that location either using The Weather Company API or in the summary response and return the status for that location.
For example, the response for
type=api
andlocation=United States of America
is shown below.{ "result": "Total Cases: 65778\nTotal Deaths: 942\nTotal Recovered: 361\n\nSource: Johns Hopkins CSSE" }
If you want to make a call to the Discovery service, you need to set some parameters that let you call the IAM-enabled service. On the left, click on the Parameters tab. Add the following parameters:
api_key
(Discovery API key)twcApiKey
(API key from The Weather Company)url
(URL to your Discovery service instance)collection_id
env_id
Enable the action as a web action. To do so, select the Endpoints tab on the left. Click the checkbox beside Enable as Web Action.
Make note of the HTTP URL. You will use this as the webhook for your assistant. You will have to add
.json
in the end of this URL to make it work as a webhook.
Integrate data sources via a Watson Assistant webhook
For detailed instructions on how to integrate data sources via a webhook, check out our documentation: Making Programmatic Calls from Watson Assistant.
Here are the specific steps to add a webhook to your COVID-19 chatbot.
Bring up the COVID-19 assistant you created earlier. Find it in your IBM Cloud account under Services > IBM Watson Assistant. Open the dialog by clicking the
CDC COVID FAQ
Dialog.Click on Options on the left.
Under Options > Webhooks, in the URL text box, paste the URL from the Cloud Funciton step. Make sure to add a
.json
at the end of the URL.Select Dialog on the left navigation.
Open up any dialog node you want to add a webhook call for.
After selecting the node, click Customize.
Enable your webhooks by moving the toggle button to On in the Webhooks section. Click Save.
Add any parameter your webhook needs. These will be sent as query parameters.
Test that your webhook integration is working by going to the Try It tab and initiating a dialog that calls the webhook.
You can easily use webhooks to give your Watson Assistant access to many external APIs and databases.
Next steps
Now that you know how to create a COVID-19 chatbot and connect it to Watson Discovery and the COVID-19 API, there are a few different integration paths you can take. The following tutorials show you how to integrate this chatbot with Slack, with a simple web application, or with a Node-RED dashboard.
- Embed your COVID-19 chatbot on a website
- Integrate your COVID-19 chatbot with Slack
- Integrate your COVID-19 chatbot with Node-RED to enable voice commands
Take on COVID-19
You now know how to build a chatbot using Watson Assistant and connect it to Watson Discovery and a COVID-19 API data source that serves up timely information about this pandemic. It’s your turn to use these technologies to help tackle this pandemic and make a difference by accepting the COVID-19 challenge!