From 4e8ae91243a4740ded3d96c42902842d439cebcc Mon Sep 17 00:00:00 2001 From: Eric Schmidt Date: Mon, 23 Jan 2023 16:16:39 -0800 Subject: [PATCH] chore(contact-center-insights): migrate code from googleapis/python-contact-center-insights (#8996) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * samples: enable pubsub notifications (#13) * samples: initial update pubsub notifications samples * Make the sample closely resemble the public Curl snippet * Rearrange tech writer tags * Clean up tests * move region tags * use fstring * use built-in settings path builder * remove region tag from helper function * Fix code samples according to review * add pytest to requirements-test.txt * Use double quotes for consistency * Assert message in test * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * reorder import groups * lint * Use pytest fixture and autoformat with Nox * disable pubsub notifications when tearing down test Co-authored-by: Owl Bot Co-authored-by: Eric Schmidt * chore(deps): update all dependencies (#39) * chore(deps): update all dependencies * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot * chore(deps): update dependency google-cloud-pubsub to v2.8.0 (#40) * samples: export data to BigQuery (#45) * feat: filter is used to filter conversations used for issue model training feat: update_time is used to indicate when the phrase matcher was updated (#48) * samples: create custom highlights (#15) * samples: set project-level TTL (#23) * samples: create topic model (#28) * samples: create conversation (#42) * samples: create analysis (#44) * samples: create conversation with TTL (#43) * samples: get operation (#24) * chore: release 0.3.1 (#52) :robot: I have created a release \*beep\* \*boop\* --- ### [0.3.1](https://www.github.com/googleapis/python-contact-center-insights/compare/v0.3.0...v0.3.1) (2021-09-24) ### Bug Fixes * add 'dict' annotation type to 'request' ([94e64ac](https://www.github.com/googleapis/python-contact-center-insights/commit/94e64acc866eeed789768c2e216dad3f561c81e3)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). * chore: Update owlbot.py (#53) * Update owlbot.py Update copyright year to unblock https://github.com/googleapis/python-contact-center-insights/pull/46 https://github.com/googleapis/python-contact-center-insights/pull/46/files#r717178756 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: edit owlbot.py copyright yeat chore: Update copyright year to unblock #46 https://github.com/googleapis/python-contact-center-insights/pull/46/files#r717178756 Co-authored-by: Owl Bot * chore(deps): update all dependencies (#46) * chore(deps): update dependency google-auth to v2.2.1 (#55) [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google-auth](https://togithub.com/googleapis/google-auth-library-python) | `==2.2.0` -> `==2.2.1` | [![age](https://badges.renovateapi.com/packages/pypi/google-auth/2.2.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-auth/2.2.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-auth/2.2.1/compatibility-slim/2.2.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-auth/2.2.1/confidence-slim/2.2.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
googleapis/google-auth-library-python ### [`v2.2.1`](https://togithub.com/googleapis/google-auth-library-python/blob/master/CHANGELOG.md#​221-httpswwwgithubcomgoogleapisgoogle-auth-library-pythoncomparev220v221-2021-09-28) [Compare Source](https://togithub.com/googleapis/google-auth-library-python/compare/v2.2.0...v2.2.1)
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-contact-center-insights). * chore(deps): update dependency google-cloud-contact-center-insights to v0.4.0 (#57) [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google-cloud-contact-center-insights](https://togithub.com/googleapis/python-contact-center-insights) | `==0.3.1` -> `==0.4.0` | [![age](https://badges.renovateapi.com/packages/pypi/google-cloud-contact-center-insights/0.4.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-cloud-contact-center-insights/0.4.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-cloud-contact-center-insights/0.4.0/compatibility-slim/0.3.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-cloud-contact-center-insights/0.4.0/confidence-slim/0.3.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
googleapis/python-contact-center-insights ### [`v0.4.0`](https://togithub.com/googleapis/python-contact-center-insights/blob/master/CHANGELOG.md#​040-httpswwwgithubcomgoogleapispython-contact-center-insightscomparev031v040-2021-09-29) [Compare Source](https://togithub.com/googleapis/python-contact-center-insights/compare/v0.3.1...v0.4.0) ##### Features - add metadata from dialogflow related to transcript segment ([#​54](https://www.togithub.com/googleapis/python-contact-center-insights/issues/54)) ([ef575cf](https://www.github.com/googleapis/python-contact-center-insights/commit/ef575cf076376261c784b9c3332ef2befa1a11d9)) - add obfuscated if from dialogflow ([ef575cf](https://www.github.com/googleapis/python-contact-center-insights/commit/ef575cf076376261c784b9c3332ef2befa1a11d9)) - add sentiment data for transcript segment ([ef575cf](https://www.github.com/googleapis/python-contact-center-insights/commit/ef575cf076376261c784b9c3332ef2befa1a11d9)) ##### [0.3.1](https://www.github.com/googleapis/python-contact-center-insights/compare/v0.3.0...v0.3.1) (2021-09-24) ##### Bug Fixes - add 'dict' annotation type to 'request' ([94e64ac](https://www.github.com/googleapis/python-contact-center-insights/commit/94e64acc866eeed789768c2e216dad3f561c81e3))
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-contact-center-insights). * chore: fail samples nox session if python version is missing (#60) * chore(deps): update dependency google-cloud-bigquery to v2.28.0 (#61) [![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [google-cloud-bigquery](https://togithub.com/googleapis/python-bigquery) | `==2.27.1` -> `==2.28.0` | [![age](https://badges.renovateapi.com/packages/pypi/google-cloud-bigquery/2.28.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-cloud-bigquery/2.28.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-cloud-bigquery/2.28.0/compatibility-slim/2.27.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-cloud-bigquery/2.28.0/confidence-slim/2.27.1)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes
googleapis/python-bigquery ### [`v2.28.0`](https://togithub.com/googleapis/python-bigquery/blob/master/CHANGELOG.md#​2280-httpswwwgithubcomgoogleapispython-bigquerycomparev2271v2280-2021-09-30) [Compare Source](https://togithub.com/googleapis/python-bigquery/compare/v2.27.1...v2.28.0) ##### Features - add `AvroOptions` to configure AVRO external data ([#​994](https://www.togithub.com/googleapis/python-bigquery/issues/994)) ([1a9431d](https://www.github.com/googleapis/python-bigquery/commit/1a9431d9e02eeb99e4712b61c623f9cca80134a6)) ##### Documentation - link to stable pandas docs ([#​990](https://www.togithub.com/googleapis/python-bigquery/issues/990)) ([ea50e80](https://www.github.com/googleapis/python-bigquery/commit/ea50e8031fc035b3772a338bc00982de263cefad)) ##### [2.27.1](https://www.github.com/googleapis/python-bigquery/compare/v2.27.0...v2.27.1) (2021-09-27) ##### Bug Fixes - remove py.typed since package fails mypy check ([#​988](https://www.togithub.com/googleapis/python-bigquery/issues/988)) ([39030f2](https://www.github.com/googleapis/python-bigquery/commit/39030f26ce081cfacd456b84694c68e3f04ed48d))
--- ### Configuration 📅 **Schedule**: At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box. --- This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-contact-center-insights). * chore(deps): update dependency google-cloud-contact-center-insights to v0.5.0 (#65) Co-authored-by: nicain * chore(deps): update all dependencies (#67) * chore(python): Add kokoro configs for python 3.10 samples testing (#71) * chore(deps): update all dependencies (#69) Co-authored-by: Anthonios Partheniou * chore(deps): update all dependencies (#74) * chore: delete owlbot.py (#75) * chore: delete owlbot.py * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot * chore(deps): update dependency protobuf to v3.19.0 (#77) * chore(deps): update dependency google-auth to v2.3.1 (#78) * chore(deps): update dependency google-api-core to v2.2.0 (#81) * chore(deps): update dependency google-auth to v2.3.2 (#82) * chore(deps): update dependency google-cloud-bigquery to v2.29.0 (#83) * chore(deps): update all dependencies (#84) * chore(deps): update dependency google-auth to v2.3.3 (#87) * chore(deps): update dependency google-cloud-contact-center-insights to v0.6.1 (#88) * chore(deps): update dependency google-api-core to v2.2.2 (#90) Co-authored-by: Anthonios Partheniou * chore(deps): update all dependencies (#92) * chore(deps): update all dependencies (#94) * chore(deps): update all dependencies * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou * chore(deps): update dependency google-cloud-contact-center-insights to v1.1.0 (#98) * chore(deps): update dependency google-cloud-pubsub to v2.9.0 (#100) * chore(deps): update dependency google-cloud-bigquery to v2.31.0 (#106) * chore(deps): update dependency google-api-core to v2.3.0 (#108) * chore(python): fix undefined name 'glob' in samples noxfile (#116) Source-Link: https://github.com/googleapis/synthtool/commit/52aef91f8d25223d9dbdb4aebd94ba8eea2101f3 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:36a95b8f494e4674dc9eee9af98961293b51b86b3649942aac800ae6c1f796d4 Co-authored-by: Owl Bot * chore(python): Noxfile recognizes that tests can live in a folder (#122) Source-Link: https://github.com/googleapis/synthtool/commit/4760d8dce1351d93658cb11d02a1b7ceb23ae5d7 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f0e4b51deef56bed74d3e2359c583fc104a8d6367da3984fc5c66938db738828 Co-authored-by: Owl Bot * chore: use gapic-generator-python 0.63.2 (#131) * chore: use gapic-generator-python 0.63.2 docs: add generated snippets PiperOrigin-RevId: 427792504 Source-Link: https://github.com/googleapis/googleapis/commit/55b9e1e0b3106c850d13958352bc0751147b6b15 Source-Link: https://github.com/googleapis/googleapis-gen/commit/bf4e86b753f42cb0edb1fd51fbe840d7da0a1cde Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYmY0ZTg2Yjc1M2Y0MmNiMGVkYjFmZDUxZmJlODQwZDdkYTBhMWNkZSJ9 * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot * chore: use gapic-generator-python 0.63.4 (#132) * chore: use gapic-generator-python 0.63.4 chore: fix snippet region tag format chore: fix docstring code block formatting PiperOrigin-RevId: 430730865 Source-Link: https://github.com/googleapis/googleapis/commit/ea5800229f73f94fd7204915a86ed09dcddf429a Source-Link: https://github.com/googleapis/googleapis-gen/commit/ca893ff8af25fc7fe001de1405a517d80446ecca Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiY2E4OTNmZjhhZjI1ZmM3ZmUwMDFkZTE0MDVhNTE3ZDgwNDQ2ZWNjYSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore: delete duplicates Co-authored-by: Owl Bot Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> * chore: update copyright year to 2022 (#133) * chore: update copyright year to 2022 PiperOrigin-RevId: 431037888 Source-Link: https://github.com/googleapis/googleapis/commit/b3397f5febbf21dfc69b875ddabaf76bee765058 Source-Link: https://github.com/googleapis/googleapis-gen/commit/510b54e1cdefd53173984df16645081308fe897e Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNTEwYjU0ZTFjZGVmZDUzMTczOTg0ZGYxNjY0NTA4MTMwOGZlODk3ZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot * fix(deps): require google-api-core>=1.31.5, >=2.3.2 (#136) * chore: Adding support for pytest-xdist and pytest-parallel (#137) Source-Link: https://github.com/googleapis/synthtool/commit/82f5cb283efffe96e1b6cd634738e0e7de2cd90a Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:5d8da01438ece4021d135433f2cf3227aa39ef0eaccc941d62aa35e6902832ae Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou * chore(deps): update all dependencies (#140) * chore(deps): update all dependencies (#141) * chore(deps): update dependency google-api-core to v2.7.0 (#142) * chore(deps): update all dependencies (#143) * chore(deps): update dependency pytest to v7.1.0 (#144) * chore(deps): update all dependencies (#145) * chore(python): use black==22.3.0 (#147) Source-Link: https://github.com/googleapis/synthtool/commit/6fab84af09f2cf89a031fd8671d1def6b2931b11 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:7cffbc10910c3ab1b852c05114a08d374c195a81cdec1d4a67a1d129331d0bfe * chore(deps): update dependency google-cloud-bigquery to v3 (#148) * chore(deps): update dependency protobuf to v3.20.0 (#153) * chore(deps): update dependency google-cloud-pubsub to v2.12.0 (#155) * chore(deps): update dependency google-auth to v2.6.3 (#157) * chore(deps): update dependency google-auth to v2.6.4 (#160) * chore(deps): update dependency google-api-core to v2.7.2 (#161) * chore: use gapic-generator-python 0.65.1 (#162) * chore: use gapic-generator-python 0.65.1 PiperOrigin-RevId: 441524537 Source-Link: https://github.com/googleapis/googleapis/commit/2a273915b3f70fe86c9d2a75470a0b83e48d0abf Source-Link: https://github.com/googleapis/googleapis-gen/commit/ab6756a48c89b5bcb9fb73443cb8e55d574f4643 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWI2NzU2YTQ4Yzg5YjViY2I5ZmI3MzQ0M2NiOGU1NWQ1NzRmNDY0MyJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou * chore(deps): update dependency google-auth to v2.6.5 (#163) * chore(python): add nox session to sort python imports (#164) Source-Link: https://github.com/googleapis/synthtool/commit/1b71c10e20de7ed3f97f692f99a0e3399b67049f Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:00c9d764fd1cd56265f12a5ef4b99a0c9e87cf261018099141e2ca5158890416 Co-authored-by: Owl Bot * chore(deps): update all dependencies (#167) * chore(deps): update dependency pytest to v7.1.2 (#168) * samples: Add docstring to all code samples (#171) * samples: Add docstring to all code samples * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot * chore(deps): update dependency google-api-core to v2.7.3 (#172) * chore(deps): update dependency google-cloud-bigquery to v3.1.0 (#176) * chore(deps): update dependency google-cloud-pubsub to v2.12.1 (#177) * chore(deps): update dependency google-api-core to v2.8.0 (#178) * chore(deps): update dependency google-api-core to v2.8.1 (#196) * fix: require python 3.7+ (#209) * chore(python): drop python 3.6 Source-Link: https://github.com/googleapis/synthtool/commit/4f89b13af10d086458f9b379e56a614f9d6dab7b Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:e7bb19d47c13839fe8c147e50e02e8b6cf5da8edd1af8b82208cd6f66cc2829c * add api_description to .repo-metadata.json * require python 3.7+ in setup.py * remove python 3.6 sample configs * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix typo * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou * chore(deps): update all dependencies (#204) * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert * revert * revert Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou * chore(deps): update all dependencies (#217) * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert * remove protobuf * remove protobuf Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou * chore(deps): update all dependencies (#219) * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou * chore(deps): update all dependencies (#220) * chore(deps): update all dependencies * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * revert Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou * chore(deps): update dependency google-cloud-pubsub to v2.13.5 (#222) * chore(deps): update dependency google-cloud-pubsub to v2.13.6 (#225) * chore(deps): update all dependencies (#228) * chore(deps): update dependency google-auth to v2.11.0 (#229) Co-authored-by: Anthonios Partheniou * chore(deps): update dependency google-cloud-contact-center-insights to v1.4.3 (#232) * chore(deps): update dependency google-api-core to v2.10.0 (#238) * chore(deps): update dependency google-api-core to v2.10.0 * revert Co-authored-by: Anthonios Partheniou * chore(deps): update dependency pytest to v7.1.3 (#242) * chore: Bump gapic-generator-python version to 1.3.0 (#243) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 472561635 Source-Link: https://github.com/googleapis/googleapis/commit/332ecf599f8e747d8d1213b77ae7db26eff12814 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4313d682880fd9d7247291164d4e9d3d5bd9f177 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNDMxM2Q2ODI4ODBmZDlkNzI0NzI5MTE2NGQ0ZTlkM2Q1YmQ5ZjE3NyJ9 * chore: detect samples tests in nested directories (#246) Source-Link: https://github.com/googleapis/synthtool/commit/50db768f450a50d7c1fd62513c113c9bb96fd434 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:e09366bdf0fd9c8976592988390b24d53583dd9f002d476934da43725adbb978 * chore(deps): update dependency google-api-core to v2.10.1 (#247) * chore(deps): update dependency google-auth to v2.11.1 (#248) * chore(deps): update all dependencies (#249) Co-authored-by: Anthonios Partheniou * chore(deps): update dependency google-cloud-contact-center-insights to v1.4.4 (#252) * chore(deps): update dependency google-api-core to v2.10.2 (#255) * chore(deps): update dependency google-cloud-contact-center-insights to v1.4.5 (#256) * chore(deps): update all dependencies (#257) * chore(deps): update dependency pytest to v7.2.0 (#258) * chore(deps): update dependency google-auth to v2.14.0 (#260) * chore(deps): update all dependencies (#261) * chore: Update gapic-generator-python to v1.6.1 (#259) * chore: update to gapic-generator-python 1.5.0 feat: add support for `google.cloud..__version__` PiperOrigin-RevId: 484665853 Source-Link: https://github.com/googleapis/googleapis/commit/8eb249a19db926c2fbc4ecf1dc09c0e521a88b22 Source-Link: https://github.com/googleapis/googleapis-gen/commit/c8aa327b5f478865fc3fd91e3c2768e54e26ad44 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYzhhYTMyN2I1ZjQ3ODg2NWZjM2ZkOTFlM2MyNzY4ZTU0ZTI2YWQ0NCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * update version in gapic_version.py * add .release-please-manifest.json with correct version * add owlbot.py to exclude generated gapic_version.py * set manifest to true in .github/release-please.yml * add release-please-config.json * chore: Update to gapic-generator-python 1.6.0 feat(python): Add typing to proto.Message based class attributes feat(python): Snippetgen handling of repeated enum field PiperOrigin-RevId: 487326846 Source-Link: https://github.com/googleapis/googleapis/commit/da380c77bb87ba0f752baf07605dd1db30e1f7e1 Source-Link: https://github.com/googleapis/googleapis-gen/commit/61ef5762ee6731a0cbbfea22fd0eecee51ab1c8e Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNjFlZjU3NjJlZTY3MzFhMGNiYmZlYTIyZmQwZWVjZWU1MWFiMWM4ZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: new APIs added to reflect updates to the filestore service - Add ENTERPRISE Tier - Add snapshot APIs: RevertInstance, ListSnapshots, CreateSnapshot, DeleteSnapshot, UpdateSnapshot - Add multi-share APIs: ListShares, GetShare, CreateShare, DeleteShare, UpdateShare - Add ConnectMode to NetworkConfig (for Private Service Access support) - New status codes (SUSPENDED/SUSPENDING, REVERTING/RESUMING) - Add SuspensionReason (for KMS related suspension) - Add new fields to Instance information: max_capacity_gb, capacity_step_size_gb, max_share_count, capacity_gb, multi_share_enabled PiperOrigin-RevId: 487492758 Source-Link: https://github.com/googleapis/googleapis/commit/5be5981f50322cf0c7388595e0f31ac5d0693469 Source-Link: https://github.com/googleapis/googleapis-gen/commit/ab0e217f560cc2c1afc11441c2eab6b6950efd2b Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWIwZTIxN2Y1NjBjYzJjMWFmYzExNDQxYzJlYWI2YjY5NTBlZmQyYiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * update path to snippet metadata json * chore: Update gapic-generator-python to v1.6.1 PiperOrigin-RevId: 488036204 Source-Link: https://github.com/googleapis/googleapis/commit/08f275f5c1c0d99056e1cb68376323414459ee19 Source-Link: https://github.com/googleapis/googleapis-gen/commit/555c0945e60649e38739ae64bc45719cdf72178f Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNTU1YzA5NDVlNjA2NDllMzg3MzlhZTY0YmM0NTcxOWNkZjcyMTc4ZiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou * chore(python): drop flake8-import-order in samples noxfile (#266) Source-Link: https://github.com/googleapis/synthtool/commit/6ed3a831cb9ff69ef8a504c353e098ec0192ad93 Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:3abfa0f1886adaf0b83f07cb117b24a639ea1cb9cffe56d43280b977033563eb Co-authored-by: Owl Bot * fix(deps): Require google-api-core >=1.34.0, >=2.11.0 (#268) * fix(deps): Require google-api-core >=1.34.0, >=2.11.0 fix: Drop usage of pkg_resources fix: Fix timeout default values docs(samples): Snippetgen should call await on the operation coroutine before calling result PiperOrigin-RevId: 493260409 Source-Link: https://github.com/googleapis/googleapis/commit/fea43879f83a8d0dacc9353b3f75f8f46d37162f Source-Link: https://github.com/googleapis/googleapis-gen/commit/387b7344c7529ee44be84e613b19a820508c612b Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMzg3YjczNDRjNzUyOWVlNDRiZTg0ZTYxM2IxOWE4MjA1MDhjNjEyYiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * add gapic_version.py Co-authored-by: Owl Bot Co-authored-by: Anthonios Partheniou * feat: add Configurable Analysis, Bulk Upload, Bulk Analyze, Delete Issue Apis (#270) * feat: add Configurable Analysis, Bulk Upload, Bulk Analyze, Delete Issue Apis PiperOrigin-RevId: 495057883 Source-Link: https://github.com/googleapis/googleapis/commit/59a66eb3180ea8474c0a22da3fe964dbe7428c77 Source-Link: https://github.com/googleapis/googleapis-gen/commit/9e7f289c6c6e4fd5f63b6dcfee0d272ab1dca1de Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiOWU3ZjI4OWM2YzZlNGZkNWY2M2I2ZGNmZWUwZDI3MmFiMWRjYTFkZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot * chore(deps): update all dependencies (#267) Co-authored-by: Anthonios Partheniou * chore(main): release 1.5.0 (#265) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * chore(deps): update dependency google-cloud-contact-center-insights to v1.5.0 (#271) * chore(python): add support for python 3.11 (#272) Source-Link: https://github.com/googleapis/synthtool/commit/7197a001ffb6d8ce7b0b9b11c280f0c536c1033a Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:c43f1d918bcf817d337aa29ff833439494a158a0831508fda4ec75dc4c0d0320 Co-authored-by: Owl Bot * chore(deps): update dependency google-auth to v2.16.0 (#273) * feat: Add support for python 3.11 (#274) * feat: Add support for python 3.11 chore: Update gapic-generator-python to v1.8.0 PiperOrigin-RevId: 500768693 Source-Link: https://github.com/googleapis/googleapis/commit/190b612e3d0ff8f025875a669e5d68a1446d43c1 Source-Link: https://github.com/googleapis/googleapis-gen/commit/7bf29a414b9ecac3170f0b65bdc2a95705c0ef1a Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiN2JmMjlhNDE0YjllY2FjMzE3MGYwYjY1YmRjMmE5NTcwNWMwZWYxYSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot * chore(main): release 1.6.0 (#275) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * chore(deps): update dependency google-cloud-pubsub to v2.13.12 (#276) * chore(deps): update dependency google-cloud-contact-center-insights to v1.6.0 (#277) * chore(deps): update dependency pytest to v7.2.1 (#278) * removed 'generated_samples' * trying to add noxfile * noxfile Co-authored-by: Bamboo Le <8941262+TrucHLe@users.noreply.github.com> Co-authored-by: Owl Bot Co-authored-by: WhiteSource Renovate Co-authored-by: WhiteSource Renovate Co-authored-by: gcf-owl-bot[bot] <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: nicain Co-authored-by: Anthonios Partheniou Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> --- .../snippets/create_analysis.py | 44 +++ .../snippets/create_conversation.py | 64 ++++ .../snippets/create_conversation_with_ttl.py | 71 +++++ .../snippets/create_issue_model.py | 52 ++++ .../snippets/create_phrase_matcher_all_of.py | 85 +++++ .../snippets/create_phrase_matcher_any_of.py | 69 +++++ .../snippets/enable_pubsub_notifications.py | 60 ++++ .../snippets/export_to_bigquery.py | 61 ++++ .../snippets/get_operation.py | 47 +++ .../snippets/noxfile_config.py | 292 ++++++++++++++++++ .../snippets/requirements-test.txt | 3 + .../snippets/requirements.txt | 3 + .../snippets/set_project_ttl.py | 65 ++++ .../snippets/test_create_analysis.py | 68 ++++ .../snippets/test_create_conversation.py | 42 +++ .../test_create_conversation_with_ttl.py | 42 +++ .../snippets/test_create_issue_model.py | 70 +++++ .../test_create_phrase_matcher_all_of.py | 48 +++ .../test_create_phrase_matcher_any_of.py | 48 +++ .../test_enable_pubsub_notifications.py | 80 +++++ .../snippets/test_export_to_bigquery.py | 63 ++++ .../snippets/test_get_operation.py | 80 +++++ .../snippets/test_set_project_ttl.py | 49 +++ 23 files changed, 1506 insertions(+) create mode 100644 contact-center-insights/snippets/create_analysis.py create mode 100644 contact-center-insights/snippets/create_conversation.py create mode 100644 contact-center-insights/snippets/create_conversation_with_ttl.py create mode 100644 contact-center-insights/snippets/create_issue_model.py create mode 100644 contact-center-insights/snippets/create_phrase_matcher_all_of.py create mode 100644 contact-center-insights/snippets/create_phrase_matcher_any_of.py create mode 100644 contact-center-insights/snippets/enable_pubsub_notifications.py create mode 100644 contact-center-insights/snippets/export_to_bigquery.py create mode 100644 contact-center-insights/snippets/get_operation.py create mode 100644 contact-center-insights/snippets/noxfile_config.py create mode 100644 contact-center-insights/snippets/requirements-test.txt create mode 100644 contact-center-insights/snippets/requirements.txt create mode 100644 contact-center-insights/snippets/set_project_ttl.py create mode 100644 contact-center-insights/snippets/test_create_analysis.py create mode 100644 contact-center-insights/snippets/test_create_conversation.py create mode 100644 contact-center-insights/snippets/test_create_conversation_with_ttl.py create mode 100644 contact-center-insights/snippets/test_create_issue_model.py create mode 100644 contact-center-insights/snippets/test_create_phrase_matcher_all_of.py create mode 100644 contact-center-insights/snippets/test_create_phrase_matcher_any_of.py create mode 100644 contact-center-insights/snippets/test_enable_pubsub_notifications.py create mode 100644 contact-center-insights/snippets/test_export_to_bigquery.py create mode 100644 contact-center-insights/snippets/test_get_operation.py create mode 100644 contact-center-insights/snippets/test_set_project_ttl.py diff --git a/contact-center-insights/snippets/create_analysis.py b/contact-center-insights/snippets/create_analysis.py new file mode 100644 index 000000000000..2377ec227940 --- /dev/null +++ b/contact-center-insights/snippets/create_analysis.py @@ -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] diff --git a/contact-center-insights/snippets/create_conversation.py b/contact-center-insights/snippets/create_conversation.py new file mode 100644 index 000000000000..2450ad465635 --- /dev/null +++ b/contact-center-insights/snippets/create_conversation.py @@ -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] diff --git a/contact-center-insights/snippets/create_conversation_with_ttl.py b/contact-center-insights/snippets/create_conversation_with_ttl.py new file mode 100644 index 000000000000..fba2dd0e76e6 --- /dev/null +++ b/contact-center-insights/snippets/create_conversation_with_ttl.py @@ -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] diff --git a/contact-center-insights/snippets/create_issue_model.py b/contact-center-insights/snippets/create_issue_model.py new file mode 100644 index 000000000000..9d677a17f56c --- /dev/null +++ b/contact-center-insights/snippets/create_issue_model.py @@ -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] diff --git a/contact-center-insights/snippets/create_phrase_matcher_all_of.py b/contact-center-insights/snippets/create_phrase_matcher_all_of.py new file mode 100644 index 000000000000..0175f1f2b079 --- /dev/null +++ b/contact-center-insights/snippets/create_phrase_matcher_all_of.py @@ -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] diff --git a/contact-center-insights/snippets/create_phrase_matcher_any_of.py b/contact-center-insights/snippets/create_phrase_matcher_any_of.py new file mode 100644 index 000000000000..e55fc4af84cc --- /dev/null +++ b/contact-center-insights/snippets/create_phrase_matcher_any_of.py @@ -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] diff --git a/contact-center-insights/snippets/enable_pubsub_notifications.py b/contact-center-insights/snippets/enable_pubsub_notifications.py new file mode 100644 index 000000000000..c36d562d4e9f --- /dev/null +++ b/contact-center-insights/snippets/enable_pubsub_notifications.py @@ -0,0 +1,60 @@ +# 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_enable_pubsub_notifications] +from google.api_core import protobuf_helpers +from google.cloud import contact_center_insights_v1 + + +def enable_pubsub_notifications( + project_id: str, topic_create_conversation: str, topic_create_analysis: str +) -> None: + """Enables Cloud Pub/Sub notifications for specified events. + + Args: + project_id: + The project identifier. For example, 'my-project'. + topic_create_conversation: + The Cloud Pub/Sub topic to notify of conversation creation events. + Format is 'projects/{project_id}/topics/{topic_id}'. + For example, 'projects/my-project/topics/my-topic'. + topic_create_analysis: + The Cloud Pub/Sub topic to notify of analysis creation events. + Format is 'projects/{project_id}/topics/{topic_id}'. + For example, 'projects/my-project/topics/my-topic'. + + Returns: + None. + """ + # Construct a settings resource. + settings = contact_center_insights_v1.Settings() + settings.name = ( + contact_center_insights_v1.ContactCenterInsightsClient.settings_path( + project_id, "us-central1" + ) + ) + settings.pubsub_notification_settings = { + "create-conversation": topic_create_conversation, + "create-analysis": topic_create_analysis, + } + + update_mask = protobuf_helpers.field_mask(None, type(settings).pb(settings)) + + # Call the Insights client to enable Pub/Sub notifications. + insights_client = contact_center_insights_v1.ContactCenterInsightsClient() + insights_client.update_settings(settings=settings, update_mask=update_mask) + print("Enabled Pub/Sub notifications") + + +# [END contactcenterinsights_enable_pubsub_notifications] diff --git a/contact-center-insights/snippets/export_to_bigquery.py b/contact-center-insights/snippets/export_to_bigquery.py new file mode 100644 index 000000000000..48f8b2973938 --- /dev/null +++ b/contact-center-insights/snippets/export_to_bigquery.py @@ -0,0 +1,61 @@ +# 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_export_to_bigquery] +from google.cloud import contact_center_insights_v1 + + +def export_to_bigquery( + project_id: str, + bigquery_project_id: str, + bigquery_dataset_id: str, + bigquery_table_id: str, +) -> None: + """Exports data to BigQuery. + + Args: + project_id: + The project identifier that owns the data source to be exported. + For example, 'my-project'. + bigquery_project_id: + The project identifier that owns the BigQuery sink to export data to. + For example, 'my-project'. + bigquery_dataset_id: + The BigQuery dataset identifier. For example, 'my-dataset'. + bigquery_table_id: + The BigQuery table identifier. For example, 'my-table'. + + Returns: + None. + """ + # Construct an export request. + request = contact_center_insights_v1.ExportInsightsDataRequest() + request.parent = ( + contact_center_insights_v1.ContactCenterInsightsClient.common_location_path( + project_id, "us-central1" + ) + ) + request.big_query_destination.project_id = bigquery_project_id + request.big_query_destination.dataset = bigquery_dataset_id + request.big_query_destination.table = bigquery_table_id + request.filter = 'agent_id="007"' + + # Call the Insights client to export data to BigQuery. + insights_client = contact_center_insights_v1.ContactCenterInsightsClient() + export_operation = insights_client.export_insights_data(request=request) + export_operation.result(timeout=600000) + print("Exported data to BigQuery") + + +# [END contactcenterinsights_export_to_bigquery] diff --git a/contact-center-insights/snippets/get_operation.py b/contact-center-insights/snippets/get_operation.py new file mode 100644 index 000000000000..f8bd03a91c6c --- /dev/null +++ b/contact-center-insights/snippets/get_operation.py @@ -0,0 +1,47 @@ +# 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. +# +# Get a long-running operation. +# [START contactcenterinsights_get_operation] +from google.cloud import contact_center_insights_v1 +from google.longrunning import operations_pb2 + + +def get_operation(operation_name: str) -> operations_pb2.Operation: + """Gets an operation. + + Args: + operation_name: + The operation name. + Format is 'projects/{project_id}/locations/{location_id}/operations/{operation_id}'. + For example, 'projects/my-project/locations/us-central1/operations/123456789'. + + Returns: + An operation. + """ + # Construct an Insights client that will authenticate via Application Default Credentials. + # See authentication details at https://cloud.google.com/docs/authentication/production. + insights_client = contact_center_insights_v1.ContactCenterInsightsClient() + + # Call the Insights client to get the operation. + operation = insights_client.transport.operations_client.get_operation( + operation_name + ) + if operation.done: + print("Operation is done") + else: + print("Operation is in progress") + + +# [END contactcenterinsights_get_operation] diff --git a/contact-center-insights/snippets/noxfile_config.py b/contact-center-insights/snippets/noxfile_config.py new file mode 100644 index 000000000000..de104dbc64d3 --- /dev/null +++ b/contact-center-insights/snippets/noxfile_config.py @@ -0,0 +1,292 @@ +# Copyright 2019 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. + +from __future__ import print_function + +import glob +import os +from pathlib import Path +import sys +from typing import Callable, Dict, Optional + +import nox + +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING +# DO NOT EDIT THIS FILE EVER! +# WARNING - WARNING - WARNING - WARNING - WARNING +# WARNING - WARNING - WARNING - WARNING - WARNING + +BLACK_VERSION = "black==22.3.0" +ISORT_VERSION = "isort==5.10.1" + +# Copy `noxfile_config.py` to your directory and modify it instead. + +# `TEST_CONFIG` dict is a configuration hook that allows users to +# modify the test configurations. The values here should be in sync +# with `noxfile_config.py`. Users will copy `noxfile_config.py` into +# their directory and modify it. + +TEST_CONFIG = { + # You can opt out from the test for specific Python versions. + "ignored_versions": [], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + "enforce_type_hints": False, + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + # If you need to use a specific version of pip, + # change pip_version_override to the string representation + # of the version number, for example, "20.2.4" + "pip_version_override": None, + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + "envs": {}, +} + + +try: + # Ensure we can import noxfile_config in the project's directory. + sys.path.append(".") + from noxfile_config import TEST_CONFIG_OVERRIDE +except ImportError as e: + print("No user noxfile_config found: detail: {}".format(e)) + TEST_CONFIG_OVERRIDE = {} + +# Update the TEST_CONFIG with the user supplied values. +TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) + + +def get_pytest_env_vars() -> Dict[str, str]: + """Returns a dict for pytest invocation.""" + ret = {} + + # Override the GCLOUD_PROJECT and the alias. + env_key = TEST_CONFIG["gcloud_project_env"] + # This should error out if not set. + ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] + + # Apply user supplied envs. + ret.update(TEST_CONFIG["envs"]) + return ret + + +# DO NOT EDIT - automatically generated. +# All versions used to test samples. +ALL_VERSIONS = ["3.7", "3.8", "3.9", "3.10", "3.11"] + +# Any default versions that should be ignored. +IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] + +TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) + +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( + "True", + "true", +) + +# Error if a python version is missing +nox.options.error_on_missing_interpreters = True + +# +# Style Checks +# + + +# Linting with flake8. +# +# We ignore the following rules: +# E203: whitespace before ‘:’ +# E266: too many leading ‘#’ for block comment +# E501: line too long +# I202: Additional newline in a section of imports +# +# We also need to specify the rules which are ignored by default: +# ['E226', 'W504', 'E126', 'E123', 'W503', 'E24', 'E704', 'E121'] +FLAKE8_COMMON_ARGS = [ + "--show-source", + "--builtin=gettext", + "--max-complexity=20", + "--exclude=.nox,.cache,env,lib,generated_pb2,*_pb2.py,*_pb2_grpc.py", + "--ignore=E121,E123,E126,E203,E226,E24,E266,E501,E704,W503,W504,I202", + "--max-line-length=88", +] + + +@nox.session +def lint(session: nox.sessions.Session) -> None: + if not TEST_CONFIG["enforce_type_hints"]: + session.install("flake8") + else: + session.install("flake8", "flake8-annotations") + + args = FLAKE8_COMMON_ARGS + [ + ".", + ] + session.run("flake8", *args) + + +# +# Black +# + + +@nox.session +def blacken(session: nox.sessions.Session) -> None: + """Run black. Format code to uniform standard.""" + session.install(BLACK_VERSION) + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) + + +# +# format = isort + black +# + + +@nox.session +def format(session: nox.sessions.Session) -> None: + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run("isort", "--fss", *python_files) + session.run("black", *python_files) + + +# +# Sample Tests +# + + +PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] + + +def _session_tests( + session: nox.sessions.Session, post_install: Callable = None +) -> None: + # check for presence of tests + test_list = glob.glob("**/*_test.py", recursive=True) + glob.glob( + "**/test_*.py", recursive=True + ) + test_list.extend(glob.glob("**/tests", recursive=True)) + + if len(test_list) == 0: + print("No tests found, skipping directory.") + return + + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") + """Runs py.test for a particular project.""" + concurrent_args = [] + if os.path.exists("requirements.txt"): + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + with open("requirements.txt") as rfile: + packages = rfile.read() + + if os.path.exists("requirements-test.txt"): + if os.path.exists("constraints-test.txt"): + session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt") + else: + session.install("-r", "requirements-test.txt") + with open("requirements-test.txt") as rtfile: + packages += rtfile.read() + + if INSTALL_LIBRARY_FROM_SOURCE: + session.install("-e", _get_repo_root()) + + if post_install: + post_install(session) + + if "pytest-parallel" in packages: + concurrent_args.extend(["--workers", "auto", "--tests-per-worker", "auto"]) + elif "pytest-xdist" in packages: + concurrent_args.extend(["-n", "auto"]) + + session.run( + "pytest", + *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), + # Pytest will return 5 when no tests are collected. This can happen + # on travis where slow and flaky tests are excluded. + # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html + success_codes=[0, 5], + env=get_pytest_env_vars(), + ) + + +@nox.session(python=ALL_VERSIONS) +def py(session: nox.sessions.Session) -> None: + """Runs py.test for a sample using the specified version of Python.""" + if session.python in TESTED_VERSIONS: + _session_tests(session) + else: + session.skip( + "SKIPPED: {} tests are disabled for this sample.".format(session.python) + ) + + +# +# Readmegen +# + + +def _get_repo_root() -> Optional[str]: + """Returns the root folder of the project.""" + # Get root of this repository. Assume we don't have directories nested deeper than 10 items. + p = Path(os.getcwd()) + for i in range(10): + if p is None: + break + if Path(p / ".git").exists(): + return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) + p = p.parent + raise Exception("Unable to detect repository root.") + + +GENERATED_READMES = sorted([x for x in Path(".").rglob("*.rst.in")]) + + +@nox.session +@nox.parametrize("path", GENERATED_READMES) +def readmegen(session: nox.sessions.Session, path: str) -> None: + """(Re-)generates the readme for a sample.""" + session.install("jinja2", "pyyaml") + dir_ = os.path.dirname(path) + + if os.path.exists(os.path.join(dir_, "requirements.txt")): + session.install("-r", os.path.join(dir_, "requirements.txt")) + + in_file = os.path.join(dir_, "README.rst.in") + session.run( + "python", _get_repo_root() + "/scripts/readme-gen/readme_gen.py", in_file + ) diff --git a/contact-center-insights/snippets/requirements-test.txt b/contact-center-insights/snippets/requirements-test.txt new file mode 100644 index 000000000000..e3d9b4d517e3 --- /dev/null +++ b/contact-center-insights/snippets/requirements-test.txt @@ -0,0 +1,3 @@ +google-auth==2.16.0 +google-cloud-pubsub==2.13.12 +pytest==7.2.1 diff --git a/contact-center-insights/snippets/requirements.txt b/contact-center-insights/snippets/requirements.txt new file mode 100644 index 000000000000..c1672ab994cc --- /dev/null +++ b/contact-center-insights/snippets/requirements.txt @@ -0,0 +1,3 @@ +google-api-core==2.11.0 +google-cloud-bigquery==3.4.1 +google-cloud-contact-center-insights==1.6.0 diff --git a/contact-center-insights/snippets/set_project_ttl.py b/contact-center-insights/snippets/set_project_ttl.py new file mode 100644 index 000000000000..a56476a6ef29 --- /dev/null +++ b/contact-center-insights/snippets/set_project_ttl.py @@ -0,0 +1,65 @@ +# 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. +# +# Set a project-level TTL for all incoming conversations. +# [START contactcenterinsights_set_project_ttl] +from google.api_core import protobuf_helpers +from google.cloud import contact_center_insights_v1 +from google.protobuf import duration_pb2 + + +def set_project_ttl(project_id: str) -> None: + """Sets a project-level TTL for all incoming conversations. + + Args: + project_id: + The project identifier. For example, 'my-project'. + + Returns: + None. + """ + # Construct a settings resource. + settings = contact_center_insights_v1.Settings() + settings.name = ( + contact_center_insights_v1.ContactCenterInsightsClient.settings_path( + project_id, "us-central1" + ) + ) + + conversation_ttl = duration_pb2.Duration() + conversation_ttl.seconds = 86400 + settings.conversation_ttl = conversation_ttl + + # Construct an update mask to only update the fields that are set on the settings resource. + update_mask = protobuf_helpers.field_mask(None, type(settings).pb(settings)) + + # Construct an Insights client that will authenticate via Application Default Credentials. + # See authentication details at https://cloud.google.com/docs/authentication/production. + insights_client = contact_center_insights_v1.ContactCenterInsightsClient() + + # Call the Insights client to set a project-level TTL. + insights_client.update_settings(settings=settings, update_mask=update_mask) + + # Call the Insights client to get the project-level TTL to confirm that it was set. + new_conversation_ttl = insights_client.get_settings( + name=settings.name + ).conversation_ttl + print( + "Set TTL for all incoming conversations to {} day".format( + new_conversation_ttl.days + ) + ) + + +# [END contactcenterinsights_set_project_ttl] diff --git a/contact-center-insights/snippets/test_create_analysis.py b/contact-center-insights/snippets/test_create_analysis.py new file mode 100644 index 000000000000..0d660123dd2c --- /dev/null +++ b/contact-center-insights/snippets/test_create_analysis.py @@ -0,0 +1,68 @@ +# 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. +# +import google.auth +from google.cloud import contact_center_insights_v1 +import pytest + +import create_analysis + +TRANSCRIPT_URI = "gs://cloud-samples-data/ccai/chat_sample.json" +AUDIO_URI = "gs://cloud-samples-data/ccai/voice_6912.txt" + + +@pytest.fixture +def project_id(): + _, project_id = google.auth.default() + return project_id + + +@pytest.fixture +def conversation_resource(project_id): + # Create a conversation. + insights_client = contact_center_insights_v1.ContactCenterInsightsClient() + + parent = ( + contact_center_insights_v1.ContactCenterInsightsClient.common_location_path( + project_id, "us-central1" + ) + ) + + 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 + + conversation = insights_client.create_conversation( + parent=parent, conversation=conversation + ) + yield conversation + + # Delete the conversation. + delete_request = contact_center_insights_v1.DeleteConversationRequest() + delete_request.name = conversation.name + delete_request.force = True + insights_client.delete_conversation(request=delete_request) + + +@pytest.fixture +def analysis_resource(conversation_resource): + conversation_name = conversation_resource.name + yield create_analysis.create_analysis(conversation_name) + + +def test_create_analysis(capsys, analysis_resource): + analysis = analysis_resource + out, err = capsys.readouterr() + assert "Created {}".format(analysis.name) in out diff --git a/contact-center-insights/snippets/test_create_conversation.py b/contact-center-insights/snippets/test_create_conversation.py new file mode 100644 index 000000000000..a3ca4c2c51b4 --- /dev/null +++ b/contact-center-insights/snippets/test_create_conversation.py @@ -0,0 +1,42 @@ +# 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. +# +import google.auth +from google.cloud import contact_center_insights_v1 +import pytest + +import create_conversation + + +@pytest.fixture +def project_id(): + _, project_id = google.auth.default() + return project_id + + +@pytest.fixture +def conversation_resource(project_id): + # Create a conversation + conversation = create_conversation.create_conversation(project_id) + yield conversation + + # Delete the conversation. + insights_client = contact_center_insights_v1.ContactCenterInsightsClient() + insights_client.delete_conversation(name=conversation.name) + + +def test_create_conversation(capsys, conversation_resource): + conversation = conversation_resource + out, err = capsys.readouterr() + assert "Created {}".format(conversation.name) in out diff --git a/contact-center-insights/snippets/test_create_conversation_with_ttl.py b/contact-center-insights/snippets/test_create_conversation_with_ttl.py new file mode 100644 index 000000000000..53ea32135728 --- /dev/null +++ b/contact-center-insights/snippets/test_create_conversation_with_ttl.py @@ -0,0 +1,42 @@ +# 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. +# +import google.auth +from google.cloud import contact_center_insights_v1 +import pytest + +import create_conversation_with_ttl + + +@pytest.fixture +def project_id(): + _, project_id = google.auth.default() + return project_id + + +@pytest.fixture +def conversation_resource(project_id): + # Create a conversation + conversation = create_conversation_with_ttl.create_conversation_with_ttl(project_id) + yield conversation + + # Delete the conversation. + insights_client = contact_center_insights_v1.ContactCenterInsightsClient() + insights_client.delete_conversation(name=conversation.name) + + +def test_create_conversation_with_ttl(capsys, conversation_resource): + conversation = conversation_resource + out, err = capsys.readouterr() + assert "Created {}".format(conversation.name) in out diff --git a/contact-center-insights/snippets/test_create_issue_model.py b/contact-center-insights/snippets/test_create_issue_model.py new file mode 100644 index 000000000000..2b5f128d635e --- /dev/null +++ b/contact-center-insights/snippets/test_create_issue_model.py @@ -0,0 +1,70 @@ +# 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. +# +import google.auth +from google.cloud import contact_center_insights_v1 +import pytest + +import create_issue_model + +MIN_CONVERSATION_COUNT = 10000 + + +@pytest.fixture +def project_id(): + _, project_id = google.auth.default() + return project_id + + +@pytest.fixture +def insights_client(): + return contact_center_insights_v1.ContactCenterInsightsClient() + + +@pytest.fixture +def count_conversations(project_id, insights_client): + # Check if the project has the minimum number of conversations required to create an issue model. + # See https://cloud.google.com/contact-center/insights/docs/topic-model. + list_request = contact_center_insights_v1.ListConversationsRequest() + list_request.page_size = 1000 + list_request.parent = ( + contact_center_insights_v1.ContactCenterInsightsClient.common_location_path( + project_id, "us-central1" + ) + ) + conversations = insights_client.list_conversations(request=list_request) + conversation_count = len(list(conversations)) + + yield conversation_count + + +@pytest.fixture +def issue_model_resource(project_id, insights_client, count_conversations): + conversation_count = count_conversations + if conversation_count >= MIN_CONVERSATION_COUNT: + # Create an issue model. + issue_model = create_issue_model.create_issue_model(project_id) + yield issue_model + + # Delete the issue model. + insights_client.delete_issue_model(name=issue_model.name) + else: + yield None + + +def test_create_issue_model(capsys, issue_model_resource): + issue_model = issue_model_resource + if issue_model: + out, err = capsys.readouterr() + assert "Created {}".format(issue_model.name) in out diff --git a/contact-center-insights/snippets/test_create_phrase_matcher_all_of.py b/contact-center-insights/snippets/test_create_phrase_matcher_all_of.py new file mode 100644 index 000000000000..6c9b217e67a1 --- /dev/null +++ b/contact-center-insights/snippets/test_create_phrase_matcher_all_of.py @@ -0,0 +1,48 @@ +# 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. +# +import google.auth +from google.cloud import contact_center_insights_v1 +import pytest + +import create_phrase_matcher_all_of + + +@pytest.fixture +def project_id(): + _, project_id = google.auth.default() + return project_id + + +@pytest.fixture +def insights_client(): + return contact_center_insights_v1.ContactCenterInsightsClient() + + +@pytest.fixture +def phrase_matcher_all_of(project_id, insights_client): + # Create a phrase matcher. + phrase_matcher = create_phrase_matcher_all_of.create_phrase_matcher_all_of( + project_id + ) + yield phrase_matcher + + # Delete the phrase matcher. + insights_client.delete_phrase_matcher(name=phrase_matcher.name) + + +def test_create_phrase_matcher_all_of(capsys, phrase_matcher_all_of): + phrase_matcher = phrase_matcher_all_of + out, err = capsys.readouterr() + assert f"Created {phrase_matcher.name}" in out diff --git a/contact-center-insights/snippets/test_create_phrase_matcher_any_of.py b/contact-center-insights/snippets/test_create_phrase_matcher_any_of.py new file mode 100644 index 000000000000..62efcccfd7d4 --- /dev/null +++ b/contact-center-insights/snippets/test_create_phrase_matcher_any_of.py @@ -0,0 +1,48 @@ +# 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. +# +import google.auth +from google.cloud import contact_center_insights_v1 +import pytest + +import create_phrase_matcher_any_of + + +@pytest.fixture +def project_id(): + _, project_id = google.auth.default() + return project_id + + +@pytest.fixture +def insights_client(): + return contact_center_insights_v1.ContactCenterInsightsClient() + + +@pytest.fixture +def phrase_matcher_any_of(project_id, insights_client): + # Create a phrase matcher. + phrase_matcher = create_phrase_matcher_any_of.create_phrase_matcher_any_of( + project_id + ) + yield phrase_matcher + + # Delete the phrase matcher. + insights_client.delete_phrase_matcher(name=phrase_matcher.name) + + +def test_create_phrase_matcher_any_of(capsys, phrase_matcher_any_of): + phrase_matcher = phrase_matcher_any_of + out, err = capsys.readouterr() + assert f"Created {phrase_matcher.name}" in out diff --git a/contact-center-insights/snippets/test_enable_pubsub_notifications.py b/contact-center-insights/snippets/test_enable_pubsub_notifications.py new file mode 100644 index 000000000000..d3ae6959dbe6 --- /dev/null +++ b/contact-center-insights/snippets/test_enable_pubsub_notifications.py @@ -0,0 +1,80 @@ +# 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. +# +import uuid + +import google.auth +from google.cloud import contact_center_insights_v1, pubsub_v1 +from google.protobuf import field_mask_pb2 +import pytest + +import enable_pubsub_notifications + +UUID = uuid.uuid4().hex[:8] +CONVERSATION_TOPIC_ID = "create-conversation-" + UUID +ANALYSIS_TOPIC_ID = "create-analysis-" + UUID + + +@pytest.fixture +def project_id(): + _, project_id = google.auth.default() + return project_id + + +@pytest.fixture +def pubsub_topics(project_id): + # Create Pub/Sub topics. + pubsub_client = pubsub_v1.PublisherClient() + conversation_topic_path = pubsub_client.topic_path( + project_id, CONVERSATION_TOPIC_ID + ) + conversation_topic = pubsub_client.create_topic( + request={"name": conversation_topic_path} + ) + analysis_topic_path = pubsub_client.topic_path(project_id, ANALYSIS_TOPIC_ID) + analysis_topic = pubsub_client.create_topic(request={"name": analysis_topic_path}) + yield conversation_topic.name, analysis_topic.name + + # Delete Pub/Sub topics. + pubsub_client.delete_topic(request={"topic": conversation_topic.name}) + pubsub_client.delete_topic(request={"topic": analysis_topic.name}) + + +@pytest.fixture +def disable_pubsub_notifications(project_id): + yield + settings = contact_center_insights_v1.Settings() + settings.name = ( + contact_center_insights_v1.ContactCenterInsightsClient.settings_path( + project_id, "us-central1" + ) + ) + settings.pubsub_notification_settings = {} + update_mask = field_mask_pb2.FieldMask() + update_mask.paths.append("pubsub_notification_settings") + + insights_client = contact_center_insights_v1.ContactCenterInsightsClient() + insights_client.update_settings(settings=settings, update_mask=update_mask) + + +def test_enable_pubsub_notifications( + capsys, project_id, pubsub_topics, disable_pubsub_notifications +): + conversation_topic, analysis_topic = pubsub_topics + + enable_pubsub_notifications.enable_pubsub_notifications( + project_id, conversation_topic, analysis_topic + ) + out, err = capsys.readouterr() + assert "Enabled Pub/Sub notifications" in out diff --git a/contact-center-insights/snippets/test_export_to_bigquery.py b/contact-center-insights/snippets/test_export_to_bigquery.py new file mode 100644 index 000000000000..c9ada15601ed --- /dev/null +++ b/contact-center-insights/snippets/test_export_to_bigquery.py @@ -0,0 +1,63 @@ +# 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. +# +import uuid + +import google.auth +from google.cloud import bigquery +import pytest + +import export_to_bigquery + +GCLOUD_TESTS_PREFIX = "python_samples_tests" + + +@pytest.fixture +def project_id(): + _, project_id = google.auth.default() + return project_id + + +@pytest.fixture +def unique_id(): + uuid_hex = uuid.uuid4().hex[:8] + return f"{GCLOUD_TESTS_PREFIX}_{uuid_hex}" + + +@pytest.fixture +def bigquery_resources(project_id, unique_id): + # Create a BigQuery dataset. + bigquery_client = bigquery.Client() + dataset_id = unique_id + table_id = unique_id + + dataset = bigquery.Dataset(f"{project_id}.{dataset_id}") + dataset.location = "US" + bigquery_client.create_dataset(dataset, timeout=30) + + # Create a BigQuery table under the created dataset. + table = bigquery.Table(f"{project_id}.{dataset_id}.{table_id}") + bigquery_client.create_table(table) + + yield dataset_id, table_id + + # Delete the BigQuery dataset and table. + bigquery_client.delete_dataset(dataset_id, delete_contents=True) + + +def test_export_data_to_bigquery(capsys, project_id, bigquery_resources): + dataset_id, table_id = bigquery_resources + export_to_bigquery.export_to_bigquery(project_id, project_id, dataset_id, table_id) + out, err = capsys.readouterr() + assert "Exported data to BigQuery" in out diff --git a/contact-center-insights/snippets/test_get_operation.py b/contact-center-insights/snippets/test_get_operation.py new file mode 100644 index 000000000000..087d6fa0ea2b --- /dev/null +++ b/contact-center-insights/snippets/test_get_operation.py @@ -0,0 +1,80 @@ +# 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. +# +import google.auth +from google.cloud import contact_center_insights_v1 +import pytest + +import get_operation + +TRANSCRIPT_URI = "gs://cloud-samples-data/ccai/chat_sample.json" +AUDIO_URI = "gs://cloud-samples-data/ccai/voice_6912.txt" + + +@pytest.fixture +def project_id(): + _, project_id = google.auth.default() + return project_id + + +@pytest.fixture +def insights_client(): + return contact_center_insights_v1.ContactCenterInsightsClient() + + +@pytest.fixture +def conversation_resource(project_id, insights_client): + # Create a conversation. + parent = ( + contact_center_insights_v1.ContactCenterInsightsClient.common_location_path( + project_id, "us-central1" + ) + ) + + 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 + + conversation = insights_client.create_conversation( + parent=parent, conversation=conversation + ) + yield conversation + + # Delete the conversation. + delete_request = contact_center_insights_v1.DeleteConversationRequest() + delete_request.name = conversation.name + delete_request.force = True + insights_client.delete_conversation(request=delete_request) + + +@pytest.fixture +def analysis_operation(conversation_resource, insights_client): + # Create an analysis. + conversation_name = conversation_resource.name + analysis = contact_center_insights_v1.Analysis() + analysis_operation = insights_client.create_analysis( + parent=conversation_name, analysis=analysis + ) + + # Wait until the analysis operation is done and return the operation. + analysis_operation.result(timeout=600) + yield analysis_operation + + +def test_get_operation(capsys, analysis_operation): + operation_name = analysis_operation.operation.name + get_operation.get_operation(operation_name) + out, err = capsys.readouterr() + assert "Operation is done" in out diff --git a/contact-center-insights/snippets/test_set_project_ttl.py b/contact-center-insights/snippets/test_set_project_ttl.py new file mode 100644 index 000000000000..6ddc3a024725 --- /dev/null +++ b/contact-center-insights/snippets/test_set_project_ttl.py @@ -0,0 +1,49 @@ +# 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. +# +import google.auth +from google.cloud import contact_center_insights_v1 +from google.protobuf import field_mask_pb2 +import pytest + +import set_project_ttl + + +@pytest.fixture +def project_id(): + _, project_id = google.auth.default() + return project_id + + +@pytest.fixture +def clear_project_ttl(project_id): + yield + settings = contact_center_insights_v1.Settings() + settings.name = ( + contact_center_insights_v1.ContactCenterInsightsClient.settings_path( + project_id, "us-central1" + ) + ) + settings.conversation_ttl = None + update_mask = field_mask_pb2.FieldMask() + update_mask.paths.append("conversation_ttl") + + insights_client = contact_center_insights_v1.ContactCenterInsightsClient() + insights_client.update_settings(settings=settings, update_mask=update_mask) + + +def test_set_project_ttl(capsys, project_id, clear_project_ttl): + set_project_ttl.set_project_ttl(project_id) + out, err = capsys.readouterr() + assert "Set TTL for all incoming conversations to 1 day" in out