使用自訂醒目顯示功能分析對話

總覽

自訂精選內容的運作方式與智慧精選內容功能類似。重點包含 CX Insights 認為有助於判斷使用者意圖的關鍵字、詞組或句子。如果轉錄稿中包含重點內容,系統會標示出來。 智慧精選片段會根據一系列預設情境自動偵測精選片段,自訂精選片段則可讓您指定應視為精選片段的自訂條件。

自訂醒目顯示內容可由一或多個詞組比對規則群組組成。 片語比對規則群組包含一或多個規則。您可以使用下列參數自訂規則的行為。

決定比對結果的規則

您可以指定只要其中一個規則群組解析為 true,就應偵測到醒目顯示,或是所有規則群組都解析為 true 時才應偵測到醒目顯示。 同樣地,您可以指定規則群組應解析為 true (只要符合其中一項規則),或規則群組中所有規則的條件都必須符合。

使用 CX Insights API 建立自訂重點

偵測「任何一個」指定的查詢字串清單

下列範例會建立 PhraseMatcher 物件,指示 CX Insights 在對話中出現任一片語時,加入精選標籤。系統不一定會偵測到這兩個片語,才會將其視為重點。

REST

如需完整詳細資料,請參閱PhraseMatcherTypePhraseMatchRuleGroupType 參考說明文件。將兩個 query 欄位分別替換為 PHONECELLPHONE,應該會產生範例輸出內容。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的 Google Cloud 專案 ID。
  • DISPLAY_NAME:片語比對工具的易讀名稱。
  • QUERY:要比對的字詞或詞組。

HTTP 方法和網址:

POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/phraseMatchers

JSON 要求主體:

{
  "display_name": DISPLAY_NAME,
  "type": "ANY_OF",
  "active": true,
  "phrase_match_rule_groups": {
    "type": "ANY_OF",
    "phrase_match_rules": {
      "query": QUERY
      "config": {
        "exact_match_config": {}
      }
    },
    "phrase_match_rules": {
      "query": QUERY
      "config": {
        "exact_match_config": {}
      }
    }
  }
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/PROJECT_ID/locations/us-central1/phraseMatchers/PHRASE_MATCHER_ID",
  "revisionId": "REVISION_ID",
  "revisionCreateTime": "2021-01-20T10:10:10.123000Z",
  "displayName": "PHONE_SERVICE",
  "type": "ANY_OF",
  "active": true,
  "phraseMatchRuleGroups": [
    {
      "type": "ANY_OF",
      "phraseMatchRules": [
        {
          "query": "PHONE",
          "config": {
            "exactMatchConfig": {}
          }
        },
        {
          "query": "CELLPHONE",
          "config": {
            "exactMatchConfig": {}
          }
        }
      ]
    }
  ],
  "activationUpdateTime": "2021-01-20T10:10:10.123000Z"
}

Python

如要向 CX Insights 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

from google.cloud import contact_center_insights_v1


def create_phrase_matcher_any_of(
    project_id: str,
) -> contact_center_insights_v1.PhraseMatcher:
    """Creates a phrase matcher that matches any of the specified queries.

    Args:
        project_id:
            The project identifier. For example, 'my-project'.

    Returns:
        A phrase matcher.
    """
    # Construct a parent resource.
    parent = (
        contact_center_insights_v1.ContactCenterInsightsClient.common_location_path(
            project_id, "us-central1"
        )
    )

    # Construct a phrase matcher that matches any of its rule groups.
    phrase_matcher = contact_center_insights_v1.PhraseMatcher()
    phrase_matcher.display_name = "PHONE_SERVICE"
    phrase_matcher.type_ = (
        contact_center_insights_v1.PhraseMatcher.PhraseMatcherType.ANY_OF
    )
    phrase_matcher.active = True

    # Construct a rule group to match the word "PHONE" or "CELLPHONE", ignoring case sensitivity.
    rule_group = contact_center_insights_v1.PhraseMatchRuleGroup()
    rule_group.type_ = (
        contact_center_insights_v1.PhraseMatchRuleGroup.PhraseMatchRuleGroupType.ANY_OF
    )

    for word in ["PHONE", "CELLPHONE"]:
        rule = contact_center_insights_v1.PhraseMatchRule()
        rule.query = word
        rule.config.exact_match_config = contact_center_insights_v1.ExactMatchConfig()
        rule_group.phrase_match_rules.append(rule)
    phrase_matcher.phrase_match_rule_groups.append(rule_group)

    # Call the Insights client to create a phrase matcher.
    insights_client = contact_center_insights_v1.ContactCenterInsightsClient()
    phrase_matcher = insights_client.create_phrase_matcher(
        parent=parent, phrase_matcher=phrase_matcher
    )

    print(f"Created {phrase_matcher.name}")
    return phrase_matcher

