Google-api-nodejs-client: Dialogflow V2 API sample

Created on 1 Jun 2018  路  3Comments  路  Source: googleapis/google-api-nodejs-client

Hi!
Can we have a Dialogflow V2 API sample?
Thanks!

question web

Most helpful comment

@JustinBeckwith there's issues with the dialogflow-nodejs-client-v2, one we found is we can't use it on AWS Lambda without loads of workarounds as we're webpacking our deps to minimize the size of them.

google-api-nodejs-client is all Axios REST so doesn't require dynamically loaded protobuf files from locations on the filesystem, so makes sense to use it instead of complex Webpack configurations/file copying.

@joseparoli Here's simple example. Took me ages to work out how to do it - the path parameters were confusing as you expect it to just be [projectId] (see the parent param)...but its more like a url path: /projects/[projectId]. Once you've got that down you can always find them at the top of the docs e.g. here

````
'use strict';

const {google} = require('googleapis');
const path = require('path');

async function runSample () {

const client = await google.auth.getClient({
keyFile: path.join(__dirname, 'key.json'),
scopes: 'https://www.googleapis.com/auth/cloud-platform'
});

const dialogflow = google.dialogflow({
version: 'v2',
auth: client
});

const result = await dialogflow.projects.getAgent({
parent: 'projects/'
});

console.log(result.data);

}

if (module === require.main) {
runSample().catch(console.error);
}

// Exports for unit testing purposes
module.exports = { runSample };
````

All 3 comments

Greetings! If you're using Dialogflow, I would highly recommend using this library instead :)
https://github.com/dialogflow/dialogflow-nodejs-client-v2

@JustinBeckwith there's issues with the dialogflow-nodejs-client-v2, one we found is we can't use it on AWS Lambda without loads of workarounds as we're webpacking our deps to minimize the size of them.

google-api-nodejs-client is all Axios REST so doesn't require dynamically loaded protobuf files from locations on the filesystem, so makes sense to use it instead of complex Webpack configurations/file copying.

@joseparoli Here's simple example. Took me ages to work out how to do it - the path parameters were confusing as you expect it to just be [projectId] (see the parent param)...but its more like a url path: /projects/[projectId]. Once you've got that down you can always find them at the top of the docs e.g. here

````
'use strict';

const {google} = require('googleapis');
const path = require('path');

async function runSample () {

const client = await google.auth.getClient({
keyFile: path.join(__dirname, 'key.json'),
scopes: 'https://www.googleapis.com/auth/cloud-platform'
});

const dialogflow = google.dialogflow({
version: 'v2',
auth: client
});

const result = await dialogflow.projects.getAgent({
parent: 'projects/'
});

console.log(result.data);

}

if (module === require.main) {
runSample().catch(console.error);
}

// Exports for unit testing purposes
module.exports = { runSample };
````

Thanks for sharing the code sample, and thanks for sharing your reasoning. Just as a heads up - now that we ship TypeScript types, you can always look at the typed parameter object to figure out what you're supposed to pass into these methods :)

@joseparoli I'm going to close this out for now. If you need any other help... please do let us know!

Was this page helpful?
0 / 5 - 0 ratings