傳送問卷調查以追蹤使用者滿意度

Business Messages 對話中的自訂問卷調查。

為確保使用者與服務專員的互動情形良好,Google 會在使用者與服務專員對話後傳送問卷調查給他們。如果您想使用不同的時間 (例如對話結束時) 收集資料,可以在對話結束時傳送問卷調查。問卷調查會顯示在對話中,並可讓使用者根據問題透過各種選項提供意見回饋。

Google 觸發的問卷調查時間取決於服務專員的訊息可用性

服務提供狀況 問卷調查時間
僅機器人 距離最後一則訊息 30 分鐘之後
僅真人 上次訊息後的 24 小時內
機器人和真人 上次訊息後的 24 小時內

如果未來 7 天內的上班時間少於 24 小時,我們會改為使用 24 小時。

每個對話每 24 小時可以傳送一份問卷調查。如果您在 Google 之前透過對話傳送問卷調查,Google 不會向該對話傳送問卷調查。如果服務專員在 24 小時內在同一對話中傳送多份問卷調查,則 Business Messages 只會嘗試傳送第一份問卷調查給使用者。

下次使用者在完成問卷調查後與代理程式進行對話時,代理程式會顯示「問候語」greeting。如果使用者沒有回覆,問卷調查會在 7 天後失效,且使用者在問卷調查到期後,會在下一個對話中看到問候語。

在對話期間進行問卷調查時,如果使用者傳送與問卷調查無關的訊息,Business Messages 就會取消問卷調查,並將使用者的訊息傳送至代理程式的 Webhook。

如果您不傳送問卷調查給使用者,您的服務專員仍會透過 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 換成要傳送問卷調查的對話 ID,並將 SURVEY_ID 替換成問卷調查的專屬 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

接收問卷調查回覆

當使用者回覆問卷調查中的問題時,服務專員會在 Webhook 收到回應。接收及處理問卷調查回應的方式與接收訊息相同。

問卷調查中所有問題的 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