I am trying to build a chatbot in Dialogflow connected to Hangouts. I am working on receiving files such as images.
I have found a youtube video about "How to receive image, audio, video and rich media on a WhatsApp chatbot (via dialogflow)". I have followed the instructions but something is not working.
This is my index.js code (Inline editor - Fulfillment):
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug';
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(`¡Bienvenido a mi chatbot! ¿Quieres subir un código QR?`);
}
function fallback(agent) {
agent.add(`Lo siento, no te he entendido.`);
agent.add(`¿Podrías repetir otra vez?`);
}
function mediaHandler(agent) {
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
let originalRequest = request.body.originalDetectIntentRequest;
agent.add(`Aquí tengo el archivo que me has mandado, gracias.` + originalRequest.payload.data.MediaUrl0);
});
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('Hangouts Media - fallback', mediaHandler);
agent.handleRequest(intentMap);});
These are my intents:
And this is the error:
Error: No handler for requested intent at WebhookClient.handleRequest (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:327:29) at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/srv/index.js:94:9) at cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:26:47) at /worker/worker.js:783:7 at /worker/worker.js:766:11 at _combinedTickCallback (internal/process/next_tick.js:132:7) at process._tickDomainCallback (internal/process/next_tick.js:219:9)
Finally, this is the 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": "^6.0"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^2.0.0-alpha.4",
"firebase-admin": "^4.2.1",
"firebase-functions": "^0.5.7",
"dialogflow": "^0.1.0",
"dialogflow-fulfillment": "^0.6.1",
"qrcode-decoder": "^0.1.2",
"xmlhttprequest": "^1.8.0",
"filereader": "^0.10.3"
}
}
Do you know how I can fix my error? Thank you in advance!