0

I am trying to use the openweathermap API with Watson Assistant, but I am getting "Webhook call was not successful. Response code is [404]. (and there is 1 more error in the log)."

(I am working from the book by Sabharwal, et al., with my own improvisations for the obsolete elements, like @sys-location.)

I created a Cloud Functions Action called "https://us-south.functions.appdomain.cloud/api/v1/web/my-account-email%40dev/default/Weather-Connection" and checked Enable as Web Action. The action code was imported from the git repo for the book:

let rp = require('request-promise')
function main(params) {
    const options = {
        uri: "http://api.openweathermap.org/data/2.5/weather?q=" + encodeURIComponent(params.object_of_interest)+ "&units=metric&APPID=19e8588cb3d7d0623e3a5a8ec529232f" ,
        json: true
    }
    return rp(options)
    .then(res => {
        WeatherReport = "Current Temperature : " +res.main.temp+ ", Pressure : " + res.main.pressure + ", Humidity : " + res.main.humidity + ", temp min : " + res.main.temp_min + " , temp max : " + res.main.temp_max
        return { WeatherReport
        } 
    })
}

In the Assistant Options the webhook URI is set to https://us-south.functions.appdomain.cloud/api/v1/web/my-account-email%40dev/default/Weather-Connection.json.

The "Assistant responds" JSON is The "Assistant responds" JSON is

{
  "output": {
    "text": {
      "values": [],
      "selection_policy": "sequential"
    }
  },
  "actions": [
    {
      "name": "/my-account-email%40dev/default/Weather-Connection.json",
      "type": "cloud_function",
      "parameters": {
        "object_of_interest": "$location"
      },
      "credentials": "$credentials",
      "result_variable": "$response"
    }
  ],
  "context": {
    "credentials": {
      "api_key": "[my-openweathermap-api-key]"
    },
    "object_of_interest": "@object_of_interest"
  }
}

For debugging, I included a dialog node that displays the value of $location, and it is okay (e.g. "London").

The "Try it out" pane prints {"cloud_functions_call_error":"The requested resource does not exist."} When I click on the Error icon I get a Runtime error pop-up saying, Direct CloudFunctions call was not successful. Http response code is [404]. (and there is 1 more error in the log).

I am not getting any output from running the CLI command ibmcloud fn activation list(I'm not sure that's the right way to check the logs).

I have tested the Weather-Connection function by invoking the Action with parameter {"object_of_interest": "London"}, and it works.

Everything is deployed in the same region (us-south) and namespace.

I can't think of anything else to try.

data_henrik
  • 16,724
  • 2
  • 28
  • 49
AltShift
  • 336
  • 3
  • 18
  • Correction: now I _am_ getting logs. The Status is coming back as `application error` – AltShift Jun 20 '21 at 07:32
  • "response": { "status": "application error", "statusCode": 0, "success": false, "result": { "error": { "error": { "cod": "400", "message": "bad query" }, – AltShift Jun 20 '21 at 07:39
  • You can check activitations and also invoke using the browser UI for Cloud Functions: https://cloud.ibm.com/functions/dashboard – data_henrik Jun 20 '21 at 12:14
  • Check what was passed from Watson Assistant to the Function, whether the received payload has the expected format. – data_henrik Jun 20 '21 at 12:17
  • Thanks @data_henrik. The logs show there is an argument "q=undefined", which says to me that the value of the location variable isn't making it into the request. I'll keep digging. – AltShift Jun 22 '21 at 09:44
  • This IBM Cloud solution tutorial passes variables to Cloud Functions. The workspace is provided on GitHub. In case you want to see a working sample. https://cloud.ibm.com/docs/solution-tutorials?topic=solution-tutorials-slack-chatbot-database-watson – data_henrik Jun 22 '21 at 10:52
  • Thanks. I figured out why the location wasn't getting passed to the cloud function, and now the activation log shows that I am getting a correct response. However, Watson Assistant still throws a 404 code and there seems to be nothing in the webhook result. – AltShift Jun 26 '21 at 04:08

1 Answers1

0

I just cracked it. I was trying to show the result using the text response is <? $webhook_result_1.response ?> when it should just have been response is <? $webhook_result_1 ?>.

AltShift
  • 336
  • 3
  • 18