Java

如要向 CX Insights 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。


import com.google.cloud.contactcenterinsights.v1.ContactCenterInsightsClient;
import com.google.cloud.contactcenterinsights.v1.ExactMatchConfig;
import com.google.cloud.contactcenterinsights.v1.LocationName;
import com.google.cloud.contactcenterinsights.v1.PhraseMatchRule;
import com.google.cloud.contactcenterinsights.v1.PhraseMatchRuleConfig;
import com.google.cloud.contactcenterinsights.v1.PhraseMatchRuleGroup;
import com.google.cloud.contactcenterinsights.v1.PhraseMatcher;
import java.io.IOException;

public class CreatePhraseMatcherAnyOf {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace this variable before running the sample.
    String projectId = "my_project_id";

    createPhraseMatcherAnyOf(projectId);
  }

  public static PhraseMatcher createPhraseMatcherAnyOf(String projectId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (ContactCenterInsightsClient client = ContactCenterInsightsClient.create()) {
      // Construct a phrase matcher that matches any of its rule groups.
      PhraseMatcher.Builder phraseMatcher =
          PhraseMatcher.newBuilder()
              .setDisplayName("PHONE_SERVICE")
              .setTypeValue(2)
              .setActive(true);

      // Construct a rule group to match the word "PHONE" or "CELLPHONE", ignoring case sensitivity.
      PhraseMatchRuleGroup.Builder ruleGroup = PhraseMatchRuleGroup.newBuilder().setTypeValue(2);

      String[] words = {"PHONE", "CELLPHONE"};
      for (String w : words) {
        PhraseMatchRule.Builder rule =
            PhraseMatchRule.newBuilder()
                .setQuery(w)
                .setConfig(
                    PhraseMatchRuleConfig.newBuilder()
                        .setExactMatchConfig(ExactMatchConfig.newBuilder().build())
                        .build());
        ruleGroup.addPhraseMatchRules(rule.build());
      }
      phraseMatcher.addPhraseMatchRuleGroups(ruleGroup.build());

      // Construct a parent resource.
      LocationName parent = LocationName.of(projectId, "us-central1");

      // Call the Insights client to create a phrase matcher.
      PhraseMatcher response = client.createPhraseMatcher(parent, phraseMatcher.build());
      System.out.printf("Created %s%n", response.getName());
      return response;
    }
  }
}

Node.js

如要向 CX Insights 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

/**
 * TODO(developer): Uncomment this variable before running the sample.
 */
// const projectId = 'my_project_id';

// Imports the Contact Center Insights client.
const {
  ContactCenterInsightsClient,
} = require('@google-cloud/contact-center-insights');

// Instantiates a client.
const client = new ContactCenterInsightsClient();

async function createPhraseMatcherAnyOf() {
  const [phraseMatcher] = await client.createPhraseMatcher({
    parent: client.locationPath(projectId, 'us-central1'),
    phraseMatcher: {
      displayName: 'PHONE_SERVICE',
      type: 'ANY_OF',
      active: true,
      phraseMatchRuleGroups: [
        {
          type: 'ANY_OF',
          phraseMatchRules: [
            {
              query: 'PHONE',
              config: {
                exactMatchConfig: {},
              },
            },
            {
              query: 'CELLPHONE',
              config: {
                exactMatchConfig: {},
              },
            },
          ],
        },
      ],
    },
  });
  console.info(`Created ${phraseMatcher.name}`);
}
createPhraseMatcherAnyOf();

偵測「所有」指定查詢字串清單

下列範例會建立 PhraseMatcher 物件,指示 CX Insights 在包含第一個 phraseMatchRuleGroups 中查詢字詞的對話中新增醒目顯示標籤,但「不」包含第二個 `phraseMatchRuleGroups` 中的查詢字詞。

REST

如需完整詳細資料,請參閱PhraseMatcherTypePhraseMatchRuleGroupType 參考說明文件。將前兩個 query 欄位替換為 PHONECELLPHONE,並將後兩個 query 欄位替換為 SHIPPINGDELIVERY,應該會產生範例輸出內容。這個範例會指示 CX Insights 在包含「手機」和「行動電話」,但不包含「運送」或「交貨」的對話中,加入重點標籤。

使用任何要求資料之前,請先修改下列項目的值:

  • PROJECT_ID:您的 Google Cloud 專案 ID。
  • DISPLAY_NAME:片語比對工具的易讀名稱。
  • QUERY:要比對的字詞或詞組。

HTTP 方法和網址:

POST https://contactcenterinsights.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/phraseMatchers

JSON 要求主體:

