Weather as a "Function" of Clouds
Hickmat 100000QA3T Visits (1498)
Following on from the success I had driving API calls from Watson Assistant as described in my last 2 posts, I wanted to look at how this approach could translate to the BETA capability in Watson Assistant to allow programatic calls to be performed from with in Watson Assistant.
If you are not familiar with this capability please see here. This capability has two modes of satisfying the request to execute a call:
Given that my previous approach was VERY similar to "Client Managed" I decided to focus on the "Server Managed" approach. With this approach the code to be invoked is created as an IBM Cloud Function "Action" where this "Action" is passed a set of parameters as defined in the Watson Assistant Action JSON structure in Dialog. The response from the IBM Cloud Function call is stored in the context variable denied in the dialog node making the call.
To help visualise this here is an example of the JSON for one of the dialog nodes I created to test this:
In this JSON you can see how the invocation type is specified and the style for defining parameters and how to manage results. In addition you can see that the credentials that are need to successfully call the IBM Cloud Function are passed. In my case I followed the approach documented in the article above and created a "creds" object in the context to hold the "user" and "password". Final thing to note is that the IBM Cloud Function to be called must be present in the same IBM Cloud Datacenter as the Watson Assistant Service instance you are using. In my case my Watson Assistant instance is hosted in US South and hence that's where I deployed my IBM Cloud Function.
With the background covered lets get to the details. Firstly I took the code I'd written to support my last post from my wrapper code and refactored it to be a cloud function. This was a trivial task and the only research I had to do was how to package up my function as I needed to include some NPM modules. A quick search through the docs showed that I could package my code as a ZIP and that could then be deployed to the IBM Cloud - simple. So what did the code look like...
Here you can see that I am taking the same approach I described in the last post in that I am using APIC as the layer to handle all the API mappings and in this way I can have a single simple IBM Cloud Function which simple routes requests to a specified API endpoint and does not need to be concerned about mapping. One change I did need to make was that I couldn't find a way to pass the entire conversation context across so I have opted for creating a holder context variable which contains the inputs and is updated with the results.
From the Watson Assistant side the flow looks pretty much the same...
but the dialog for "Get Location" and "Get Weather" needed to be updated to make the "Action" call. In addition the other nodes were modified to handle the data being in the "api" context variable rather than just being directly in the context. The following screen shots give a view on how I configured all the dialog nodes from "Get Location" down.
Reply with Weather
Clear out API
With the reworked dialog in place I could recreate the say conversation experience as I showed in the previous post. So my work here is done for now. As a bit of fun I'm thinking about seeing if I can make call outs to a set of TP-Link smart plugs I have at home - why? Because I can If I get that working then I may do a post covering it.