I'm trying to create a webhook that will get the Intent and current state, change the state, and send back a reply using actions-on-google library for node.js.
index.js is as follows:
'use strict';
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const app = dialogflow({debug: true});
app.intent('welcome', conv => {
let replyState = setReplyState( conv, 'prompt' );
let intent = getIntentName( conv );
sendReply( conv, intent, replyState );
});
function getReplyState( conv ){
return conv.data['replyState'];
}
function setReplyState( conv, state ){
conv.data['replyState'] = state;
return state;
}
function getIntentName( conv ){
return conv.intent;
}
const welcomeReplies = [
"Welcome!"
];
const allReplies = {
welcome: welcomeReplies,
};
function sendReply( conv, intent, replyState ){
let repliesNamed = replyState;
let replies = allReplies[repliesNamed];
conv.add( reply );
}
exports.fulfillment = functions.https.onRequest(action);
package.json is as follows:
{
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "8"
},
"dependencies": {
"firebase-admin": "~6.0.0",
"firebase-functions": "^2.0.3",
"actions-on-google": "~2.5.0"
},
"private": true
}
Error occurred:
MalformedResponse Failed to parse Dialogflow response into AppResponse because of invalid platform response: Could not find a RichResponse or SystemIntent in the platform response for agentId: ab93fe46-9eb1-4a6c-aea7-1699d67d7369 and intentId: 1ec758db-d03a-40b7-85fe-189d9245e6e2.
I referred https://github.com/afirstenberg/examples/tree/master/conversation-to-code-2-aog
You don't show the function execution log, but it looks like action
isn't defined anywhere, so the call functions.https.onRequest(action);
returns an error.
In the source you're working from, action
is defined as
const action = dialogflow();
and all the Intent Handlers are registered with
action.intent(...)
While you have a similar definition
const app = dialogflow({debug: true});
so you can probably change the line that defines the function to
exports.fulfillment = functions.https.onRequest(app);
to resolve your immediate problem.