[go: nahoru, domu]

Skip to content

Commit

Permalink
Added support for CSAT survey customization
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjchan committed Jul 28, 2021
1 parent a78ddca commit 3d98150
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.api.services.businesscommunications.v1.enums;

/**
* Enum values for interaction type.
*/
public enum CustomSurveyQuestionTypeValues {
TYPE_UNSPECIFIED,
GOOGLE_STANDARD_QUESTION,
GOOGLE_TEMPLATE_QUESTION,
PARTNER_CUSTOM_QUESTION
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.api.services.businesscommunications.v1.enums.DayOfWeek;
import com.google.api.services.businesscommunications.v1.enums.InteractionType;
import com.google.api.services.businesscommunications.v1.enums.OptionsValueListEntryValues;
import com.google.api.services.businesscommunications.v1.enums.CustomSurveyQuestionTypeValues;
import com.google.api.services.businesscommunications.v1.model.*;

import java.io.IOException;
Expand Down Expand Up @@ -128,6 +129,58 @@ public static void main(String[] args) {

View.printBreak(3);

View.header("Updating Agent Custom Survey");
// Configure a CSAT survey with one template question and a custom question
SurveyConfig updatedSurveyConfig = new SurveyConfig()
.setCustomSurveys(new HashMap<String, CustomSurveyConfig>() {{
put("en", new CustomSurveyConfig()
.setCustomQuestions(new ArrayList<SurveyQuestion>() {{
add(new SurveyQuestion()
.setName("Question Name 1")
.setQuestionContent("Does a custom question yield better survey results?")
.setQuestionType(CustomSurveyQuestionTypeValues.PARTNER_CUSTOM_QUESTION.toString())
.setResponseOptions(new ArrayList<SurveyResponse>() {{
add(new SurveyResponse()
.setContent("👍")
.setPostbackData("yes"));
add(new SurveyResponse()
.setContent("👎")
.setPostbackData("no"));
}})
);
add(new SurveyQuestion()
.setName("Question Name 2")
.setQuestionContent("How would you rate this agent?")
.setQuestionType(CustomSurveyQuestionTypeValues.PARTNER_CUSTOM_QUESTION.toString())
.setResponseOptions(new ArrayList<SurveyResponse>() {{
add(new SurveyResponse()
.setContent("⭐️")
.setPostbackData("1-star"));
add(new SurveyResponse()
.setContent("⭐️️⭐️")
.setPostbackData("2-star"));
add(new SurveyResponse()
.setContent("⭐️⭐️⭐️")
.setPostbackData("3-star"));
add(new SurveyResponse()
.setContent("⭐️⭐️⭐️⭐️")
.setPostbackData("4-star"));
add(new SurveyResponse()
.setContent("⭐️⭐️⭐️⭐️⭐️")
.setPostbackData("5-star"));
}})
);
}})
);
}})
.setTemplateQuestionIds(new ArrayList<String>(){{
add("GOOGLE_DEFINED_ASSOCIATE_SATISFACTION");
add("GOOGLE_DEFINED_CUSTOMER_EFFORT_ALTERNATE");
}});
updateAgentSurveyConfig(agent, updatedSurveyConfig);

View.printBreak(3);

// List agents
View.header("List Agents:");
listAgents(brandName);
Expand Down Expand Up @@ -233,6 +286,31 @@ private static Agent createAgent(String brandName) {
add("US");
}});

// Configure a CSAT survey with one template question and a custom question
SurveyConfig surveyConfig = new SurveyConfig()
.setCustomSurveys(new HashMap<String, CustomSurveyConfig>() {{
put("en", new CustomSurveyConfig()
.setCustomQuestions(new ArrayList<SurveyQuestion>() {{
add(new SurveyQuestion()
.setName("Question Name 1")
.setQuestionContent("Did this agent do the best that it could?")
.setQuestionType(CustomSurveyQuestionTypeValues.PARTNER_CUSTOM_QUESTION.toString())
.setResponseOptions(new ArrayList<SurveyResponse>() {{
add(new SurveyResponse()
.setContent("👍")
.setPostbackData("yes"));
add(new SurveyResponse()
.setContent("👎")
.setPostbackData("no"));
}})
);
}})
);
}})
.setTemplateQuestionIds(new ArrayList<String>(){{
add("GOOGLE_DEFINED_ASSOCIATE_SATISFACTION");
}});

BusinessCommunications.Brands.Agents.Create request = builder
.build().brands().agents().create(brandName,
new Agent()
Expand All @@ -258,6 +336,7 @@ private static Agent createAgent(String brandName) {
.setHours(hours))))
.setAdditionalAgentInteractions(additionalAgentInteractions) // Optional
.setConversationalSettings(conversationalSettings)
.setSurveyConfig(surveyConfig)
));

agent = request.execute();
Expand Down Expand Up @@ -325,13 +404,27 @@ 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);

return updateAgent(agent, "businessMessagesAgent.primaryAgentInteraction");
}

/**
* Update the agent's feedback survey
*
* @param agent The agent that needs to be updated.
* @param surveyConfig The new surveyConfig
* @return The updated agent object.
*/
private static Agent updateAgentSurveyConfig(Agent agent, SurveyConfig surveyConfig) {
// Set the new survey config within the agent object
agent.getBusinessMessagesAgent().setSurveyConfig(surveyConfig);

return updateAgent(agent, "businessMessagesAgent.surveyConfig");
}

/**
* Updates the saved agent with the passed in agent object for the fields specified in the update
* mask.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 java.io.IOException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* A sample application that lists all available template survey questions.
*/
public class ListSurveyQuestions {

private static BusinessCommunications.Builder builder;
private static final Logger logger = Logger.getLogger(BrandSample.class.getName());

public static void main(String[] args) {

View.header("Fetching template survey questions");

builder = BusinessCommunicationsApi.getBusinessCommunicationsBuilder();

try {
// Produce a request builder for sending a request to /v1/surveyQuestions.
BusinessCommunications.SurveyQuestions.List request = builder.build().surveyQuestions().list();

// Execute the request.
System.out.println(request.execute());
} catch (Exception e) {
logger.log(Level.SEVERE, Constants.EXCEPTION_WAS_THROWN, e);
}
}
}

0 comments on commit 3d98150

Please sign in to comment.