Up until now we required an external custom component in order to implement any backend integration.
But starting with 22.06, we have an easier way to simplify backend integration, with the ability to call a REST service from within the dialog flow, where we have a new state for that purpose.
Important to note that this is aimed at simple integrations. If one still needs extensive transformation and/or orchestration, the customer component is the ideal choice.
If your skill needs to retrieve or update some data through a backend service, you can quickly implement this by adding a REST service configuration for the API’s endpoint and calling that service from your skill using the Call REST Service component.
https://docs.oracle.com/en/cloud/paas/digital-assistant/use-chatbot/backend-integration1.html#GUID-1992F05A-0336-4AFE-B9DE-FDBE2AFFB377
Add an API Service
The first thing we need to do is to add a new API Service! For this example I will use an open weather API to test.
We provide a Name and an Endpoint with the optional Methods (which can be updated later)
This API has an API Key as authentication type. This ODA registry supports other types as well.
The weather API has a couple of query parameters which I define here.
We can test the service and even save the response as a static element (for development)
How to call the REST service from the Visual Flow Designer
II will create a small dialog that:
- Asks user for the desired location for which he wants to see the weather
- Calls the REST service
- Displays the temperature back to the user
This is the final layout of the flow.
The first step is a simple component – ask question – which is a simpler template of a common response component. Here I create a variable, which will hold the input from the user. In this case location, or city.
Now we can add the new component called – Call REST Service.
The configuration follows most of what we configured in the first step.
The main difference is that we map the city variable to the query parameter, and map the response to another variable. These variables can be created from this screen as well.
Final state is an output, which will write back to the user the below text, where we fetch the temperature from the response JSON that comes back from the weather API service. I created the apache freemarker expression from the sample response.
Moment of truth
And this ran easily on the test mode, quite fast, and extremely simplified implementation – compared with the custom component. The only ‘hard’ part was the freemarker expression, but if you have some practice with it, it should not be a challenge.
As mentioned before, this is meant for simple(r) backend calls. If there is a need for more complex transformations/orchestrations, then the best approach is to use a custom component.