How do I connect my external API to Watson Assistant?
When you're building your chatbot it's not uncommon to need to connect it to an external API. Whether that's combining menu items and ingredient lists, spitting out weather information, or even playing back your favorite music there's always a place for an external API. IBM's Watson has neat and simple tools that make connecting your Watson bot to an external API simple. Today Elite is here to show you how in just a few simple steps but it is crucial to note before we start that Watson can only use an external API if the call and callback are in JSON format.
- Log in to your IBM cloud.
- Choose your service and launch tool.
- Choose your desired assistant.
- Choose your desired dialog skill.
Now that you're logged in and ready to begin, let's go through the steps on actually connecting your API.
- Connecting your API link to Watson assistant
- Create intents & dialog nodes for your API
- Switching on your Webhook
- Calling back your API info in the dialog node
- Try it out
Open the options tab on the left-hand side and click on webhooks. Place in your API URL.
For this, we are using breakfast and lunch as intents which we have set up to trigger when someone asks the bot what's for either breakfast or lunch.
Open up your desired dialog node that you would like to set up directly to your API, here we are using our Breakfast and Lunch nodes. At the top in the upper right-hand corner select customize, find the webhooks section and switch it to on, then apply.
Once your webhook is turned on you'll need to type in a simple phrase to get your assistant to respond with your API information (in this case either a breakfast or lunch menu item.) In the "respond with" section you'll need to use the phrase: $webhook_result_1.(key)
In this case, ours will look like this:
.food is the key.
Don't be shy, try it out can be found in the upper right-hand corner, or you can test it out directly.
After completing these steps your bot will be connected to your external API. Going off of the image from Step 5 we can see that asking Ellie "What's for breakfast?" she now responds with "eggs" straight from our api without having to put it directly into Watson dialog.