Created
October 29, 2021 18:22
-
-
Save dinhanhthi/b40217eff2b938ffbfece82de8bb0907 to your computer and use it in GitHub Desktop.
Example of using Google Dialogflow SDK APIs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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