Search in sources :

Example 1 with IntentName

use of com.google.cloud.dialogflow.v2.IntentName in project java-dialogflow-cx by googleapis.

the class ListTrainingPhrases method listTrainingPhrases.

// DialogFlow API List Training Phrases sample.
public static void listTrainingPhrases(String projectId, String location, String agentId, String intentId) throws IOException {
    try (IntentsClient client = IntentsClient.create()) {
        // Set the intent name
        IntentName name = IntentName.of(projectId, location, agentId, intentId);
        // Compose the get-intent request
        GetIntentRequest request = GetIntentRequest.newBuilder().setName(name.toString()).build();
        // Make API request to get intent
        Intent response = client.getIntent(request);
        // Loop through the results
        for (Intent.TrainingPhrase phrase : response.getTrainingPhrasesList()) {
            System.out.println("***********************************************");
            List<Intent.TrainingPhrase.Part> parts = phrase.getPartsList();
            for (Intent.TrainingPhrase.Part part : parts) {
                System.out.println(String.format("Training Phrase: %s", part.getText()));
            }
        }
    }
}
Also used : IntentsClient(com.google.cloud.dialogflow.cx.v3.IntentsClient) IntentName(com.google.cloud.dialogflow.cx.v3.IntentName) GetIntentRequest(com.google.cloud.dialogflow.cx.v3.GetIntentRequest) Intent(com.google.cloud.dialogflow.cx.v3.Intent)

Example 2 with IntentName

use of com.google.cloud.dialogflow.v2.IntentName in project java-dialogflow by googleapis.

the class IntentManagement method deleteIntent.

// [END dialogflow_create_intent]
// [START dialogflow_delete_intent]
/**
 * Delete intent with the given intent type and intent value
 *
 * @param intentId The id of the intent.
 * @param projectId Project/Agent Id.
 */
public static void deleteIntent(String intentId, String projectId) throws ApiException, IOException {
    // Instantiates a client
    try (IntentsClient intentsClient = IntentsClient.create()) {
        IntentName name = IntentName.of(projectId, intentId);
        // Performs the delete intent request
        intentsClient.deleteIntent(name);
    }
}
Also used : IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) IntentName(com.google.cloud.dialogflow.v2.IntentName)

Example 3 with IntentName

use of com.google.cloud.dialogflow.v2.IntentName in project java-dialogflow by googleapis.

the class ListTrainingPhrases method listTrainingPhrases.

// DialogFlow API List Training Phrases sample.
public static void listTrainingPhrases(String projectId, String intentId) throws IOException {
    try (IntentsClient client = IntentsClient.create()) {
        // Set the intent name
        IntentName name = IntentName.of(projectId, intentId);
        // Compose the get-intent request
        GetIntentRequest request = GetIntentRequest.newBuilder().setName(name.toString()).setIntentView(IntentView.INTENT_VIEW_FULL).build();
        // Make API request to update intent
        Intent response = client.getIntent(request);
        // Loop through the results
        for (Intent.TrainingPhrase phrase : response.getTrainingPhrasesList()) {
            System.out.println("***********************************************");
            System.out.println(String.format("Phrase ID: %s", phrase.getName()));
            List<Intent.TrainingPhrase.Part> parts = phrase.getPartsList();
            for (Intent.TrainingPhrase.Part part : parts) {
                System.out.println(String.format("Training Phrase: %s", part.getText()));
            }
        }
    }
}
Also used : IntentsClient(com.google.cloud.dialogflow.v2.IntentsClient) IntentName(com.google.cloud.dialogflow.v2.IntentName) GetIntentRequest(com.google.cloud.dialogflow.v2.GetIntentRequest) Intent(com.google.cloud.dialogflow.v2.Intent)

Example 4 with IntentName

use of com.google.cloud.dialogflow.v2.IntentName in project java-dialogflow by googleapis.

the class ITSystemTest method setUp.

@BeforeClass
public static void setUp() throws IOException {
    agentsClient = AgentsClient.create();
    /* create entity */
    entityTypesClient = EntityTypesClient.create();
    EntityType createEntityType = EntityType.newBuilder().setDisplayName(ENTITY_NAME).setKind(EntityType.Kind.KIND_LIST).addEntities(ENTITY).build();
    CreateEntityTypeRequest entityTypeRequest = CreateEntityTypeRequest.newBuilder().setParent(PROJECT_AGENT_NAME.toString()).setEntityType(createEntityType).build();
    entityType = entityTypesClient.createEntityType(entityTypeRequest);
    entityName = entityType.getName().substring(entityType.getName().lastIndexOf("/")).replace("/", "");
    entityTypeName = EntityTypeName.of(PROJECT_ID, entityName);
    /* create intents */
    intentsClient = IntentsClient.create();
    Intent createIntent = Intent.newBuilder().setDisplayName(INTENT_NAME).addEvents(EVENT_NAME).setAction(ACTION_NAME).build();
    CreateIntentRequest intentRequest = CreateIntentRequest.newBuilder().setParent(PROJECT_AGENT_NAME.toString()).setIntent(createIntent).build();
    intent = intentsClient.createIntent(intentRequest);
    intentId = intent.getName().substring(intent.getName().lastIndexOf("/")).replace("/", "");
    intentName = IntentName.of(PROJECT_ID, intentId);
    /* create session */
    sessionsClient = SessionsClient.create();
    /* create context */
    contextsClient = ContextsClient.create();
    Context createContext = Context.newBuilder().setName(CONTEXT_NAME.toString()).setLifespanCount(LIFE_SPAN_COUNT).build();
    CreateContextRequest request = CreateContextRequest.newBuilder().setParent(SESSION_NAME.toString()).setContext(createContext).build();
    context = contextsClient.createContext(request);
}
Also used : EntityType(com.google.cloud.dialogflow.v2.EntityType) Context(com.google.cloud.dialogflow.v2.Context) CreateContextRequest(com.google.cloud.dialogflow.v2.CreateContextRequest) CreateEntityTypeRequest(com.google.cloud.dialogflow.v2.CreateEntityTypeRequest) Intent(com.google.cloud.dialogflow.v2.Intent) CreateIntentRequest(com.google.cloud.dialogflow.v2.CreateIntentRequest) BeforeClass(org.junit.BeforeClass)

Aggregations

Intent (com.google.cloud.dialogflow.v2.Intent)2 IntentName (com.google.cloud.dialogflow.v2.IntentName)2 IntentsClient (com.google.cloud.dialogflow.v2.IntentsClient)2 GetIntentRequest (com.google.cloud.dialogflow.cx.v3.GetIntentRequest)1 Intent (com.google.cloud.dialogflow.cx.v3.Intent)1 IntentName (com.google.cloud.dialogflow.cx.v3.IntentName)1 IntentsClient (com.google.cloud.dialogflow.cx.v3.IntentsClient)1 Context (com.google.cloud.dialogflow.v2.Context)1 CreateContextRequest (com.google.cloud.dialogflow.v2.CreateContextRequest)1 CreateEntityTypeRequest (com.google.cloud.dialogflow.v2.CreateEntityTypeRequest)1 CreateIntentRequest (com.google.cloud.dialogflow.v2.CreateIntentRequest)1 EntityType (com.google.cloud.dialogflow.v2.EntityType)1 GetIntentRequest (com.google.cloud.dialogflow.v2.GetIntentRequest)1 BeforeClass (org.junit.BeforeClass)1