Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(contact-center-insights): migrate code from googleapis/python-contact-center-insights #8996

Merged
merged 115 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
93d5be8
samples: enable pubsub notifications (#13)
TrucHLe Sep 1, 2021
b64c6a1
chore(deps): update all dependencies (#39)
renovate-bot Sep 1, 2021
c62e2dd
chore(deps): update dependency google-cloud-pubsub to v2.8.0 (#40)
renovate-bot Sep 7, 2021
32e66b5
samples: export data to BigQuery (#45)
TrucHLe Sep 13, 2021
61ad847
feat: filter is used to filter conversations used for issue model tra…
gcf-owl-bot[bot] Sep 20, 2021
fbe592f
samples: create custom highlights (#15)
TrucHLe Sep 20, 2021
50fb4e9
samples: set project-level TTL (#23)
TrucHLe Sep 21, 2021
26edca8
samples: create topic model (#28)
TrucHLe Sep 21, 2021
40d1263
samples: create conversation (#42)
TrucHLe Sep 23, 2021
b0c37c4
samples: create analysis (#44)
TrucHLe Sep 23, 2021
f90d2d9
samples: create conversation with TTL (#43)
TrucHLe Sep 24, 2021
b34509d
samples: get operation (#24)
TrucHLe Sep 24, 2021
a2f9134
chore: release 0.3.1 (#52)
release-please[bot] Sep 27, 2021
6bd5fb1
chore: Update owlbot.py (#53)
nicain Sep 28, 2021
b904a40
chore(deps): update all dependencies (#46)
renovate-bot Sep 28, 2021
6642fc5
chore(deps): update dependency google-auth to v2.2.1 (#55)
renovate-bot Sep 29, 2021
5483271
chore(deps): update dependency google-cloud-contact-center-insights t…
renovate-bot Sep 30, 2021
7e284a3
chore: fail samples nox session if python version is missing (#60)
gcf-owl-bot[bot] Sep 30, 2021
b3e1dc0
chore(deps): update dependency google-cloud-bigquery to v2.28.0 (#61)
renovate-bot Sep 30, 2021
12303a5
chore(deps): update dependency google-cloud-contact-center-insights t…
renovate-bot Oct 5, 2021
3c73a85
chore(deps): update all dependencies (#67)
renovate-bot Oct 7, 2021
7052463
chore(python): Add kokoro configs for python 3.10 samples testing (#71)
gcf-owl-bot[bot] Oct 8, 2021
6993785
chore(deps): update all dependencies (#69)
renovate-bot Oct 11, 2021
0c50f93
chore(deps): update all dependencies (#74)
renovate-bot Oct 13, 2021
2cb459d
chore: delete owlbot.py (#75)
parthea Oct 18, 2021
d7f81dd
chore(deps): update dependency protobuf to v3.19.0 (#77)
renovate-bot Oct 25, 2021
5baab89
chore(deps): update dependency google-auth to v2.3.1 (#78)
renovate-bot Oct 25, 2021
f604747
chore(deps): update dependency google-api-core to v2.2.0 (#81)
renovate-bot Oct 26, 2021
afb68ac
chore(deps): update dependency google-auth to v2.3.2 (#82)
renovate-bot Oct 27, 2021
4b55e8c
chore(deps): update dependency google-cloud-bigquery to v2.29.0 (#83)
renovate-bot Oct 28, 2021
f2fa4ec
chore(deps): update all dependencies (#84)
renovate-bot Oct 29, 2021
8ed94d6
chore(deps): update dependency google-auth to v2.3.3 (#87)
renovate-bot Nov 2, 2021
cdc7a5b
chore(deps): update dependency google-cloud-contact-center-insights t…
renovate-bot Nov 2, 2021
761bf83
chore(deps): update dependency google-api-core to v2.2.2 (#90)
renovate-bot Nov 3, 2021
d972cc6
chore(deps): update all dependencies (#92)
renovate-bot Nov 4, 2021
8f1a8e1
chore(deps): update all dependencies (#94)
renovate-bot Nov 5, 2021
fafeed4
chore(deps): update dependency google-cloud-contact-center-insights t…
renovate-bot Nov 9, 2021
544d447
chore(deps): update dependency google-cloud-pubsub to v2.9.0 (#100)
renovate-bot Nov 11, 2021
498c2b3
chore(deps): update dependency google-cloud-bigquery to v2.31.0 (#106)
renovate-bot Dec 3, 2021
c066edb
chore(deps): update dependency google-api-core to v2.3.0 (#108)
renovate-bot Dec 8, 2021
df30f53
chore(python): fix undefined name 'glob' in samples noxfile (#116)
gcf-owl-bot[bot] Jan 11, 2022
9cc487d
chore(python): Noxfile recognizes that tests can live in a folder (#122)
gcf-owl-bot[bot] Jan 19, 2022
46be4d9
chore: use gapic-generator-python 0.63.2 (#131)
gcf-owl-bot[bot] Feb 11, 2022
836b4be
chore: use gapic-generator-python 0.63.4 (#132)
gcf-owl-bot[bot] Feb 25, 2022
68dd471
chore: update copyright year to 2022 (#133)
gcf-owl-bot[bot] Feb 26, 2022
fadd9ec
fix(deps): require google-api-core>=1.31.5, >=2.3.2 (#136)
parthea Mar 4, 2022
4fd5567
chore: Adding support for pytest-xdist and pytest-parallel (#137)
gcf-owl-bot[bot] Mar 4, 2022
6d9d791
chore(deps): update all dependencies (#140)
renovate-bot Mar 7, 2022
d06119f
chore(deps): update all dependencies (#141)
renovate-bot Mar 7, 2022
c8c6e6a
chore(deps): update dependency google-api-core to v2.7.0 (#142)
renovate-bot Mar 8, 2022
4c30999
chore(deps): update all dependencies (#143)
renovate-bot Mar 10, 2022
b519420
chore(deps): update dependency pytest to v7.1.0 (#144)
renovate-bot Mar 13, 2022
d28ff4b
chore(deps): update all dependencies (#145)
renovate-bot Mar 23, 2022
f125de2
chore(python): use black==22.3.0 (#147)
gcf-owl-bot[bot] Mar 29, 2022
105e93c
chore(deps): update dependency google-cloud-bigquery to v3 (#148)
renovate-bot Mar 30, 2022
a4dd02f
chore(deps): update dependency protobuf to v3.20.0 (#153)
renovate-bot Apr 3, 2022
94173db
chore(deps): update dependency google-cloud-pubsub to v2.12.0 (#155)
renovate-bot Apr 7, 2022
a44c2f0
chore(deps): update dependency google-auth to v2.6.3 (#157)
renovate-bot Apr 7, 2022
123f52d
chore(deps): update dependency google-auth to v2.6.4 (#160)
renovate-bot Apr 13, 2022
cceab2d
chore(deps): update dependency google-api-core to v2.7.2 (#161)
renovate-bot Apr 13, 2022
5b3e49b
chore: use gapic-generator-python 0.65.1 (#162)
gcf-owl-bot[bot] Apr 14, 2022
dbf7750
chore(deps): update dependency google-auth to v2.6.5 (#163)
renovate-bot Apr 15, 2022
f6f8865
chore(python): add nox session to sort python imports (#164)
gcf-owl-bot[bot] Apr 21, 2022
8a37651
chore(deps): update all dependencies (#167)
renovate-bot Apr 22, 2022
4100cac
chore(deps): update dependency pytest to v7.1.2 (#168)
renovate-bot Apr 25, 2022
10b4a62
samples: Add docstring to all code samples (#171)
TrucHLe Apr 28, 2022
086643e
chore(deps): update dependency google-api-core to v2.7.3 (#172)
renovate-bot May 2, 2022
b47f931
chore(deps): update dependency google-cloud-bigquery to v3.1.0 (#176)
renovate-bot May 9, 2022
f956dc7
chore(deps): update dependency google-cloud-pubsub to v2.12.1 (#177)
renovate-bot May 12, 2022
cbf300d
chore(deps): update dependency google-api-core to v2.8.0 (#178)
renovate-bot May 19, 2022
5bc226d
chore(deps): update dependency google-api-core to v2.8.1 (#196)
renovate-bot May 27, 2022
f2c3362
fix: require python 3.7+ (#209)
gcf-owl-bot[bot] Jul 10, 2022
b704958
chore(deps): update all dependencies (#204)
renovate-bot Jul 16, 2022
5e57565
chore(deps): update all dependencies (#217)
renovate-bot Aug 2, 2022
89bc9f4
chore(deps): update all dependencies (#219)
renovate-bot Aug 6, 2022
dc813ee
chore(deps): update all dependencies (#220)
renovate-bot Aug 9, 2022
5717efa
chore(deps): update dependency google-cloud-pubsub to v2.13.5 (#222)
renovate-bot Aug 11, 2022
f62399e
chore(deps): update dependency google-cloud-pubsub to v2.13.6 (#225)
renovate-bot Aug 12, 2022
fa04b11
chore(deps): update all dependencies (#228)
renovate-bot Aug 19, 2022
345e6ba
chore(deps): update dependency google-auth to v2.11.0 (#229)
renovate-bot Aug 23, 2022
91c433d
chore(deps): update dependency google-cloud-contact-center-insights t…
renovate-bot Aug 24, 2022
4e4cd18
chore(deps): update dependency google-api-core to v2.10.0 (#238)
renovate-bot Sep 2, 2022
9ab68e6
chore(deps): update dependency pytest to v7.1.3 (#242)
renovate-bot Sep 6, 2022
52a3bbc
chore: Bump gapic-generator-python version to 1.3.0 (#243)
gcf-owl-bot[bot] Sep 7, 2022
07ff5dd
chore: detect samples tests in nested directories (#246)
gcf-owl-bot[bot] Sep 13, 2022
5b739dd
chore(deps): update dependency google-api-core to v2.10.1 (#247)
renovate-bot Sep 14, 2022
1e1d655
chore(deps): update dependency google-auth to v2.11.1 (#248)
renovate-bot Sep 20, 2022
cadc5b5
chore(deps): update all dependencies (#249)
renovate-bot Oct 4, 2022
dec78aa
chore(deps): update dependency google-cloud-contact-center-insights t…
renovate-bot Oct 4, 2022
deaffe4
chore(deps): update dependency google-api-core to v2.10.2 (#255)
renovate-bot Oct 8, 2022
e574e24
chore(deps): update dependency google-cloud-contact-center-insights t…
renovate-bot Oct 10, 2022
b912402
chore(deps): update all dependencies (#257)
renovate-bot Oct 18, 2022
bd7c6fd
chore(deps): update dependency pytest to v7.2.0 (#258)
renovate-bot Oct 26, 2022
5712db4
chore(deps): update dependency google-auth to v2.14.0 (#260)
renovate-bot Nov 1, 2022
19d6208
chore(deps): update all dependencies (#261)
renovate-bot Nov 21, 2022
d2bd683
chore: Update gapic-generator-python to v1.6.1 (#259)
gcf-owl-bot[bot] Nov 21, 2022
027df8f
chore(python): drop flake8-import-order in samples noxfile (#266)
gcf-owl-bot[bot] Nov 27, 2022
47947b9
fix(deps): Require google-api-core >=1.34.0, >=2.11.0 (#268)
gcf-owl-bot[bot] Dec 7, 2022
cc4c0a3
feat: add Configurable Analysis, Bulk Upload, Bulk Analyze, Delete Is…
gcf-owl-bot[bot] Dec 14, 2022
3943ee3
chore(deps): update all dependencies (#267)
renovate-bot Dec 15, 2022
49b5c21
chore(main): release 1.5.0 (#265)
release-please[bot] Dec 15, 2022
4750a05
chore(deps): update dependency google-cloud-contact-center-insights t…
renovate-bot Dec 16, 2022
15bc09e
chore(python): add support for python 3.11 (#272)
gcf-owl-bot[bot] Jan 6, 2023
bc9bb38
chore(deps): update dependency google-auth to v2.16.0 (#273)
renovate-bot Jan 9, 2023
05229b8
feat: Add support for python 3.11 (#274)
gcf-owl-bot[bot] Jan 10, 2023
0cdc014
chore(main): release 1.6.0 (#275)
release-please[bot] Jan 10, 2023
8bf0774
chore(deps): update dependency google-cloud-pubsub to v2.13.12 (#276)
renovate-bot Jan 10, 2023
04413ee
chore(deps): update dependency google-cloud-contact-center-insights t…
renovate-bot Jan 10, 2023
a616200
chore(deps): update dependency pytest to v7.2.1 (#278)
renovate-bot Jan 14, 2023
bc42627
Merge remote-tracking branch 'migration/main' into python-contact-cen…
telpirion Jan 17, 2023
ba2437d
Merge branch 'main' into python-contact-center-insights-migration
telpirion Jan 18, 2023
323516d
Merge branch 'main' into python-contact-center-insights-migration
telpirion Jan 23, 2023
38fa908
removed 'generated_samples'
telpirion Jan 23, 2023
70c6871
trying to add noxfile
telpirion Jan 23, 2023
f5afd4d
noxfile
telpirion Jan 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions contact-center-insights/snippets/create_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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
#
# http://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.
#
# [START contactcenterinsights_create_analysis]
from google.cloud import contact_center_insights_v1


def create_analysis(conversation_name: str) -> contact_center_insights_v1.Analysis:
"""Creates an analysis.

Args:
conversation_name:
The parent resource of the analysis.
Format is 'projects/{project_id}/locations/{location_id}/conversations/{conversation_id}'.
For example, 'projects/my-project/locations/us-central1/conversations/123456789'.

Returns:
An analysis.
"""
# Construct an analysis.
analysis = contact_center_insights_v1.Analysis()

# Call the Insights client to create an analysis.
insights_client = contact_center_insights_v1.ContactCenterInsightsClient()
analysis_operation = insights_client.create_analysis(
parent=conversation_name, analysis=analysis
)
analysis = analysis_operation.result(timeout=86400)
print(f"Created {analysis.name}")
return analysis


# [END contactcenterinsights_create_analysis]
64 changes: 64 additions & 0 deletions contact-center-insights/snippets/create_conversation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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
#
# http://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.
#
# [START contactcenterinsights_create_conversation]
from google.cloud import contact_center_insights_v1


def create_conversation(
project_id: str,
transcript_uri: str = "gs://cloud-samples-data/ccai/chat_sample.json",
audio_uri: str = "gs://cloud-samples-data/ccai/voice_6912.txt",
) -> contact_center_insights_v1.Conversation:
"""Creates a conversation.

Args:
project_id:
The project identifier. For example, 'my-project'.
transcript_uri:
The Cloud Storage URI that points to a file that contains the
conversation transcript. Format is 'gs://{bucket_name}/{file.json}'.
For example, 'gs://cloud-samples-data/ccai/chat_sample.json'.
audio_uri:
The Cloud Storage URI that points to a file that contains the
conversation audio. Format is 'gs://{bucket_name}/{file.json}'.
For example, 'gs://cloud-samples-data/ccai/voice_6912.txt'.

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

# Construct a conversation.
conversation = contact_center_insights_v1.Conversation()
conversation.data_source.gcs_source.transcript_uri = transcript_uri
conversation.data_source.gcs_source.audio_uri = audio_uri
conversation.medium = contact_center_insights_v1.Conversation.Medium.CHAT

# Call the Insights client to create a conversation.
insights_client = contact_center_insights_v1.ContactCenterInsightsClient()
conversation = insights_client.create_conversation(
parent=parent, conversation=conversation
)

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


# [END contactcenterinsights_create_conversation]
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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
#
# http://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.
#
# Create a conversation with a TTL.
# [START contactcenterinsights_create_conversation_with_ttl]
from google.cloud import contact_center_insights_v1
from google.protobuf import duration_pb2


def create_conversation_with_ttl(
project_id: str,
transcript_uri: str = "gs://cloud-samples-data/ccai/chat_sample.json",
audio_uri: str = "gs://cloud-samples-data/ccai/voice_6912.txt",
) -> contact_center_insights_v1.Conversation:
"""Creates a conversation with a TTL value.

Args:
project_id:
The project identifier. For example, 'my-project'.
transcript_uri:
The Cloud Storage URI that points to a file that contains the
conversation transcript. Format is 'gs://{bucket_name}/{file.json}'.
For example, 'gs://cloud-samples-data/ccai/chat_sample.json'.
audio_uri:
The Cloud Storage URI that points to a file that contains the
conversation audio. Format is 'gs://{bucket_name}/{file.json}'.
For example, 'gs://cloud-samples-data/ccai/voice_6912.txt'.

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

# Construct a conversation.
conversation = contact_center_insights_v1.Conversation()
conversation.data_source.gcs_source.transcript_uri = transcript_uri
conversation.data_source.gcs_source.audio_uri = audio_uri
conversation.medium = contact_center_insights_v1.Conversation.Medium.CHAT

# Construct a TTL.
ttl = duration_pb2.Duration()
ttl.seconds = 86400
conversation.ttl = ttl

# Call the Insights client to create a conversation.
insights_client = contact_center_insights_v1.ContactCenterInsightsClient()
conversation = insights_client.create_conversation(
parent=parent, conversation=conversation
)

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


# [END contactcenterinsights_create_conversation_with_ttl]
52 changes: 52 additions & 0 deletions contact-center-insights/snippets/create_issue_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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
#
# http://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.
#
# [START contactcenterinsights_create_issue_model]
from google.cloud import contact_center_insights_v1


def create_issue_model(project_id: str) -> contact_center_insights_v1.IssueModel:
"""Creates an issue model.

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

Returns:
An issue model.
"""
# Construct a parent resource.
parent = (
contact_center_insights_v1.ContactCenterInsightsClient.common_location_path(
project_id, "us-central1"
)
)

# Construct an issue model.
issue_model = contact_center_insights_v1.IssueModel()
issue_model.display_name = "my-model"
issue_model.input_data_config.filter = 'medium="CHAT"'

# Call the Insights client to create an issue model.
insights_client = contact_center_insights_v1.ContactCenterInsightsClient()
issue_model_operation = insights_client.create_issue_model(
parent=parent, issue_model=issue_model
)

issue_model = issue_model_operation.result(timeout=86400)
print(f"Created an issue model named {issue_model.name}")
return issue_model


# [END contactcenterinsights_create_issue_model]
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 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
#
# http://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.
#
# [START contactcenterinsights_create_phrase_matcher_all_of]
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


# [END contactcenterinsights_create_phrase_matcher_all_of]
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 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
#
# http://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.
#
# [START contactcenterinsights_create_phrase_matcher_any_of]
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


# [END contactcenterinsights_create_phrase_matcher_any_of]
Loading