-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: set agent code sample (#660)
* samples: set agent code sample * Lint fix * Update samples/snippets/src/test/java/com/example/dialogflow/SetAgentIT.java Co-authored-by: Jeff Ching <[email protected]> * Update samples/snippets/src/main/java/com/example/dialogflow/SetAgent.java Co-authored-by: Jeff Ching <[email protected]> * Update samples/snippets/src/main/java/com/example/dialogflow/SetAgent.java Co-authored-by: Jeff Ching <[email protected]> * Update samples/snippets/src/main/java/com/example/dialogflow/SetAgent.java Co-authored-by: Jeff Ching <[email protected]> * updated tests * Test and lint fix * Lint fix * Changed package name * revised code Co-authored-by: Jeff Ching <[email protected]>
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dialogflow; | ||
|
||
// [START dialogflow_es_create_agent] | ||
|
||
import com.google.cloud.dialogflow.v2.Agent; | ||
import com.google.cloud.dialogflow.v2.Agent.Builder; | ||
import com.google.cloud.dialogflow.v2.AgentsClient; | ||
import com.google.cloud.dialogflow.v2.AgentsSettings; | ||
import java.io.IOException; | ||
|
||
public class SetAgent { | ||
|
||
public static void main(String[] args) throws IOException { | ||
String projectId = "my-project-id"; | ||
|
||
// The display name will set the name of your agent | ||
String displayName = "my-display-name"; | ||
|
||
setAgent(projectId, displayName); | ||
} | ||
|
||
public static Agent setAgent(String parent, String displayName) throws IOException { | ||
|
||
AgentsSettings agentsSettings = AgentsSettings.newBuilder().build(); | ||
try (AgentsClient client = AgentsClient.create(agentsSettings)) { | ||
// Set the details of the Agent to create | ||
Builder build = Agent.newBuilder(); | ||
|
||
build.setDefaultLanguageCode("en"); | ||
build.setDisplayName(displayName); | ||
|
||
Agent agent = build.build(); | ||
|
||
// Make API request to create agent | ||
Agent response = client.setAgent(agent); | ||
System.out.println(response); | ||
return response; | ||
} | ||
} | ||
} | ||
// [END dialogflow_es_create_agent] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dialogflow; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class SetAgentIT { | ||
|
||
|
||
/* | ||
* We cannot test setAgent because Dialogflow ES can only have one agent | ||
* and if we create a agent it will delete the exisitng testing agent and | ||
* would cause all tests to fail | ||
*/ | ||
@Test | ||
public void testCreateAgent() { | ||
Assert.assertTrue(true); | ||
} |