{
  "display_name": DISPLAY_NAME,
  "type": "ALL_OF",
  "active": true,
  "phrase_match_rule_groups": {
    "type": "ANY_OF",
    "phrase_match_rules": {
      "query": QUERY
      "config": {
        "exact_match_config": {}
      }
    },
    "phrase_match_rules": {
      "query": QUERY
      "config": {
        "exact_match_config": {}
      }
    },
    "phrase_match_rule_groups": {
      "type": "ALL_OF",
      "phrase_match_rules": {
        "query": QUERY
        "negated": "true"
        "config": {
          "exact_match_config": {}
        }
      },
      "phrase_match_rules": {
        "query": QUERY
        "negated": "true"
        "config": {
          "exact_match_config": {}
        }
      }
    }
  }
}

請展開以下其中一個選項,以傳送要求:

您應該會收到如下的 JSON 回覆:

{
  "name": "projects/PROJECT_ID/locations/us-central1/phraseMatchers/PHRASE_MATCHER_ID",
  "revisionId": "456456456",
  "revisionCreateTime": "2021-01-20T10:10:10.123000Z",
  "displayName": "NON_SHIPPING_PHONE_SERVICE",
  "type": "ALL_OF",
  "active": true,
  "phraseMatchRuleGroups": [
    {
      "type": "ANY_OF",
      "phraseMatchRules": [
        {
          "query": "PHONE",
          "config": {
            "exactMatchConfig": {}
          }
        },
        {
          "query": "CELLPHONE",
          "config": {
            "exactMatchConfig": {}
          }
        }
      ]
    },
    {
      "type": "ALL_OF",
      "phraseMatchRules": [
        {
          "query": "SHIPPING",
          "negated": true,
          "config": {
            "exactMatchConfig": {}
          }
        },
        {
          "query": "DELIVERY",
          "negated": true,
          "config": {
            "exactMatchConfig": {}
          }
        }
      ]
    }
  ],
  "activationUpdateTime": "2021-01-20T10:10:10.123000Z"
}

Python

如要向 CX Insights 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

from google.cloud import contact_center_insights_v1


def create_phrase_matcher_all_of(
    project_id: str,
) -> contact_center_insights_v1.PhraseMatcher:
    """Creates a phrase matcher that matches all specified queries.

    Args:
        project_id:
            The project identifier. For example, 'my-project'.

    Returns:
        A phrase matcher.
    """
    # Construct a parent resource.
    parent = (
        contact_center_insights_v1.ContactCenterInsightsClient.common_location_path(
            project_id, "us-central1"
        )
    )

    # Construct a phrase matcher that matches all of its rule groups.
    phrase_matcher = contact_center_insights_v1.PhraseMatcher()
    phrase_matcher.display_name = "NON_SHIPPING_PHONE_SERVICE"
    phrase_matcher.type_ = (
        contact_center_insights_v1.PhraseMatcher.PhraseMatcherType.ALL_OF
    )
    phrase_matcher.active = True

    # Construct a rule group to match the word "PHONE" or "CELLPHONE", ignoring case sensitivity.
    rule_group_phone_or_cellphone = contact_center_insights_v1.PhraseMatchRuleGroup()
    rule_group_phone_or_cellphone.type_ = (
        contact_center_insights_v1.PhraseMatchRuleGroup.PhraseMatchRuleGroupType.ANY_OF
    )

    for word in ["PHONE", "CELLPHONE"]:
        rule = contact_center_insights_v1.PhraseMatchRule()
        rule.query = word
        rule.config.exact_match_config = contact_center_insights_v1.ExactMatchConfig()
        rule_group_phone_or_cellphone.phrase_match_rules.append(rule)
    phrase_matcher.phrase_match_rule_groups.append(rule_group_phone_or_cellphone)

    # Construct another rule group to not match the word "SHIPPING" or "DELIVERY", ignoring case sensitivity.
    rule_group_not_shipping_or_delivery = (
        contact_center_insights_v1.PhraseMatchRuleGroup()
    )
    rule_group_not_shipping_or_delivery.type_ = (
        contact_center_insights_v1.PhraseMatchRuleGroup.PhraseMatchRuleGroupType.ALL_OF
    )

    for word in ["SHIPPING", "DELIVERY"]:
        rule = contact_center_insights_v1.PhraseMatchRule()
        rule.query = word
        rule.negated = True
        rule.config.exact_match_config = contact_center_insights_v1.ExactMatchConfig()
        rule_group_not_shipping_or_delivery.phrase_match_rules.append(rule)
    phrase_matcher.phrase_match_rule_groups.append(rule_group_not_shipping_or_delivery)

    # Call the Insights client to create a phrase matcher.
    insights_client = contact_center_insights_v1.ContactCenterInsightsClient()
    phrase_matcher = insights_client.create_phrase_matcher(
        parent=parent, phrase_matcher=phrase_matcher
    )

    print(f"Created {phrase_matcher.name}")
    return phrase_matcher

