[go: nahoru, domu]

Skip to content

Commit

Permalink
Add greetings support
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjchan committed Oct 31, 2022
1 parent 3d98150 commit 39d3fa2
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 4 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,36 @@ mvn compile && mvn exec:java -Dexec.mainClass="com.google.businesscommunications
```

Replace AGENT_NAME with a valid agent ID in "brands/BRAND_ID/agents/AGENT_ID" format. If you haven't created an agent, run the agent sample with the NO-DELETE argument to create an agent to reference.


### List template survey questions

This sample lists all template questions provided by Google. You can configure an Agent to send these questions when a survey is triggered.

View the [source code](https://github.com/google-business-communications/bc-bm-java-command-line-examples/blob/master/ListSurveyQuestions.java).

Usage:

```bash
mvn compile && mvn exec:java -Dexec.mainClass="com.google.businesscommunications.businessmessages.samples.ListSurveyQuestions"
```

### Agent Greeting operations

These sample demonstrates how to create a new greeting, get greeting details, update the greeting, and list all greetings.

View the source code to [CreateGreeting](https://github.com/google-business-communications/bc-bm-java-command-line-examples/blob/master/src/main/java/com/google/businesscommunications/businessmessages/samples/CreateGreeting.java), [GetGreeting](https://github.com/google-business-communications/bc-bm-java-command-line-examples/blob/master/src/main/java/com/google/businesscommunications/businessmessages/samples/GetGreeting.java), [UpdateGreetings](https://github.com/google-business-communications/bc-bm-java-command-line-examples/blob/master/src/main/java/com/google/businesscommunications/businessmessages/samples/UpdateGreeting.java), and [ListGreetings](https://github.com/google-business-communications/bc-bm-java-command-line-examples/blob/master/src/main/java/com/google/businesscommunications/businessmessages/samples/ListGreetings.java).

Usage:

```bash
mvn compile && mvn exec:java -Dexec.mainClass="com.google.businesscommunications.businessmessages.samples.CreateGreeting"

mvn compile && mvn exec:java -Dexec.mainClass="com.google.businesscommunications.businessmessages.samples.GetGreeting"

mvn compile && mvn exec:java -Dexec.mainClass="com.google.businesscommunications.businessmessages.samples.UpdateGreeting"

