Hi,
We used the below code to handle actions on google. This has stopped working after the latest release. Can you please tell what changed.
Here is sample code of the intent handler which is no longer working:
function agent_conv_test(agent){
const conv = agent.conv();
conv.ask("testing agent conv...");
agent.add(conv);
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('agent_conv_test', agent_conv_test);
Below is the error it throws.
TypeError: Cannot read property 'forEach' of undefined at V2Agent.addActionsOnGoogle_ (/user_code/node_modules/dialogflow-fulfillment/src/v2-agent.js:284:28) at WebhookClient.addResponse_ (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:239:19) at WebhookClient.add (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:225:12) at agent_conv_test (/user_code/index.js:86:13) at WebhookClient.handleRequest (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:273:44) at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:96:9) at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:47) at /var/tmp/worker/worker.js:689:7 at /var/tmp/worker/worker.js:673:9 at _combinedTickCallback (internal/process/next_tick.js:73:7)
Also this link https://github.com/dialogflow/dialogflow-fulfillment-nodejs/blob/master/docs/WebhookClient.md is no longer working. Would have been nice to redirect to the new or corresponding page.
@amit-dp What are your listed dependencies and versions in package.json?
It didnt seem to matter what combination of dependencies I use. But here
goes
"dependencies": {
"actions-on-google": "^2.2.0",
"firebase-admin": "^4.2.1",
"firebase-functions": "^0.5.7",
"dialogflow": "^0.7.0",
"dialogflow-fulfillment": "^0.6.0"
}
On Mon, Oct 8, 2018 at 11:47 PM Sarah Dwyer notifications@github.com
wrote:
@amit-dp https://github.com/amit-dp What are your listed dependencies
and versions in package.json?—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/149#issuecomment-427931218,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AE6IWpSynf1zURKyeNJrMdwSLQYZkc6Dks5ui5aPgaJpZM4XNVm8
.
--
Amit Deshpande |
Vice President, India Development Center | SpringML
http://www.springml.com/?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature
https://zoom.us/webinar/register/WN_EFV5Ie7FQWSHSdJ6v7iyVA?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature
Tensorflow for Manufacturing Quality Control
https://springml.com/2018/04/19/tensorflow-manufacturing-quality-control/?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature
same problem.
My code like:
cons _text = 'bye.';
const conv = agent.conv();
conv.close(_text);
agent.add(conv);
then catch exception:
Response has already been digested at DialogflowConversation.response (/user_code/node_modules/actions-on-google/dist/service/actionssdk/conversation/conversation.js:194:19) at DialogflowConversation.serialize (/user_code/node_modules/actions-on-google/dist/service/dialogflow/conv.js:159:109) at WebhookClient.addResponse_ (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:269:48) at WebhookClient.add (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:245:12) at agentEnd (/user_code/index.js:110:10) at stopDongle (/user_code/index.js:122:4) at co.catch (/user_code/index.js:830:3) at process._tickDomainCallback (internal/process/next_tick.js:135:7)
agent: v2
dependencies:
"dependencies": {
"actions-on-google": "^2.1.3",
"axios": "^0.18.0",
"co": "^4.6.0",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.5.0",
"firebase-admin": "^4.2.1",
"firebase-functions": "^0.5.7",
"fuzzyset.js": "0.0.7",
"lodash.result": "^4.5.2",
"md5": "^2.2.1"
}
I have the same problem. Using version 2.4.0 seemed to resolve the issue for me.
"dependencies": {
"actions-on-google": "2.4.0",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.5.0",
"cheerio": "^1.0.0-rc.2",
"request-promise-native": "^1.0",
"request": "^2.87"
}
Thanks for the report everyone. We have reproduced the issue and will issue a fix shortly.
workaround is:
const data = conv.serialize();
agent.add(new Payload(
'ACTIONS_ON_GOOGLE',
data.payload.google)
);
any update on this? workarounds mentioned in this thread don't work for me unfortunately,
even the one I just mentioned @barisssss ? What goes wrong?
if i got you right, i should do something like this:
let conv = agent.conv();
conv.ask("hello world");
const data = conv.serialize();
agent.add(new Payload("ACTIONS_ON_GOOGLE", data.payload.google));
unfortunately that gives me the same error as before.
The suggestion by izactherobot80 should help as a workaround.
I am facing the same problem, I am working on a firebase function with dialogflow-fulfillment library, I am testing on simulator provided by DF console.
My code is as follows:
let conv = agent.conv();
console.log(' ---- conversation BEFORE ----- ' + JSON.stringify(conv));
conv.close(strOutput);
console.log(' ---- conversation AFTER CLOSE ----- ' + JSON.stringify(conv));
agent.add(conv); // error, but if you use strOutput it works fine
// error Cannot read property 'forEach' of undefined at V2Agent.addActionsOnGoogle
*/
resolve(agent);
I tried also the workaround:
let conv = agent.conv();
const data = conv.serialize();
agent.add(new Payload('ACTIONS_ON_GOOGLE',data.payload.google)
);
resolve(agent);
but I receive the same error...
These are the dependencies:
"dependencies": {
"actions-on-google": "^2.4.0",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.5.0"
}
Any help would be appreciated, thanks in advance
I had the same error, but changing dependencies at package.json file solved the problem. My dependencies right now are the following:
"dependencies": {
"actions-on-google": "^2.5.0",
"dialogflow": "^4.0.3",
"dialogflow-fulfillment": "^0.6.1",
"firebase-admin": "^6.4.0",
"firebase-functions": "^2.1.0"
},
Yes, you will need to update the dialogflow-fulfillment package dependency to "^0.6.1"
ok updated the dependencies, but now i am receiving the error
typeError: Cannot read property 'ask' of null
at agent_conv_test (/user_code/index.js:35:5)
at WebhookClient.handleRequest (/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:313:44)
at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/user_code/index.js:43:7)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:57:9)
at /var/tmp/worker/worker.js:724:7
at /var/tmp/worker/worker.js:707:11
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
this is the code in index.js
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((req, res) => {
const agent = new WebhookClient({ request: req, response: res});
function agent_conv_test(agent){
let text = 'bye!';
const conv = agent.conv();
conv.ask(text);
conv.close(text);
agent.add(conv);
}
let intentMap = new Map();
intentMap.set('test_fb', agent_conv_test);
agent.handleRequest(intentMap);
});
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.5.0",
"firebase-functions": "^2.1.0",
"firebase-admin": "^6.4.0",
"dialogflow": "^4.0.3",
"dialogflow-fulfillment": "^0.6.1"
}
}
what am i doing wrong?
thanks in advance
@valeadami In the future, it's appreciated if Github issues is a place solely for direct errors with the library itself.
The error you're seeing is because you're using elements from the Actions on Google library (i.e. conv.ask, conv.close, any references to the conv object, etc.). If you're interested in using Actions on Google, please refer to the official Actions on Google repo on Github. Keep in mind you can import many Dialogflow features using the Actions on Google library, if that's something you had in mind.
If, however, you'd like to use Dialogflow's library, then the code below will work.
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug';
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((req, res) => {
const agent = new WebhookClient({ request: req, response: res});
function agent_conv_test(agent){
let text = 'bye!';
agent.add(text);
}
let intentMap = new Map();
intentMap.set('test_fb', agent_conv_test);
agent.handleRequest(intentMap);
});
ok got it, thanks!
@valeadami I'm combining both libaries and it is working fine. Try adding this at the begining (with the other "require"), so you can use those elements from actions on google library:
const {
dialogflow,
SimpleResponse,
BasicCard,
Suggestions,
Permission,
UpdatePermission,
RegisterUpdate,
} = require('actions-on-google');
And in the functions, use "let" instead of "const" to declare "conv":
let conv = agent.conv();
Hope this work for you too.
ok thanks!
In my case, only updating the dialog-fulfillment worked. Here are my versions:
"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"
In my case, only updating the dialog-fulfillment worked. Here are my versions:
"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"
In the package.json changing dialogflow-fulfillment to 0.6.1 & adding the line agent.requestSource = agent.ACTIONS_ON_GOOGLE; worked for me. (where agent is initialized with const agent = new WebhookClient({ request, response });)
ok thanks!
@valeadami In the future, it's appreciated if Github issues is a place solely for direct errors with the library itself.
The error you're seeing is because you're using elements from the Actions on Google library (i.e. conv.ask, conv.close, any references to the conv object, etc.). If you're interested in using Actions on Google, please refer to the official Actions on Google repo on Github. Keep in mind you can import many Dialogflow features using the Actions on Google library, if that's something you had in mind.
If, however, you'd like to use Dialogflow's library, then the code below will work.
'use strict'; const functions = require('firebase-functions'); const {WebhookClient} = require('dialogflow-fulfillment'); process.env.DEBUG = 'dialogflow:debug'; exports.dialogflowFirebaseFulfillment = functions.https.onRequest((req, res) => { const agent = new WebhookClient({ request: req, response: res}); function agent_conv_test(agent){ let text = 'bye!'; agent.add(text); } let intentMap = new Map(); intentMap.set('test_fb', agent_conv_test); agent.handleRequest(intentMap); });
I have some issue after console.log() aagent.add is not working. here is detailed description https://stackoverflow.com/questions/57678290/error-agent-add-function-is-not-working-i-e-not-getting-output-value-to-user
I have having similar problem then eventually realized:
1) testing in Dialogflow framework was failing
2) testing in Google Assistant (actions on google) worked
Move explicitly, in Dialogflow, the conv object was null. when using actions on google test framework, in came back as a propper object with associated properties. This may not the be the whole issue here, but knowing this distinction helped me work out other bugs.
(tl;dr: the request needs to originate from Google Assistant or any platform that becomes actions-on-google or it'll null out as folks are experiencing)
@koshnick & for anyone stumbling on this issue (ie Cannot read property 'ask' of null) in the future:
Here's the "problem" on line 460:
The reason it's failing from "DialogFlow framework" (I'm presuming you mean the DialogFlow simulator in web console) and working when you test from Google Assistant is because the DialogFlow simulator DOES NOT pass its request/platform as "actions on google" (it's not Google Assistant, so makes sense it really shouldn't)
Dialogflow-fulfillment actually uses actions-on-google internally to access that conv object: https://github.com/dialogflow/dialogflow-fulfillment-nodejs/blob/3a849641108746eb95e84f71294c8a51befa18c6/src/common.js#L16
Bottom line: if the originating service isn't Google Assistant or something that would have "Actions-on-Google" as its platform, the agent.conv() returns null
What to do about this:
1) Use Google Assistant or a platform/service that uses it
2) Cheat
Here's a sample that would work as a fulfillment as a cloud function if there's an issue with platform/request source:
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = 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 });
function googleAssistantHandler(agent) {
agent.requestSource = agent.ACTIONS_ON_GOOGLE;
let conv = agent.conv();
conv.ask('Hello from the Actions on Google client library!');
agent.add(conv);
}
let intentMap = new Map();
const intentName = 'my intent 123';
intentMap.set(intentName, googleAssistantHandler);
agent.handleRequest(intentMap);
});
I'm getting this issue once I set dependency for npm axios in package.json at Dialogflow.

Please help in this.
@abhinaysingh40 -- Looks like an unrelated JSON syntax issue. Try pasting that package.json here & check for errors: https://jsonlint.com/
If still having trouble, maybe check out a resource like SO
i get -- Error - 11200 HTTP retrieval failure in twilio console
what's that mean ?
using twilio in firebase functions
I had the same error, but changing dependencies at package.json file solved the problem. My dependencies right now are the following:
"dependencies": {
"actions-on-google": "^2.5.0",
"dialogflow": "^4.0.3",
"dialogflow-fulfillment": "^0.6.1",
"firebase-admin": "^6.4.0",
"firebase-functions": "^2.1.0"
},
Thanks for the help it solved my issue
Most helpful comment
I had the same error, but changing dependencies at package.json file solved the problem. My dependencies right now are the following:
"dependencies": {
"actions-on-google": "^2.5.0",
"dialogflow": "^4.0.3",
"dialogflow-fulfillment": "^0.6.1",
"firebase-admin": "^6.4.0",
"firebase-functions": "^2.1.0"
},