'Dialogflow using external API with Axios
To study, I'm trying to make a bot that, in response to a request, will send an image. Used waifu pics api (https://waifu.pics/docs) just pictures. It sends the url, that's enough.
Gives the following errors:
Webhook call failed. Error: UNAVAILABLE, State: URL_UNREACHABLE, Reason: UNREACHABLE_5xx, HTTP status code: 500. Error: No responses defined for platform: DIALOGFLOW_CONSOLE at V2Agent.sendResponses_
Here is the code from index.js
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function welcome(agent) {
agent.add(`Welcome to my agent!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
//Its not-worked function
function AnimePicHandler(agent){
return axios.get(`https://api.waifu.pics/sfw/waifu`)
.then((result) =>
agent.add("result"));
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('AnimePic', AnimePicHandler);
agent.handleRequest(intentMap);
});
And here is from package.json
{
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "10"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"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",
"axios": "^0.27.2"
}
}
Solution 1:[1]
I´m on this same issue. My communication works. But the agent.add won´t do any effect.
In your case, add a catch statement, just to log addional info or error if occurr.
.catch((err) => {
console.error(err);
});
Also, try to loose this "return". As the examples of welcome and fallback functions. Just add to the agent at the end and do not return anything.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Giovani Luiz Giuberti |