Java

如要向 CX Insights 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。


import com.google.cloud.contactcenterinsights.v1.ContactCenterInsightsClient;
import com.google.cloud.contactcenterinsights.v1.ExactMatchConfig;
import com.google.cloud.contactcenterinsights.v1.LocationName;
import com.google.cloud.contactcenterinsights.v1.PhraseMatchRule;
import com.google.cloud.contactcenterinsights.v1.PhraseMatchRuleConfig;
import com.google.cloud.contactcenterinsights.v1.PhraseMatchRuleGroup;
import com.google.cloud.contactcenterinsights.v1.PhraseMatcher;
import java.io.IOException;

public class CreatePhraseMatcherAllOf {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace this variable before running the sample.
    String projectId = "my_project_id";

    createPhraseMatcherAllOf(projectId);
  }

  public static PhraseMatcher createPhraseMatcherAllOf(String projectId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (ContactCenterInsightsClient client = ContactCenterInsightsClient.create()) {
      // Construct a phrase matcher that matches all of its rule groups.
      PhraseMatcher.Builder phraseMatcher =
          PhraseMatcher.newBuilder()
              .setDisplayName("NON_SHIPPING_PHONE_SERVICE")
              .setTypeValue(1)
              .setActive(true);

      // Construct a rule group to match the word "PHONE" or "CELLPHONE", ignoring case sensitivity.
      PhraseMatchRuleGroup.Builder ruleGroup1 = PhraseMatchRuleGroup.newBuilder().setTypeValue(2);

      String[] words1 = {"PHONE", "CELLPHONE"};
      for (String w : words1) {
        PhraseMatchRule.Builder rule =
            PhraseMatchRule.newBuilder()
                .setQuery(w)
                .setConfig(
                    PhraseMatchRuleConfig.newBuilder()
                        .setExactMatchConfig(ExactMatchConfig.newBuilder().build())
                        .build());
        ruleGroup1.addPhraseMatchRules(rule.build());
      }
      phraseMatcher.addPhraseMatchRuleGroups(ruleGroup1.build());

      // Construct another rule group to not match the word "SHIPPING" or "DELIVERY",
      // ignoring case sensitivity.
      PhraseMatchRuleGroup.Builder ruleGroup2 = PhraseMatchRuleGroup.newBuilder().setTypeValue(1);

      String[] words2 = {"SHIPPING", "DELIVERY"};
      for (String w : words2) {
        PhraseMatchRule.Builder rule =
            PhraseMatchRule.newBuilder()
                .setQuery(w)
                .setNegated(true)
                .setConfig(
                    PhraseMatchRuleConfig.newBuilder()
                        .setExactMatchConfig(ExactMatchConfig.newBuilder().build())
                        .build());
        ruleGroup2.addPhraseMatchRules(rule.build());
      }
      phraseMatcher.addPhraseMatchRuleGroups(ruleGroup2.build());

      // Construct a parent resource.
      LocationName parent = LocationName.of(projectId, "us-central1");

      // Call the Insights client to create a phrase matcher.
      PhraseMatcher response = client.createPhraseMatcher(parent, phraseMatcher.build());
      System.out.printf("Created %s%n", response.getName());
      return response;
    }
  }
}

Node.js

如要向 CX Insights 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

/**
 * TODO(developer): Uncomment this variable before running the sample.
 */
// const projectId = 'my_project_id';

// Imports the Contact Center Insights client.
const {
  ContactCenterInsightsClient,
} = require('@google-cloud/contact-center-insights');

// Instantiates a client.
const client = new ContactCenterInsightsClient();

async function createPhraseMatcherAllOf() {
  const [phraseMatcher] = await client.createPhraseMatcher({
    parent: client.locationPath(projectId, 'us-central1'),
    phraseMatcher: {
      displayName: 'NON_SHIPPING_PHONE_SERVICE',
      type: 'ALL_OF',
      active: true,
      phraseMatchRuleGroups: [
        {
          type: 'ANY_OF',
          phraseMatchRules: [
            {
              query: 'PHONE',
              config: {
                exactMatchConfig: {},
              },
            },
            {
              query: 'CELLPHONE',
              config: {
                exactMatchConfig: {},
              },
            },
          ],
        },
        {
          type: 'ALL_OF',
          phraseMatchRules: [
            {
              query: 'SHIPPING',
              negated: true,
              config: {
                exactMatchConfig: {},
              },
            },
            {
              query: 'DELIVERY',
              negated: true,
              config: {
                exactMatchConfig: {},
              },
            },
          ],
        },
      ],
    },
  });
  console.info(`Created ${phraseMatcher.name}`);
}
createPhraseMatcherAllOf();