为确保用户与您的代理进行令人满意的互动,Google 会在用户与您的代理结束对话后向用户发送调查问卷。如果您想在不同时间收集数据(例如在对话结束时),可以在对话情境中发送调查问卷。调查会显示在对话中,用户可以根据问题通过各种选项提供反馈。
Google 触发的调查问卷的显示时间取决于客服人员的消息功能可用性:
| 可用性 | 调查时间 |
|---|---|
| 仅限聊天机器人 | 最后一条消息发送 30 分钟后 |
| 仅人工 | 自上一条消息发出后 24 个工作小时 |
| 聊天机器人和人工 | 自上一条消息发出后 24 个工作小时 |
如果未来 7 天内的营业时间不足 24 小时,我们会改为使用 24 小时。
每 24 小时,您可以在每次对话中发送一次调查问卷。如果您在 Google 之前在对话中发送了调查问卷,Google 不会向该对话发送调查问卷。如果代理在同一对话中于 24 小时内发送多份调查问卷,Business Messages 只会尝试向用户发送第一份调查问卷。
用户完成调查问卷后,下次与您的代理开始对话时,代理会显示问候语。如果用户未回复调查问卷,该问卷会在 7 天后失效,并且用户会在问卷失效后的下一次对话中看到问候语。
如果用户在对话中调查问卷处于有效状态时发送与调查问卷无关的消息,Business Messages 会取消调查问卷,并将用户的消息发送到代理的 webhook。
如果您不向用户发送调查问卷,您的代理仍会在您的网络钩子上接收 Google 调查问卷的结果,并且应相应地接受和处理这些结果。
问题
调查最多可包含 5 个问题,分为三类:必答、模板和自定义。调查始终包含必答问题,然后显示最多两个模板问题,最后显示最多两个自定义问题。
必答题
必需问题已针对 Business Messages 支持的所有语言区域进行了本地化。用户可以通过“赞”或“踩”来回应。
必答问题:“这款即时通讯服务能否满足你与AGENT_NAME的沟通需求?”
模板问题
模板问题是可选的,是 Google 定义的问题,已针对 Business Messages 支持的所有语言区域进行本地化。一项调查最多可包含两个模板问题。用户回答格式因问题而异。
模板问题包括
- 与 AGENT_NAME 在线聊天的体验如何?
- 您向朋友推荐AGENT_NAME的可能性有多大?
- 下次与 AGENT_NAME 联系时,您选择发送消息的可能性有多大?
- 总体来说,你觉得与 AGENT_NAME 互动容易吗?
- 您在多大程度上赞同或不赞同以下说法:AGENT_NAME可协助我轻松处理问题。
- 请就对支持人员的整体满意度进行评价。
- 该聊天会话是否帮得上忙,让你不必向AGENT_NAME拨打电话?
如需查看所有可用模板问题的列表并获取模板 ID,
- 打开 Business Communications 开发者控制台,然后使用您的 Business Messages Google 账号登录。
- 选择您的代理。
- 在左侧导航栏中,点击调查。
自定义问题
一份调查问卷最多可以包含两个自定义问题。如果您指定自定义问题,请针对智能体支持的每种语言区域提供相应的问题版本。您必须为默认语言区域指定每个问题的版本。如果用户收到了调查问卷,但其所用语言区域没有指定版本的自定义问题,则该问题会以智能体默认语言区域中的定义显示。
自定义问题的回答支持单独的文本和回发数据,类似于建议的回答。
自定义调查问卷
如需为代理自定义调查问卷,请执行以下操作:
- 打开 Business Communications 开发者控制台,然后使用您的 Business Messages Google 账号登录。
- 选择您的代理。
- 在左侧导航栏中,点击调查。
- 向调查问卷添加最多两个可用的模板问题。
- 点击创建自定义问题,向调查问卷添加自定义问题。
如需了解格式设置和值选项,请参阅 surveyConfig。
发送调查问卷
如需发送调查问卷,请运行以下命令。将 CONVERSATION_ID 替换为要向其发送调查问卷的对话的标识符,并将 SURVEY_ID 替换为调查问卷的唯一标识符。
cURL
# 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 # https://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. # This code sends a survey to the user: # Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/message/surveys?hl=en # Replace the __CONVERSATION_ID__ with a conversation id that you can send messages to # Make sure a service account key file exists at ./service_account_key.json curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/surveys?surveyId=f4bd7576-6c2e-4674-9db4-d697166f63ce" \ -H "Content-Type: application/json" \ -H "User-Agent: curl/business-messages" \ -H "$(oauth2l header --json ./service_account_key.json businessmessages)"
Node.js
/** * This code sends a survey to the user: * Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/message/surveys?hl=en * * This code is based on the https://github.com/google-business-communications/nodejs-businessmessages Node.js * Business Messages client library. */ /** * Edit the values below: */ const PATH_TO_SERVICE_ACCOUNT_KEY = './service_account_key.json'; const CONVERSATION_ID = 'EDIT_HERE'; const businessmessages = require('businessmessages'); const uuidv4 = require('uuid').v4; const {google} = require('googleapis'); // Initialize the Business Messages API const bmApi = new businessmessages.businessmessages_v1.Businessmessages({}); // Set the scope that we need for the Business Messages API const scopes = [ 'https://www.googleapis.com/auth/businessmessages', ]; // Set the private key to the service account file const privatekey = require(PATH_TO_SERVICE_ACCOUNT_KEY); /** * Posts a survey to the Business Messages API. * * @param {string} conversationId The unique id for this user and agent. */ async function sendSurvey(conversationId) { const authClient = await initCredentials(); // Create the payload for creating a new survey const apiParams = { auth: authClient, parent: 'conversations/' + conversationId, surveyId: uuidv4(), resource: {} }; // Call the message create function using the // Business Messages client library bmApi.conversations.surveys.create(apiParams, {auth: authClient}, (err, response) => { console.log(err); console.log(response); }); } /** * Initializes the Google credentials for calling the * Business Messages API. */ async function initCredentials() { // configure a JWT auth client const authClient = new google.auth.JWT( privatekey.client_email, null, privatekey.private_key, scopes, ); return new Promise(function(resolve, reject) { // authenticate request authClient.authorize(function(err, tokens) { if (err) { reject(false); } else { resolve(authClient); } }); }); } sendSurvey(CONVERSATION_ID);
Java
import com.google.api.client.googleapis.services.AbstractGoogleClientRequest; import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler; import com.google.api.client.http.HttpRequest; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; import com.google.api.client.http.HttpTransport; import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.client.util.ExponentialBackOff; import com.google.api.services.businessmessages.v1.Businessmessages; import com.google.api.services.businessmessages.v1.model.*; import java.io.FileInputStream; import java.util.Arrays; import java.util.UUID; class SendSurveySnippet { /** * Initializes credentials used by the Business Messages API. */ private static Businessmessages.Builder getBusinessMessagesBuilder() { Businessmessages.Builder builder = null; try { GoogleCredential credential = GoogleCredential .fromStream(new FileInputStream("PATH_TO_SERVICE_ACCOUNT_KEY")); credential = credential.createScoped(Arrays.asList( "https://www.googleapis.com/auth/businessmessages")); credential.refreshToken(); HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance(); // Create instance of the Business Messages API builder = new Businessmessages .Builder(httpTransport, jsonFactory, null) .setApplicationName("Sample Application"); // Set the API credentials and endpoint builder.setHttpRequestInitializer(credential); } catch (Exception e) { e.printStackTrace(); } return builder; } public static void main(String args[]) { try { String conversationId = "CONVERSATION_ID"; // Create client library reference Businessmessages.Builder builder = getBusinessMessagesBuilder(); // Create a new survey to send to the user associated with the conversationId Businessmessages.Conversations.Surveys.Create request = bmBuilder.build().conversations().surveys() .create("conversations/" + conversationId, new BusinessMessagesSurvey()); request.setSurveyId(UUID.randomUUID().toString()); // Setup retries with exponential backoff HttpRequest httpRequest = ((AbstractGoogleClientRequest) request).buildHttpRequest(); httpRequest.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler( new ExponentialBackOff())); // Execute request httpRequest.execute(); } catch (Exception e) { e.printStackTrace(); } } }
Python
"""This code sends a survey to the user. Read more: https://developers.google.com/business-communications/business-messages/guides/how-to/message/surveys?hl=en This code is based on the https://github.com/google-business-communications/python-businessmessages Python Business Messages client library. """ import uuid from businessmessages import businessmessages_v1_client as bm_client from businessmessages.businessmessages_v1_messages import BusinessmessagesConversationsSurveysCreateRequest from businessmessages.businessmessages_v1_messages import BusinessMessagesSurvey from oauth2client.service_account import ServiceAccountCredentials # Edit the values below: path_to_service_account_key = './service_account_key.json' conversation_id = 'EDIT_HERE' credentials = ServiceAccountCredentials.from_json_keyfile_name( path_to_service_account_key, scopes=['https://www.googleapis.com/auth/businessmessages']) client = bm_client.BusinessmessagesV1(credentials=credentials) # Create the survey request survey_request = BusinessmessagesConversationsSurveysCreateRequest( surveyId=str(uuid.uuid4().int), parent='conversations/' + conversation_id, businessMessagesSurvey=BusinessMessagesSurvey()) # Send the survey bm_client.BusinessmessagesV1.ConversationsSurveysService( client=client).Create(request=survey_request)
如需了解格式设置和值选项,请参阅 conversations.surveys。
接收调查问卷回复
当用户回答调查问卷中的问题时,代理会在其网络钩子中收到回答。以接收消息的相同方式接收和处理调查问卷回答。
调查问卷中的所有问题都具有相同的 surveyResponse.survey 值。如果您的调查问卷包含多个问题,请确保您的基础架构接受具有相同 surveyResponse.survey 值的多个回答,并通过 surveyResponse.surveyQuestionId 字段识别各个问题。
调查问卷回答的文本值会显示在 surveyResponse.questionResponseText 中。对于必填问题和模板问题,Google 商家信息会返回“赞”响应 (VERY_SATISFIED) 和“踩”响应 (VERY_DISSATISFIED)。如果自定义问题回答包含表情符号,最佳做法是依赖 surveyResponse.questionResponsePostbackData,而不是尝试解析 Unicode 值。
调查问卷回答采用以下格式。
{ "agent": "brands/BRAND_ID/agents/AGENT_ID", "sendTime": "SEND_TIME", "conversationId": "CONVERSATION_ID", "requestId": "REQUEST_ID", "surveyResponse": { "survey": "conversations/CONVERSATION_ID/surveys/SURVEY_ID", "rating": "SURVEY_RATING", "createTime": "CREATE_TIME", "surveyQuestionId": "QUESTION_ID", "questionResponseText": "RESPONSE_TEXT", "questionResponsePostbackData": "RESPONSE_POSTBACK_DATA", "questionType": "QUESTION_TYPE", "questionIndex": QUESTION_INDEX, "totalQuestionCount": TOTAL_QUESTION_COUNT, "surveyTriggerSource": "TRIGGER_SOURCE" } }
如需了解格式设置和值选项,请参阅 UserMessage 和 SurveyResponse。