Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as dialogflow from "dialogflow";
const agentsClient = new dialogflow.AgentsClient();
const contextsClient = new dialogflow.ContextsClient();
const entityTypesClient = new dialogflow.EntityTypesClient();
const intentsClient = new dialogflow.IntentsClient();
const sessionEntityTypesClient = new dialogflow.SessionEntityTypesClient();
const sessionsClient = new dialogflow.SessionsClient();
// TODO: Add real significant tests
async function listIntents(projectId) {
// [START dialogflow_list_intents]
// Imports the Dialogflow library
const dialogflow = require('dialogflow');
// Instantiates clients
const intentsClient = new dialogflow.IntentsClient();
// The path to identify the agent that owns the intents.
const projectAgentPath = intentsClient.projectAgentPath(projectId);
const request = {
parent: projectAgentPath,
};
console.log(projectAgentPath);
// Send the request for listing intents.
const [response] = await intentsClient.listIntents(request);
response.forEach(intent => {
console.log('====================');
console.log(`Intent name: ${intent.name}`);
console.log(`Intent display name: ${intent.displayName}`);
async function deleteIntent(projectId, intentId) {
// [START dialogflow_delete_intent]
// Imports the Dialogflow library
const dialogflow = require('dialogflow');
// Instantiates clients
const intentsClient = new dialogflow.IntentsClient();
const intentPath = intentsClient.intentPath(projectId, intentId);
const request = {name: intentPath};
// Send the request for deleting the intent.
const result = await intentsClient.deleteIntent(request);
console.log(`Intent ${intentPath} deleted`);
return result;
// [END dialogflow_delete_intent]
}
async function createIntent(
projectId,
displayName,
trainingPhrasesParts,
messageTexts
) {
// [START dialogflow_create_intent]
// Imports the Dialogflow library
const dialogflow = require('dialogflow');
// Instantiates the Intent Client
const intentsClient = new dialogflow.IntentsClient();
// The path to identify the agent that owns the created intent.
const agentPath = intentsClient.projectAgentPath(projectId);
const trainingPhrases = [];
trainingPhrasesParts.forEach(trainingPhrasesPart => {
const part = {
text: trainingPhrasesPart,
};
// Here we create a new training phrase for each provided part.
const trainingPhrase = {
type: 'EXAMPLE',
parts: [part],
};