mvn compile && mvn exec:java -Dexec.mainClass="com.google.businesscommunications.businessmessages.samples.ListGreetings"
```

For each of the snippets above, ensure you modify the agentId, brandId, and greetingId within the respective snippets.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ limitations under the License.
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-businesscommunications</artifactId>
<version>1.25.3</version>
<version>2.1.0</version>
</dependency>

<!-- App Engine SDK dependency : only required if you need to explicitly use App Engine API -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ private static Agent createAgent(String brandName) {
.setWelcomeMessage(new WelcomeMessage().setText("Welcome! How can I help?"))
.setOfflineMessage(new OfflineMessage().setText(
"We are currently offline, please leave a message and we will get back to you as soon as possible."))
.setConversationStarters(conversationStarters));
.setConversationStarters(conversationStarters)
.setNegativeBotFeedbackMessage(new NegativeBotFeedbackMessage().setText("Thanks for the feedback! These help us improve the conversational experience to better help our customers.")));
}};

// Configuration options for launching on non-local entry points
Expand Down Expand Up @@ -404,7 +405,7 @@ private static Agent updateAgentConversationalSettings(Agent agent,
* @return The updated agent object.
*/
private static Agent updateAgentPrimaryAgentInteraction(Agent agent,
SupportedAgentInteraction supportedAgentInteraction) {
SupportedAgentInteraction supportedAgentInteraction) {
// Set the new primary interaction within the agent object
agent.getBusinessMessagesAgent().setPrimaryAgentInteraction(supportedAgentInteraction);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public interface Constants {
// Name of your service account key credentials file.
// You must create this file in order to run this sample.
public static final String CREDENTIALS_FILE_NAME = "bc-agent-service-account-credentials.json";
public static final String CREDENTIALS_FILE_NAME = "service_account_key.json";

public static final String API_URL = "https://businesscommunications.googleapis.com/";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2020 Google Inc. All rights reserved.
*
* 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 com.google.businesscommunications.businessmessages.samples;

import com.google.api.services.businesscommunications.v1.BusinessCommunications;
import com.google.api.services.businesscommunications.v1.model.*;

import java.util.*;


/**
* This code snippet creates a new greeting.
*
* Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents.greetings
*
* This code is based on the https://github.com/google-business-communications/java-businesscommunications Java
* Business Communications client library.
*/

public class CreateGreeting {

private static BusinessCommunications.Builder builder;

public static void main(String[] args) {

builder = BusinessCommunicationsApi.getBusinessCommunicationsBuilder();

String brandId = "EDIT_HERE";
String agentId = "EDIT_HERE";

String agentName = "brands/" + brandId + "/agents/" + agentId;

// Create a list of conversation starters for the greeting
List<ConversationStarters> conversationStarters = new ArrayList<ConversationStarters>() {{
add(new ConversationStarters().setSuggestion(new Suggestion()
.setReply(new SuggestedReply().setText("Click me").setPostbackData("postback_option_1"))));
add(new ConversationStarters().setSuggestion(new Suggestion()
.setReply(new SuggestedReply().setText("Chip #2").setPostbackData("postback_option_2"))));
}};

// Create a list of welcome messages for the greeting
List<WelcomeMessage> welcomeMessages = new ArrayList<WelcomeMessage>() {{
add(new WelcomeMessage().setText("Hello there!"));
add(new WelcomeMessage().setText("How may I help you?"));
}};

// Actually create the greeting object
Greeting greeting = new Greeting();
greeting
.setLocale("en")
.setCustomId("My first greeting")
.setWelcomeMessages(welcomeMessages)
.setConversationStarters(conversationStarters);

// Build the request to create the greeting and execute it
try {
BusinessCommunications.Brands.Agents.Greetings.Create request = builder
.build().brands().agents().greetings().create(agentName, greeting);

greeting = request.execute();

// Print the response and display the contents of the greeting
System.out.println(greeting.toPrettyString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2020 Google Inc. All rights reserved.
*
* 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 com.google.businesscommunications.businessmessages.samples;

import com.google.api.services.businesscommunications.v1.BusinessCommunications;
import com.google.api.services.businesscommunications.v1.model.*;

import java.io.IOException;
import java.util.*;

/**
* This code snippet gets an agent.
* Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents/get
*
* This code is based on the https://github.com/google-business-communications/java-businesscommunications Java
* Business Communications client library.
*/

public class GetAgent {

private static BusinessCommunications.Builder builder;

public static void main(String[] args) {

builder = BusinessCommunicationsApi.getBusinessCommunicationsBuilder();

String brandId = "EDIT_HERE";
String agentId = "EDIT_HERE";

String agentName = "brands/" + brandId + "/agents/" + agentId;

// Get agent details
System.out.println("Get Agent Details:");
Agent agent = null;

try {
BusinessCommunications.Brands.Agents.Get request = builder
.build().brands().agents().get(agentName);

agent = request.execute();
System.out.println(agent.toPrettyString());

} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2020 Google Inc. All rights reserved.
*
* 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 com.google.businesscommunications.businessmessages.samples;

import com.google.api.services.businesscommunications.v1.BusinessCommunications;
import com.google.api.services.businesscommunications.v1.model.*;

import java.util.*;


/**
* This code snippet gets a greeting.
*
* Read more: https://developers.devsite.corp.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents.greetings#get
*
* This code is based on the https://github.com/google-business-communications/java-businesscommunications Java
* Business Communications client library.
*/

public class GetGreeting {

private static BusinessCommunications.Builder builder;

public static void main(String[] args) {

builder = BusinessCommunicationsApi.getBusinessCommunicationsBuilder();

String brandId = "EDIT_HERE";
String agentId = "EDIT_HERE";
String greetingId = "EDIT_HERE";

String greetingName = "brands/" + brandId + "/agents/" + agentId +
"/greetings/" + greetingId;

// Build the request to get the greeting object and execute it
try {
BusinessCommunications.Brands.Agents.Greetings.Get request = builder
.build().brands().agents().greetings().get(greetingName);

Greeting greeting = request.execute();

// Print the response and display the contents of the greeting
System.out.println(greeting.toPrettyString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2020 Google Inc. All rights reserved.
*
* 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 com.google.businesscommunications.businessmessages.samples;

import com.google.api.services.businesscommunications.v1.BusinessCommunications;
import com.google.api.services.businesscommunications.v1.model.*;

import java.util.*;

/**
* This code snippet lists all greetings associated with an agent
* Read more: https://developers.google.com/business-communications/business-messages/reference/business-communications/rest/v1/brands.agents.greetings/list
*
* This code is based on the https://github.com/google-business-communications/java-businesscommunications Java
* Business Communications client library.
*/


public class ListGreetings {

private static BusinessCommunications.Builder builder;

public static void main(String[] args) {

builder = BusinessCommunicationsApi.getBusinessCommunicationsBuilder();

String brandId = "EDIT_HERE";
String agentId = "EDIT_HERE";

String agentName = "brands/" + brandId + "/agents/" + agentId;

// Build the request to get the greeting object and execute it
try {
BusinessCommunications.Brands.Agents.Greetings.List request = builder
.build().brands().agents().greetings().list(agentName);

ListGreetingsResponse greetings = request.execute();

// Print the response and display the contents of the greeting
System.out.println(greetings.toPrettyString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Loading

0 comments on commit 39d3fa2

Please sign in to comment.