I'm new to using Dialogflow and Google Cloud Functions in general.
I've managed to set up the Inline Editor and a function for when an Intent is called. The plan is to send simple POST requests when a certain Intent is triggered. To test this I am trying to use the fetch API and display the status code. The function looks like this:
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const fetch = require('node-fetch');
.
.
.
.
function endConversation(agent) {
var status = '';
fetch('https://google.com')
.then(response => {
console.log('response.status: ', response.status); //200
console.log(response);
status = response.status;
agent.add(status);
})
.catch(err => {
console.log(err);
agent.add(err);
});
}
package.json:
"dependencies": {
"actions-on-google": "^2.2.0",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.6.1",
"node-fetch": "^2.7.0"
}
When the intent is triggered the chat bot agent displays "Not available" and under diagnostic info -> Raw API response I see this error:
"webhookStatus": {
"code": 14,
"message": "Webhook call failed. Error: UNAVAILABLE, State: URL_UNREACHABLE, Reason: UNREACHABLE_5xx, HTTP status code: 503."
}
Looking at the Google Cloud Functions Logs I see following errors: Google Cloud Functions Logs
Does anybody understand what is happening here?
I tested different URLs and could successfully run the js code in other environments.
Ok so I managed to get it working, I changed the endConversation() function to:
I guess it has something to do with not being able to use async functions with Google Cloud Functions? Maybe somebody understands what excatly makes one function work and the other not, feel free to comment.