发送调查问卷以跟踪用户满意度

Business Messages 对话中的自定义调查问卷。

为了确保用户与代理之间的互动令人满意,Google 会在用户与代理的对话结束后向其发送调查问卷。如果您想收集不同时间(例如在对话结束时)的数据,可以在对话的上下文中发送调查问卷。调查问卷会显示在对话中,并可让用户根据问题提供各种选项的反馈。

Google 触发的问卷调查的时间取决于代理的消息功能可用性

可用性 调查问卷时间
仅限聊天机器人 最后一条消息后 30 分钟
仅人工 最后一条消息发出 24 个工时后
聊天机器人和人工 最后一条消息发出 24 个工时后

如果未来 7 天的工作时间少于 24 小时,我们会改为使用 24 小时。

您可以每 24 小时在每个对话中发送一份调查问卷。如果您在 Google 之前的对话中发送调查问卷,Google 不会向该对话发送调查问卷。如果您的代理在 24 小时内在同一个对话中发送多份调查问卷,Business Messages 仅会尝试向用户发送第一份调查问卷。

完成调查后,用户下一次开始与代理对话时,代理会显示greeting。如果用户没有回复调查问卷,则调查问卷将在 7 天后过期,并且用户在调查问卷过期后的下一次对话中看到问候语。

如果用户在对话过程中发送了与调查问卷无关的消息,Business Messages 会取消调查问卷并将用户的消息发送到代理的 webhook。

如果您不向用户发送调查问卷,您的代理仍会通过您的网络钩子接收 Google 调查问卷的结果,并应相应地接受和处理这些结果。

问题

调查问卷最多可包含五个问题,分为三个类别:必需模板自定义。调查问卷始终包含所需的问题,然后最多显示两个模板问题,最多显示两个自定义问题。

必填问题

必需问题已在 Business Messages 支持的所有语言区域中进行本地化。用户可以使用“我喜欢”或“不喜欢”来回复。

必选问题:“这项消息传递服务能否满足您的 AGENT_NAME 需求?”

模板问题

模板问题是可选的,由 Google 定义,在 Business Messages 支持的所有语言区域中进行本地化。一份调查问卷最多可包含两个模板问题。用户响应格式因问题而异。

模板问题包括

  • 你与“AGENT_NAME”发送消息的体验如何?
  • 你将AGENT_NAME推荐给好友的可能性有多大?
  • 下次与 AGENT_NAME 联系时,您选择消息功能的可能性有多大?
  • 总体而言,你觉得与AGENT_NAME互动容易吗?
  • 您对以下说法的赞同程度如何: AGENT_NAME 让我能够轻松处理我的问题。
  • 请评价您对支持人员的整体满意度。
  • 此聊天会话是否有助于您避免向 AGENT_NAME 拨打电话?

要查看所有可用模板问题的列表并获取模板 ID,请执行以下操作:

  1. 打开 Business Communications 开发者控制台,然后使用您的 Business Messages Google 帐号登录。
  2. 选择您的代理。
  3. 在左侧导航栏中,点击调查问卷

自定义问题

一份调查问卷最多可包含两个自定义问题。如果您指定自定义问题,请为您的代理支持的每个语言区域添加问题版本。您必须针对默认语言区域指定每个问题的版本。如果用户接收了调查问卷,但其所在语言区域没有指定自定义问题版本,则问题会按照代理的默认语言区域中定义的方式显示。

建议的回复类似,对自定义问题的响应支持单独的文本和回传数据。

自定义调查问卷

如需为客服人员自定义调查问卷,请按以下步骤操作:

  1. 打开 Business Communications 开发者控制台,然后使用您的 Business Messages Google 帐号登录。
  2. 选择您的代理。
  3. 在左侧导航栏中,点击调查问卷
  4. 最多可向调查问卷中添加两个可用的模板问题。
  5. 点击创建自定义问题,将自定义问题添加到您的调查问卷中。

如需了解格式设置和值选项,请参阅 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 中。对于必选问题和模板问题,Business Messages 会返回“我喜欢”响应(作为 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"
  }
}

如需了解格式设置和值选项,请参阅 UserMessageSurveyResponse