The Expected version "^8.11.2 || >=9.4" the maximum AWS Lambda offers is 8.10.
Greetings! This module only requires nodejs 6 and up:
https://github.com/googleapis/nodejs-dialogflow/blob/master/package.json#L8
Are you running into a specific issue while trying it with that version of 8?
I am facing an error with the google-gax module:
/Users/knowledge/Developer/alda-dialogflow/node_modules/google-gax/build/src/path_template_parser.js:304
if (input.charCodeAt(peg$currPos) === 47) {
^
TypeError: input.charCodeAt is not a function
at peg$parsetemplate (/Users/knowledge/Developer/alda-dialogflow/node_modules/google-gax/build/src/path_template_parser.js:304:17)
at Object.peg$parse [as parse] (/Users/knowledge/Developer/alda-dialogflow/node_modules/google-gax/build/src/path_template_parser.js:633:18)
at new PathTemplate (/Users/knowledge/Developer/alda-dialogflow/node_modules/google-gax/build/src/path_template.js:55:54)
at segments.forEach.segment (/Users/knowledge/Developer/alda-dialogflow/node_modules/google-gax/build/src/path_template.js:120:29)
at Array.forEach (<anonymous>)
at PathTemplate.render (/Users/knowledge/Developer/alda-dialogflow/node_modules/google-gax/build/src/path_template.js:114:23)
at SessionsClient.sessionPath (/Users/knowledge/Developer/alda-dialogflow/node_modules/dialogflow/src/v2/sessions_client.js:320:52)
at Object.<anonymous> (/Users/knowledge/Developer/alda-dialogflow/handler.js:8:35)
at Module._compile (internal/modules/cjs/loader.js:736:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:747:10
First I thought it would be a problem with the node version. The error message is not helping me.
I made a simple example:
'use strict';
const dialogflow = require('dialogflow');
const sessionClient = new dialogflow.SessionsClient();
const projectId = 'alda-57116'
const languageCode = 'es'
const sessionId = 1
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
const request = {
session: sessionPath,
queryInput: {
text: {
text: query,
languageCode: languageCode,
},
},
};
sessionClient.detectIntent(request).then(res => {
console.log(res[0].queryResult.fulfillmentMessages)
})
and supsect that something is wrong with my service-account authentification.
In principle I created a service-account-key, retrieved a .json file and mapped the GOOGLE_APPLICATION_CREDENTIALS environmental variable to the .json file.
This is just a horrific error message that means you haven't passed a project Id :/ We need to fix that. Can you verify that you're either a.) Using a service account key that has a project id in it or b.) setting the GCLOUD_PROJECT env var?
Still not working. I did the following:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/[FILE_NAME].json"
export GCLOUD_PROJECT="test-123456"
and the error still occurs. I am also confused of the fact that I have to set the Google Project Id two times? One time in the code const sessionPath = sessionClient.sessionPath(projectId, sessionId); and one time in the environment?
A part from that I am pretty sure that there is a dependency that needs a higher version of node than 8.10:
mkdir lol
cd lol
nvm use 8.10
node --version => v8.10.0
yarn add dialogflow
error @grpc/[email protected]: The engine "node" is incompatible with this module. Expected version "^8.11.2 || >=9.4".
error Found incompatible module
so grpc is also causing troubles.
Anyways I got it working by trying your quicksample.js:
const dialogflow = require('dialogflow');
const uuid = require('uuid');
/**
* Send a query to the dialogflow agent, and return the query result.
* @param {string} projectId The project to be used
*/
async function runSample(projectId = 'your-project-id') {
// A unique identifier for the given session
const sessionId = uuid.v4();
// Create a new session
const sessionClient = new dialogflow.SessionsClient();
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: 'hello',
// The language used by the client (en-US)
languageCode: 'en-US',
},
},
};
// Send request and log result
const responses = await sessionClient.detectIntent(request);
console.log('Detected intent');
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(` Intent: ${result.intent.displayName}`);
} else {
console.log(` No intent matched.`);
}
}
// [END dialogflow_quickstart]
const args = process.argv.slice(2);
if (args.length !== 1) {
console.error(`
USAGE:
node quickstart.js <projectId>
EXAMPLE:
node quickstart.js my-project-id
You can find your project ID in your Dialogflow agent settings: https://dialogflow.com/docs/agents#settings.
`);
process.exit(1);
}
I do not know where this differs from my code but I am good for know!
Thanks for your help ;)
BTW I know what was causing the error!
The sessionId has to be a String in sessionClient.sessionPath(projectId, sessionId).
In my code I passed the function a integer, which you should consider accepting as well:
sessionClient.sessionPath(projectId, 1)
Changing it to a string also fixed the issue here.
Strange that the official docs and example are saying the following:
sessionId: Random number or hashed user identifier
Most helpful comment
BTW I know what was causing the error!
The sessionId has to be a String in
sessionClient.sessionPath(projectId, sessionId).In my code I passed the function a integer, which you should consider accepting as well:
sessionClient.sessionPath(projectId, 1)