You can query for dynamic data using webhooks in IBM Watson Assistant. Our crisis communication chatbot uses two different sources:
- Create an IBM Cloud Account.
- Create a Watson Assistant COVID-19 crisis communications chatbot. Follow these instructions
- Create a Weather Company API Account
- From your IBM Cloud account, go to Watson Discovery.
- Create a new lite service.
- 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.
-
Signup with your info. Your API key will be emailed to you.
-
Save the API key for future use.
-
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
and location=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 in double quotes:
api_key
(Discovery API Key)twcApiKey
(API key from The Weather Company)url
(Discovery Service URL)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.
- For detailed instructions on how to do this, check out our documentation: Making Programmatic Calls from Watson Assistant.
- 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 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.