Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Dialogflow API Java examples

These samples demonstrate the use of the Dialogflow API.

These samples show how to detect intents with text, audio, and streaming audio.

These samples show how to manage contexts, entities, entity types, and intents

Java Version

This sample requires you to have Java8.

Download Maven

To get started, download and install it.

Setup

  • Create a project with the Google Cloud Console, and enable the Dialogflow API.

  • Set up authentication. For example, from the Cloud Console, create a service account, download its json credentials file, then set the appropriate environment variable:

    export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json
  • To run tests, set GOOGLE_CLOUD_PROJECT to your PROJECT_ID:

    export GOOGLE_CLOUD_PROJECT=PROJECT_ID
    
    mvn clean verify
    
  • Set PROJECT_ID in pom.xml to your Google Cloud Project Id.

  • Set SESSION_ID in pom.xml to a session name of your choice. (Defaults to SESSION_ID)

  • Set CONTEXT_ID in pom.xml to a context name of your choice. (Defaults to CONTEXT_ID)

Run the sample

To build the sample, we use Maven.

mvn clean package

Set up the Agent

Import the sample agent (RoomReservation.zip) from the resources directory to your Dialogflow Project using the following guide: Versioning with Import/Export

Samples

Detect Intent Texts

DialogFlow API Detect Intent sample with text inputs.

mvn exec:java -DDetectIntentText

Detect Intent Audio

DialogFlow API Detect Intent sample with audio files. Returns the result of detect intent with an audio file as input.

Note: Execute the following commands in order to yield reasonable outputs.

mvn exec:java -DDetectIntentAudioBookARoom
mvn exec:java -DDetectIntentAudioMountainView
mvn exec:java -DDetectIntentAudioToday
mvn exec:java -DDetectIntentAudio230PM
mvn exec:java -DDetectIntentAudioHalfAnHour
mvn exec:java -DDetectIntentAudioTwoPeople

Detect Intent Stream

DialogFlow API Detect Intent sample with audio files processes as an audio stream.

mvn exec:java -DDetectIntentStreamBookARoom
mvn exec:java -DDetectIntentStreamMountainView

Detect Intent With Model Selection

DialogFlow API Detect Intent sample with model selection

mvn exec:java -DDetectIntentWithModelSelection -Dexec.args='--projectId PROJECT_ID --audioFilePath resources/book_a_room.wav --sessionId SESSION_ID'

Detect Intent With Sentiment Analysis

DialogFlow API Detect Intent sample with sentiment analysis

mvn exec:java -DDetectIntentWithSentimentAnalysis -Dexec.args="--projectId PROJECT_ID -sessionId SESSION_ID 'hello'"

Detect Intent With Text-to-Speech

DialogFlow API Detect Intent sample with Text-to-Speech

mvn exec:java -DetectIntentTTSResponse

Detect Intent Knowledge

DialogFlow API Detect Intent sample with querying knowledge connector.

mvn exec:java -DDetectIntentKnowledge -Dexec.args="--projectId PROJECT_ID --knowledgeBaseId KNOWLEDGE_BASE_ID -sessionId SESSION_ID 'Where can I find pricing information?'"

Context Management

DialogFlow API Context sample.

Lists contexts

mvn exec:java -DContextManagementList

Create an entity type

mvn exec:java -DContextManagementCreate

Delete entity type

mvn exec:java -DContextManagementDelete

Entity Management

DialogFlow API Entity sample.

List entities

mvn exec:java -DEntityManagementList

Create an entity

mvn exec:java -DEntityManagementCreate

Delete entity

mvn exec:java -DEntityManagementDelete

Entity Type Management

DialogFlow API EntityType sample.

List entity types

mvn exec:java -DEntityTypeManagementList

Create an entity type

mvn exec:java -DEntityTypeManagementCreate

Delete entity type

mvn exec:java -DEntityTypeManagementDelete

Intent Management

DialogFlow API Intent sample.

List intents

mvn exec:java -DIntentManagementList

Create an intent

mvn exec:java -DIntentManagementCreate

Delete intent

mvn exec:java -DIntentManagementDelete

Session Entity Type Management

DialogFlow API SessionEntityType sample.

List session entity types

mvn exec:java -DSessionEntityTypeManagementList

Create session entity type

mvn exec:java -DSessionEntityTypeManagementCreate

Delete session entity type

mvn exec:java -DSessionEntityTypeManagementDelete

Knowledge Base Management

DialogFlow API KnowledgeBaseManagement sample

List knowledge base

mvn exec:java -DKnowledgeBaseManagement -Dexec.args='list --projectId PROJECT_ID'

Create knowledge base

mvn exec:java -DKnowledgeBaseManagement -Dexec.args='create DISPLAY_NAME --projectId PROJECT_ID'

Delete knowledge base

mvn exec:java -DKnowledgeBaseManagement -Dexec.args='delete KNOWLEDGE_BASE_ID --projectId PROJECT_ID'

Document Management

DialogFlow API DocumentManagement sample

List documents

mvn exec:java -DDocumentManagement -Dexec.args='list --projectId PROJECT_ID --knowledgeBaseId KNOWLEDGE_BASE_ID'

Create doucment

mvn exec:java -DDocumentManagement -Dexec.args='create KNOWLEDGE_BASE_ID --projectId PROJECT_ID
   --displayName DISPLAY_NAME
   --mimeType text/html
   --knowledgeType FAQ'
   --contentUri https://cloud.google.com/storage/docs/faq'

Delete doucment

mvn exec:java -DDocumentManagement -Dexec.args='delete KNOWLEDGE_BASE_ID --projectId PROJECT_ID --documentId DOCUMENT_ID