ユーザー満足度を追跡するためのアンケートを送信する

ビジネス メッセージの会話に表示されるカスタマイズされたアンケート。

ユーザーがエージェントと快適にやり取りできるように、Google はエージェントとの会話が終了したユーザーにアンケートを送信します。会話の最後など、異なるタイミングでデータを収集する場合は、会話のコンテキスト内でアンケートを送信できます。アンケートが会話に表示され、ユーザーが質問に応じてさまざまなオプションでフィードバックを提供できるようになります。

Google によってトリガーされるアンケートのタイミングは、エージェントのメッセージの可用性によって異なります。

対象 アンケートのタイミング
bot のみ 最後のメッセージから 30 分後
人間のみ 最後のメッセージから 24 営業時間
bot と人間 最後のメッセージから 24 営業時間

今後 7 日間の営業時間が 24 時間未満の場合は、24 時間が使用されます。

1 件の会話につき 24 時間ごとに 1 件のアンケートを送信できます。Google より前に会話でアンケートを送信した場合、Google はその会話にアンケートを送信しません。エージェントが 24 時間以内に同じ会話で複数のアンケートを送信した場合、ビジネス メッセージは最初のアンケートのみをユーザーに送信しようとします。

次回ユーザーがアンケートに回答した後、エージェントとの会話を開始すると、エージェントがgreetingを表示します。ユーザーがアンケートに回答しなかった場合、アンケートは 7 日後に期限切れになり、アンケートの有効期限が切れた後の次の会話で挨拶が表示されます。

会話でアンケートが有効なときに、アンケートとは無関係のメッセージがユーザーから送信された場合、ビジネス メッセージによってアンケートがキャンセルされ、ユーザーのメッセージがエージェントの Webhook に送信されます。

ユーザーにアンケートを送信しない場合でも、エージェントは Webhook で Google のアンケートの結果を受け取り、それに応じて処理する必要があります。

質問

アンケートには最大 5 つの質問を含めることができ、必須テンプレートカスタムの 3 つのカテゴリに分けられます。アンケートには必須の質問が常に含まれています。次に、テンプレートの質問を最大 2 つ表示し、その後、カスタムの質問を最大 2 つ表示します。

必須の質問

必須の質問は、ビジネス メッセージでサポートされているすべての言語 / 地域にローカライズされています。ユーザーは、高評価または低評価で応答できます。

必須の質問: 「このメッセージ サービスは AGENT_NAME でニーズに応えていますか?」

テンプレートに関する質問

テンプレートの質問は、ビジネス メッセージでサポートされているすべての言語 / 地域にローカライズされている、Google が定義する任意の質問です。アンケートには、テンプレートの質問を最大 2 つ含めることができます。ユーザーの回答形式は質問によって異なります。

テンプレートの質問の例

  • AGENT_NAME へのメッセージはいかがでしたか?
  • AGENT_NAME を友人にすすめる可能性はどれくらいありますか。
  • 次回 AGENT_NAME に連絡するとき、メッセージ機能を選択する可能性はどの程度ありますか。
  • 全体的に、AGENT_NAME の操作のしやすさはいかがでしたか。
  • 次の記述にどの程度同意しますか。 AGENT_NAME によって問題は簡単に対処できた。
  • サポート担当者について、総合的にどの程度満足されていますか。
  • このチャット セッションは、AGENT_NAME への電話を回避するのに役立ちましたか?

利用可能なすべての質問の一覧を表示し、テンプレート ID を取得するには、

  1. Business Communications デベロッパー コンソールを開き、ビジネス メッセージの Google アカウントでログインします。
  2. エージェントを選択します。
  3. 左側のナビゲーションで [アンケート] をクリックします。

カスタムの質問

1 つのアンケートにはカスタムの質問を最大 2 つ含めることができます。カスタムの質問を指定する場合は、エージェントがサポートする言語 / 地域ごとに質問のバージョンを含めます。デフォルトの言語 / 地域に合わせて、各質問のバージョンを指定する必要があります。ユーザーがアンケートを受け取ったものの、言語 / 地域にカスタムの質問を指定していない場合、その質問はエージェントのデフォルト言語 / 地域で定義されているとおりに表示されます。

カスタムの質問に対する回答では、返信文の候補と同様に、個別のテキスト データとポストバック データがサポートされます。

アンケートをカスタマイズする

エージェント向けにアンケートをカスタマイズするには

  1. Business Communications デベロッパー コンソールを開き、ビジネス メッセージの Google アカウントでログインします。
  2. エージェントを選択します。
  3. 左側のナビゲーションで [アンケート] をクリックします。
  4. アンケートには、テンプレートの質問を最大 2 つ追加します。
  5. [カスタムの質問を作成] をクリックして、アンケートにカスタムの質問を追加します。

書式設定と値のオプションについては、surveyConfig をご覧ください。

アンケートを送信する

アンケート

アンケートを送信するには、次のコマンドを実行します。CONVERSATION_ID は、アンケートを送信する会話の 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 をご覧ください。

アンケートの回答を受け取る

ユーザーがアンケートの質問に回答すると、エージェントは Webhook でその回答を受け取ります。アンケートの回答は、メッセージの受信と同じ方法で受信して処理します。

アンケートの質問はすべて同じ surveyResponse.survey 値になります。アンケートに複数の質問が含まれている場合は、インフラストラクチャが同じ surveyResponse.survey 値を持つ複数の回答を受け入れ、surveyResponse.surveyQuestionId フィールドで個々の質問を識別できるようにしてください。

アンケートの回答のテキスト値は surveyResponse.questionResponseText に表示されます。必須の質問とテンプレートの質問の場合、ビジネス メッセージは「高評価」の応答を VERY_SATISFIED として、「低評価」の応答を VERY_DISSATISFIED として返します。カスタムの質問の回答に絵文字が含まれている場合、Unicode 値を解析するのではなく、surveyResponse.questionResponsePostbackData を使用することをおすすめします。

アンケートの回答の形式は次のとおりです。

{
  "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 をご覧ください。