Skip to content

chore(dialogflow): migrate code from googleapis/python-dialogflow #9011

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

Closed
wants to merge 96 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
1d0b983
Moving the Dialogflow samples to the python-docs-sampl… [(#1629)](htt…
nnegrey Aug 29, 2018
e5e8da1
Fix typos in dialogflow cloud client comments [(#1889)](https://githu…
leahecole Dec 3, 2018
bfff51b
Auto-update dependencies. [(#1980)](https://github.com/GoogleCloudPla…
dpebot Feb 6, 2019
30927b2
TTS / Sentiment GA [(#2157)](https://github.com/GoogleCloudPlatform/p…
nnegrey May 15, 2019
778c5d7
dialogflow: use unique names for all resources for tests to avoid col…
nnegrey Jan 17, 2020
ff2f90f
dialogflow: split up entity and entity type tests [(#2735)](https://g…
nnegrey Jan 27, 2020
a41b04f
dialogflow: make flaky test more generic [(#2936)](https://github.com…
nnegrey Feb 26, 2020
d169e21
chore(deps): update dependency dialogflow to v0.8.0 [(#3147)](https:/…
renovate-bot Mar 27, 2020
f54ea97
Simplify noxfile setup. [(#2806)](https://github.com/GoogleCloudPlatf…
kurtisvg Apr 2, 2020
0885178
dialogflow: remove unused samples + tests [(#3249)](https://github.c…
Strykrol Apr 23, 2020
3a0f680
[dialogflow] fix: marking a test with flaky [(#3671)](https://github.…
May 5, 2020
60b0f8c
chore: some lint fixes [(#3743)](https://github.com/GoogleCloudPlatfo…
May 12, 2020
295d43b
chore(deps): update dependency dialogflow to v1 [(#3798)](https://git…
renovate-bot May 18, 2020
bc248e1
Replace GCLOUD_PROJECT with GOOGLE_CLOUD_PROJECT. [(#4022)](https://g…
kurtisvg Jun 9, 2020
2d71b0f
chore(deps): update dependency pytest to v5.4.3 [(#4279)](https://git…
renovate-bot Jul 12, 2020
0fb3eaa
Update dependency flaky to v3.7.0 [(#4300)](https://github.com/Google…
renovate-bot Jul 16, 2020
cd10498
Update dependency pytest to v6 [(#4390)](https://github.com/GoogleClo…
renovate-bot Aug 1, 2020
04ad2c0
chore(deps): update dependency dialogflow to v1.1.0 [(#4556)](https:/…
renovate-bot Aug 27, 2020
3aa1f1c
chore(deps): update dependency pytest to v6.1.1 [(#4761)](https://git…
renovate-bot Oct 14, 2020
30ae7c5
chore(deps): update dependency pytest to v6.1.2 [(#4921)](https://git…
renovate-bot Oct 29, 2020
c2b0c5e
chore: update templates
busunkim96 Nov 30, 2020
b5c4eaa
feat!: use microgenerator (#239)
busunkim96 Dec 14, 2020
64e2f27
chore(samples): update dialogflow version (#244)
busunkim96 Jan 21, 2021
1342e16
feat: add sample code for using regional Dialogflow endpoint (#254)
martini9393 Feb 13, 2021
34627fa
docs(samples): add Agent Assist code samples (#267)
rogers140 Mar 25, 2021
ee3f65f
chore(deps): update dependency google-cloud-dialogflow to v2.1.2 (#285)
renovate-bot May 7, 2021
0656fb0
chore(deps): update dependency pytest to v6.2.4 (#287)
renovate-bot May 11, 2021
216eabd
chore(deps): update dependency google-cloud-dialogflow to v2.2.0 (#296)
renovate-bot May 18, 2021
5e71298
chore(deps): update dependency google-cloud-dialogflow to v2.3.0 (#300)
renovate-bot May 25, 2021
63a904a
chore(deps): update dependency google-cloud-dialogflow to v2.4.0 (#307)
renovate-bot Jun 2, 2021
027f99a
chore(deps): update dependency google-cloud-dialogflow to v2.5.0 (#326)
renovate-bot Jul 3, 2021
a6fbf11
chore(deps): update dependency google-cloud-dialogflow to v2.6.0 (#329)
renovate-bot Jul 22, 2021
88f00ec
chore(deps): update dependency google-cloud-dialogflow to v2.7.0 (#343)
renovate-bot Jul 25, 2021
5ec3f4a
docs: fix typos (#347)
slowy07 Jul 25, 2021
599b972
chore(deps): update dependency google-cloud-dialogflow to v2.7.1 (#353)
renovate-bot Jul 26, 2021
e6238f1
docs(samples): add update intent code sample (#357)
galz10 Aug 17, 2021
9384a75
chore: migrate to main branch (#372)
dandhlee Aug 25, 2021
955950c
test(samples): replace the deleted gcs file with public file (#388)
rogers140 Sep 2, 2021
192fc77
docs(samples): add region tags to update intent sample (#382)
galz10 Sep 3, 2021
075df19
test(samples): replace the deleted gcs file with gcs file located in …
galz10 Sep 7, 2021
72aab2a
chore(deps): update dependency pytest to v6.2.5 (#379)
renovate-bot Sep 8, 2021
524c681
docs(samples): add set agent code sample (#370)
galz10 Sep 8, 2021
af7153f
chore(deps): update dependency google-cloud-dialogflow to v2.8.0 (#394)
renovate-bot Sep 16, 2021
676b5f5
chore: blacken samples noxfile template (#395)
gcf-owl-bot[bot] Sep 17, 2021
5e17d40
fix: added increased timout (#400)
b-loved-dreamer Sep 27, 2021
95a59cc
fix: increased timeout to 600 (#402)
b-loved-dreamer Sep 29, 2021
31372d0
chore(deps): update dependency google-cloud-dialogflow to v2.8.1 (#403)
renovate-bot Sep 30, 2021
4edc90e
chore: fail samples nox session if python version is missing (#408)
gcf-owl-bot[bot] Sep 30, 2021
29710c3
docs(samples): added webhook code snippet (#401)
galz10 Sep 30, 2021
d41c66c
chore(deps): update dependency google-cloud-dialogflow to v2.9.0 (#409)
renovate-bot Oct 1, 2021
89a6f2a
docs(samples): adds training phrases sample (#404)
b-loved-dreamer Oct 4, 2021
527cdba
chore(python): Add kokoro configs for python 3.10 samples testing (#418)
gcf-owl-bot[bot] Oct 8, 2021
62192f2
chore(deps): update all dependencies (#410)
renovate-bot Oct 9, 2021
1bcc956
docs(samples): Added comments (#425)
galz10 Oct 18, 2021
bcca42f
chore(deps): update dependency google-cloud-dialogflow to v2.10.0 (#440)
renovate-bot Nov 16, 2021
20c390a
ci: opt in to use multiple projects (#438)
parthea Nov 16, 2021
944d209
chore(samples): Add check for tests in directory (#455)
gcf-owl-bot[bot] Jan 11, 2022
c0ec252
chore(deps): update dependency google-cloud-dialogflow to v2.11.0 (#459)
renovate-bot Jan 14, 2022
b72c5ec
chore(python): Noxfile recognizes that tests can live in a folder (#462)
gcf-owl-bot[bot] Jan 19, 2022
273deb5
chore: Adding support for pytest-xdist and pytest-parallel (#480)
gcf-owl-bot[bot] Mar 4, 2022
0e424e0
chore(deps): update all dependencies (#483)
renovate-bot Mar 7, 2022
a06222f
chore(deps): update dependency google-cloud-dialogflow to v2.13.0 (#484)
renovate-bot Mar 8, 2022
96a95b9
chore(deps): update dependency pytest to v7.1.0 (#486)
renovate-bot Mar 13, 2022
adef109
chore(deps): update dependency pytest to v7.1.1 (#487)
renovate-bot Mar 19, 2022
d4f08a7
chore(python): use black==22.3.0 (#493)
gcf-owl-bot[bot] Mar 29, 2022
b065165
chore(deps): update dependency flask to v2.1.0 (#492)
renovate-bot Mar 30, 2022
dbd7af1
chore(deps): update dependency flask to v2.1.1 (#495)
renovate-bot Apr 1, 2022
2cdf0ec
chore(python): add nox session to sort python imports (#510)
gcf-owl-bot[bot] Apr 21, 2022
8645abc
chore(deps): update dependency pytest to v7.1.2 (#513)
renovate-bot Apr 25, 2022
0cfc1a5
chore(deps): update dependency flask to v2.1.2 (#515)
renovate-bot Apr 28, 2022
dcc5baa
chore(deps): update dependency google-cloud-dialogflow to v2.14.0 (#521)
renovate-bot May 19, 2022
91f52e5
fix: require python 3.7+ (#535)
gcf-owl-bot[bot] Jul 6, 2022
7a24221
docs: Update region_tag: dialogflow_detect_intent_text --> dialogflow…
nicain Jul 6, 2022
cf759e2
chore(deps): update all dependencies (#528)
renovate-bot Jul 16, 2022
75f45fa
chore(deps): update all dependencies (#546)
renovate-bot Aug 2, 2022
468db0e
chore(deps): update all dependencies (#547)
renovate-bot Aug 2, 2022
d6a03d7
samples: update logs for knowledge base management sample (#550)
deliaqi Aug 4, 2022
3cf9126
chore(deps): update all dependencies (#549)
renovate-bot Aug 5, 2022
b603300
chore(deps): update all dependencies (#551)
renovate-bot Aug 9, 2022
cb56a53
chore(deps): update all dependencies to v2.15.1 (#553)
renovate-bot Aug 10, 2022
37ac4c2
chore(deps): update dependency pytest to v7.1.3 (#566)
renovate-bot Sep 6, 2022
d2f89a3
chore(deps): update dependency google-cloud-dialogflow to v2.15.2 (#570)
renovate-bot Sep 12, 2022
431e2b0
chore: detect samples tests in nested directories (#572)
gcf-owl-bot[bot] Sep 13, 2022
38e33fb
chore(deps): update dependency google-cloud-dialogflow to v2.16.0 (#583)
renovate-bot Oct 4, 2022
24fac03
docs(samples): add sample code for StreamingAnalyzeContent for live t…
rogers140 Oct 5, 2022
93e9273
chore(deps): update dependency google-cloud-dialogflow to v2.16.1 (#586)
renovate-bot Oct 18, 2022
f167490
chore(deps): update dependency pytest to v7.2.0 (#589)
renovate-bot Oct 26, 2022
5ef9172
chore(python): drop flake8-import-order in samples noxfile (#597)
gcf-owl-bot[bot] Nov 26, 2022
1e967a1
fix(deps): Require google-api-core >=1.34.0, >=2.11.0 (#591)
gcf-owl-bot[bot] Dec 14, 2022
01b8e42
chore(deps): update dependency google-cloud-dialogflow to v2.17.0 (#602)
renovate-bot Dec 15, 2022
f68d31c
chore(python): add support for python 3.11 (#603)
gcf-owl-bot[bot] Jan 9, 2023
3463838
chore(deps): update dependency google-cloud-dialogflow to v2.18.0 (#606)
renovate-bot Jan 10, 2023
863a34f
chore(deps): update dependency pytest to v7.2.1 (#609)
renovate-bot Jan 14, 2023
6d4f080
chore(deps): update dependency google-cloud-dialogflow to v2.19.0 (#610)
renovate-bot Jan 18, 2023
b99ceae
Merge remote-tracking branch 'migration/main' into python-dialogflow-…
telpirion Jan 18, 2023
2f02ed7
Merge branch 'main' into python-dialogflow-migration
kweinmeister Jan 18, 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
465 changes: 465 additions & 0 deletions dialogflow/README.rst

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions dialogflow/README.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This file is used to generate README.rst

product:
name: Dialogflow Enterprise Edition API
short_name: Dialogflow API
url: https://cloud.google.com/dialogflow-enterprise/docs/
description: >
The `Dialogflow Enterprise Edition API`_ enables you to create conversational experiences across devices and platforms.

setup:
- auth
- install_deps

samples:
- name: Detect Intent Text
file: detect_intent_texts.py
show_help: True
- name: Detect Intent Audio
file: detect_intent_audio.py
show_help: True
- name: Detect Intent Stream
file: detect_intent_stream.py
show_help: True
- name: Detect Intent Knowledge Base
file: detect_intent_knowledge.py
show_help: True
- name: Detect Intent with Sentiment Analysis
file: detect_intent_with_sentiment_analysis.py
show_help: True
- name: Detect Intent with Text to Speech Response
file: detect_intent_with_texttospeech_response.py
show_help: True
- name: Intent Management
file: intent_management.py
show_help: True
- name: Knowledge Base Management
file: knowledge_base_management.py
show_help: True
- name: Document Management
file: document_management.py
show_help: True

cloud_client_library: true
86 changes: 86 additions & 0 deletions dialogflow/analyze_content_stream_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright 2022 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 os
import uuid

import pytest

import conversation_management
import conversation_profile_management
import participant_management

PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
AUDIO_FILE_PATH = "{0}/resources/book_a_room.wav".format(
os.path.realpath(os.path.dirname(__file__)),
)


@pytest.fixture
def conversation_profile_display_name():
return f"sample_conversation_profile_{uuid.uuid4()}"


@pytest.fixture
def conversation_profile_id(conversation_profile_display_name):
# Create conversation profile.
response = conversation_profile_management.create_conversation_profile_article_faq(
project_id=PROJECT_ID, display_name=conversation_profile_display_name
)
conversation_profile_id = response.name.split("conversationProfiles/")[1].rstrip()

yield conversation_profile_id

# Delete the conversation profile.
conversation_profile_management.delete_conversation_profile(
PROJECT_ID, conversation_profile_id
)


@pytest.fixture
def conversation_id(conversation_profile_id):
# Create conversation.
response = conversation_management.create_conversation(
project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id
)
conversation_id = response.name.split("conversations/")[1].rstrip()

yield conversation_id

# Complete the conversation.
conversation_management.complete_conversation(
project_id=PROJECT_ID, conversation_id=conversation_id
)


@pytest.fixture
def participant_id(conversation_id):
response = participant_management.create_participant(
project_id=PROJECT_ID, conversation_id=conversation_id, role="END_USER"
)
participant_id = response.name.split("participants/")[1].rstrip()
yield participant_id


# Test live transcription with streaming_analyze_content.
def test_analyze_content_audio_stream(capsys, conversation_id, participant_id):
# Call StreamingAnalyzeContent to transcribe the audio.
participant_management.analyze_content_audio_stream(
project_id=PROJECT_ID,
conversation_id=conversation_id,
participant_id=participant_id,
audio_file_path=AUDIO_FILE_PATH,
)
out, _ = capsys.readouterr()
assert "book a room" in out
47 changes: 47 additions & 0 deletions dialogflow/answer_record_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python

# 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.
"""Dialogflow API Python sample showing how to manage AnswerRecord.
"""

from google.cloud import dialogflow_v2beta1 as dialogflow


# [START dialogflow_update_answer_record]
def update_answer_record(project_id, answer_record_id, is_clicked):
"""Update the answer record.

Args:
project_id: The GCP project linked with the conversation profile.
answer_record_id: The answer record id returned along with the
suggestion.
is_clicked: whether the answer record is clicked."""

client = dialogflow.AnswerRecordsClient()
answer_record_path = client.answer_record_path(project_id, answer_record_id)

response = client.update_answer_record(
answer_record={
"name": answer_record_path,
"answer_feedback": {"clicked": is_clicked},
},
update_mask={"paths": ["answer_feedback"]},
)
print("AnswerRecord Name: {}".format(response.name))
print("Clicked: {}".format(response.answer_feedback.clicked))
return response


# [END dialogflow_update_answer_record]
104 changes: 104 additions & 0 deletions dialogflow/answer_record_management_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# 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 os

import answer_record_management
import conversation_management
import conversation_profile_management
import participant_management

PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
SMART_REPLY_MODEL = os.getenv("SMART_REPLY_MODEL")
SMART_REPLY_ALLOWLIST = os.getenv("SMART_REPLY_ALLOWLIST")
CONVERSATION_PROFILE_DISPLAY_NAME = "sample code profile for smart reply"


def test_smart_reply(capsys):
"""Test smart reply feature."""

# Create conversation profile.
conversation_profile_management.create_conversation_profile_smart_reply(
project_id=PROJECT_ID,
display_name=CONVERSATION_PROFILE_DISPLAY_NAME,
smart_reply_allowlist_name=SMART_REPLY_ALLOWLIST,
smart_reply_model_name=SMART_REPLY_MODEL,
)

out, _ = capsys.readouterr()
assert "Display Name: {}".format(CONVERSATION_PROFILE_DISPLAY_NAME) in out
conversation_profile_id = out.split("conversationProfiles/")[1].rstrip()

# Create conversation.
conversation_management.create_conversation(
project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id
)

out, _ = capsys.readouterr()
conversation_id = out.split("conversations/")[1].rstrip()

# Create end user participant.
participant_management.create_participant(
project_id=PROJECT_ID, conversation_id=conversation_id, role="END_USER"
)
out, _ = capsys.readouterr()
end_user_id = out.split("participants/")[1].rstrip()

# Create human agent participant.
participant_management.create_participant(
project_id=PROJECT_ID, conversation_id=conversation_id, role="HUMAN_AGENT"
)
out, _ = capsys.readouterr()
human_agent_id = out.split("participants/")[1].rstrip()

# AnalyzeContent
participant_management.analyze_content_text(
project_id=PROJECT_ID,
conversation_id=conversation_id,
participant_id=human_agent_id,
text="Hi, how are you?",
)
out, _ = capsys.readouterr()
assert "What would you like to know?" in out

response = participant_management.analyze_content_text(
project_id=PROJECT_ID,
conversation_id=conversation_id,
participant_id=end_user_id,
text="I am doing well, just want to check",
)
out, _ = capsys.readouterr()
assert "Sounds good." in out
# Update AnswerRecord.
answer_record_id = (
response.human_agent_suggestion_results[0]
.suggest_smart_replies_response.smart_reply_answers[0]
.answer_record.split("answerRecords/")[1]
.rstrip()
)
answer_record_management.update_answer_record(
project_id=PROJECT_ID, answer_record_id=answer_record_id, is_clicked=True
)
out, _ = capsys.readouterr()
assert "Clicked: True" in out

# Complete conversation.
conversation_management.complete_conversation(
project_id=PROJECT_ID, conversation_id=conversation_id
)

# Delete conversation profile.
conversation_profile_management.delete_conversation_profile(
project_id=PROJECT_ID, conversation_profile_id=conversation_profile_id
)
91 changes: 91 additions & 0 deletions dialogflow/conversation_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env python

# 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.
"""Dialogflow API Python sample showing how to manage Conversations.
"""

from google.cloud import dialogflow_v2beta1 as dialogflow


# [START dialogflow_create_conversation]
def create_conversation(project_id, conversation_profile_id):
"""Creates a conversation with given values

Args:
project_id: The GCP project linked with the conversation.
conversation_profile_id: The conversation profile id used to create
conversation."""

client = dialogflow.ConversationsClient()
conversation_profile_client = dialogflow.ConversationProfilesClient()
project_path = client.common_project_path(project_id)
conversation_profile_path = conversation_profile_client.conversation_profile_path(
project_id, conversation_profile_id
)
conversation = {"conversation_profile": conversation_profile_path}
response = client.create_conversation(
parent=project_path, conversation=conversation
)

print("Life Cycle State: {}".format(response.lifecycle_state))
print("Conversation Profile Name: {}".format(response.conversation_profile))
print("Name: {}".format(response.name))
return response


# [END dialogflow_create_conversation]


# [START dialogflow_get_conversation]
def get_conversation(project_id, conversation_id):
"""Gets a specific conversation profile.

Args:
project_id: The GCP project linked with the conversation.
conversation_id: Id of the conversation."""

client = dialogflow.ConversationsClient()
conversation_path = client.conversation_path(project_id, conversation_id)

response = client.get_conversation(name=conversation_path)

print("Life Cycle State: {}".format(response.lifecycle_state))
print("Conversation Profile Name: {}".format(response.conversation_profile))
print("Name: {}".format(response.name))
return response


# [END dialogflow_get_conversation]


# [START dialogflow_complete_conversation]
def complete_conversation(project_id, conversation_id):
"""Completes the specified conversation. Finished conversations are purged from the database after 30 days.

Args:
project_id: The GCP project linked with the conversation.
conversation_id: Id of the conversation."""

client = dialogflow.ConversationsClient()
conversation_path = client.conversation_path(project_id, conversation_id)
conversation = client.complete_conversation(name=conversation_path)
print("Completed Conversation.")
print("Life Cycle State: {}".format(conversation.lifecycle_state))
print("Conversation Profile Name: {}".format(conversation.conversation_profile))
print("Name: {}".format(conversation.name))
return conversation


# [END dialogflow_complete_conversation]
Loading