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

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

為確保使用者與服務專員的互動良好 在使用者與服務專員對話後,系統就會傳送問卷調查給他們。如果 但您想使用不同的時間點收集資料 對話時,您可以在以下情境中傳送問卷調查: 對話。問卷調查會顯示在對話中,方便使用者在對話中表達意見 針對問題提供不同選項。

具體時間取決於服務專員的訊息內容 供應情形

可用性 問卷調查時間
僅限機器人 發送最後一封郵件的 30 分鐘後
真人專用 發送最後一則訊息後的 24 小時服務時間
機器人與真人 發送最後一則訊息後的 24 小時服務時間

如果未來 7 天的營業時間為 24 小時,而我們會改用 24 小時。

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

當使用者完成 服務專員會顯示問候語。 如果使用者沒有回覆問卷調查,問卷調查會在 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 Messages Google 帳戶登入
  2. 選擇代理程式。
  3. 在左側導覽面板中按一下「問卷調查」

自訂問題

一份問卷調查最多可以包含兩個自訂問題。如果您要指定自訂機器類型 請為每個問題提供不同版本 語言代碼 代理程式的支援您必須為每個問題指定一個版本 預設語言代碼如果使用者收到問卷調查,但所在地區不支援 會依照系統定義的方式顯示問題 寫入代理程式的預設語言代碼

自訂問題的答案可分為不同的文字和回傳資料 為建議 回覆

自訂問卷調查

如要自訂服務專員的問卷調查,請按照下列步驟操作:

  1. 開啟業務通訊開發人員 控制台 然後使用 Business Messages Google 帳戶登入
  2. 選擇代理程式。
  3. 在左側導覽面板中按一下「問卷調查」
  4. 請在問卷中新增最多兩個問題範本問題。
  5. 按一下「建立自訂問題」,即可在問卷中加入自訂問題。

如需格式設定和值選項,請參閱: surveyConfig

傳送問卷調查

問卷調查

如要傳送問卷調查,請執行下列指令。取代 CONVERSATION_ID 以及您要接收問卷調查的對話 ID 將 SURVEY_ID 替換為問卷調查的專屬 ID。

# 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)"
/**
 * 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);
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();
    }
  }
}
"""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"
  }
}

如需格式設定和值選項,請參閱: UserMessage敬上 和 SurveyResponse