Skip to content

Instantly share code, notes, and snippets.

@dinhanhthi
Created October 29, 2021 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinhanhthi/b40217eff2b938ffbfece82de8bb0907 to your computer and use it in GitHub Desktop.
Save dinhanhthi/b40217eff2b938ffbfece82de8bb0907 to your computer and use it in GitHub Desktop.
Example of using Google Dialogflow SDK APIs
// Obtain JSON first: https://cloud.google.com/docs/authentication/getting-started#creating_a_service_account
// How to use: node search-agents-sdk.js
// SDK reference: https://googleapis.dev/nodejs/dialogflow/latest/v2.AgentsClient.html#searchAgents
"use strict";
require('dotenv').config();
// private_key and client_email are store in .env file
async function main() {
const location = "global";
const { AgentsClient } = require("@google-cloud/dialogflow");
const parent = (location) => "projects/-" + "/locations/" + location;
const private_key = process.env.PRIVATE_KEY;
const client_email = process.env.CLIENT_EMAIL;
const client = new AgentsClient({
credentials: { private_key, client_email },
apiEndpoint: location + "-dialogflow.googleapis.com",
});
async function searchAgents() {
const request = {
parent: parent(location),
};
const options = {
autoPaginate: false,
}
const [response] = await client.searchAgents(request);
console.log(`response: ${JSON.stringify(response, null, 2)}`);
}
await searchAgents();
}
process.on("unhandledRejection", (err) => {
console.error(err.message);
process.exitCode = 1;
});
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment